Skip to content

Commit 9f29e36

Browse files
committed
ci: mark tests as failed on bs
1 parent d5a22c9 commit 9f29e36

26 files changed

+492
-198
lines changed

examples/webpack.config.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ module.exports = {
4141
},
4242
{
4343
test: /\.css$/,
44-
use: [
45-
'vue-style-loader',
46-
'css-loader'
47-
]
44+
use: ['vue-style-loader', 'css-loader']
4845
}
4946
]
5047
},
@@ -68,7 +65,5 @@ module.exports = {
6865
}
6966
},
7067

71-
plugins: [
72-
new VuePlugin()
73-
]
68+
plugins: [new VuePlugin()]
7469
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
]
5353
},
5454
"devDependencies": {
55+
"axios": "^0.19.0",
5556
"babel-core": "^6.24.1",
5657
"babel-eslint": "^10.0.1",
5758
"babel-loader": "^7.1.3",

test/e2e/browserstack-send-status.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const axios = require('axios')
2+
3+
const BS_USER = process.env.BS_USER
4+
const BS_KEY = process.env.BS_KEY
5+
6+
function getKey (client) {
7+
// const { capabilities, currentTest } = client
8+
// originally i wanted to use this but it turns out the information changes
9+
// on the afterEach, making the key non valid. But because every environment
10+
// runs on a different thread, the sessionMap object is only shared for a given
11+
// environment, so only using the name of the test (currentTest.module) seems to be
12+
// enough
13+
// return `${capabilities.platform}::${capabilities.browserName}@${
14+
// capabilities.version
15+
// } ${currentTest.module}: ${currentTest.name}`
16+
17+
return `${client.currentTest.module}: ${client.currentTest.name}`
18+
}
19+
20+
/**
21+
* Generates an object with beforeEach and afterEach functions to be added
22+
* to every test suite. It cannot be added globably because these must be
23+
* executed before each test (instead of each test suite as it does in globalModules)
24+
*/
25+
module.exports = function sendStatus () {
26+
const sessionMap = Object.create(null)
27+
28+
return {
29+
beforeEach (browser, cb) {
30+
// retrieve the session and save it to the map
31+
const key = getKey(this.client)
32+
browser.session(({ sessionId }) => {
33+
sessionMap[key] = sessionId
34+
cb()
35+
})
36+
},
37+
38+
afterEach (browser, cb) {
39+
const key = getKey(this.client)
40+
const { results } = this.client.currentTest
41+
const sessionId = sessionMap[key]
42+
43+
if (!sessionId) {
44+
console.warn('❌ Cannot find sessionId for ' + key)
45+
return cb()
46+
}
47+
48+
if (results.errors > 0) {
49+
const reason = results.lastError.message
50+
console.log('Found failed test', reason)
51+
axios
52+
.put(
53+
`https://api.browserstack.com/automate/sessions/${sessionId}.json`,
54+
{
55+
// change the name so it's easier to find
56+
name: key,
57+
status: 'failed',
58+
reason
59+
},
60+
{
61+
auth: {
62+
username: BS_USER,
63+
password: BS_KEY
64+
}
65+
}
66+
)
67+
.catch(err => {
68+
console.log('❌ Failed changing status for sessions', err)
69+
})
70+
.then(() => {
71+
console.log('✅ Sent for', sessionId)
72+
cb()
73+
})
74+
} else {
75+
cb()
76+
}
77+
}
78+
}
79+
}

test/e2e/nightwatch.browserstack.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const nwConf = {
2222
output_folder: 'test/e2e/reports',
2323
custom_commands_path: ['node_modules/nightwatch-helpers/commands'],
2424
custom_assertions_path: ['node_modules/nightwatch-helpers/assertions'],
25+
// set to true when testing on multiple browsers (-e chrome,firefox) to display tests as they pass instead of waiting for everything to be finished
26+
live_output: true,
27+
28+
// this couldn't work at the end, so we used ./browserstack-send-status.js
29+
// globals_path: resolve(__dirname, './globalModules.js'),
2530

2631
selenium: {
2732
start_process: false,
@@ -105,8 +110,7 @@ for (const setting in nwConf.test_settings) {
105110
// merge common_capabilities
106111
for (const key in nwConf.common_capabilities) {
107112
// fallback to common_capabilities
108-
config['desiredCapabilities'][key] =
109-
config['desiredCapabilities'][key] || nwConf.common_capabilities[key]
113+
config['desiredCapabilities'][key] = config['desiredCapabilities'][key] || nwConf.common_capabilities[key]
110114
}
111115
}
112116

test/e2e/nightwatch.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module.exports = {
55
output_folder: 'test/e2e/reports',
66
custom_commands_path: ['node_modules/nightwatch-helpers/commands'],
77
custom_assertions_path: ['node_modules/nightwatch-helpers/assertions'],
8+
// set to true when testing on multiple browsers (-e chrome,firefox) to display tests as they pass instead of waiting for everything to be finished
9+
live_output: false,
810

911
selenium: {
1012
start_process: true,

test/e2e/specs/active-links.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
const bsStatus = require('../browserstack-send-status')
12

23
module.exports = {
4+
...bsStatus(),
5+
36
'active links': function (browser) {
47
browser
58
.url('http://localhost:8080/active-links/')
@@ -38,17 +41,21 @@ module.exports = {
3841
activeA.forEach(i => {
3942
browser.assert.cssClassPresent(`li:nth-child(${i}) a`, 'router-link-active')
4043
})
41-
activeLI && activeLI.forEach(i => {
42-
browser.assert.cssClassPresent(`li:nth-child(${i})`, 'router-link-active')
43-
})
44+
activeLI &&
45+
activeLI.forEach(i => {
46+
browser.assert.cssClassPresent(`li:nth-child(${i})`, 'router-link-active')
47+
})
4448
exactActiveA.forEach(i => {
45-
browser.assert.cssClassPresent(`li:nth-child(${i}) a`, 'router-link-exact-active')
49+
browser.assert
50+
.cssClassPresent(`li:nth-child(${i}) a`, 'router-link-exact-active')
4651
.assert.cssClassPresent(`li:nth-child(${i}) a`, 'router-link-active')
4752
})
48-
exactActiveLI && exactActiveLI.forEach(i => {
49-
browser.assert.cssClassPresent(`li:nth-child(${i})`, 'router-link-exact-active')
50-
.assert.cssClassPresent(`li:nth-child(${i})`, 'router-link-active')
51-
})
53+
exactActiveLI &&
54+
exactActiveLI.forEach(i => {
55+
browser.assert
56+
.cssClassPresent(`li:nth-child(${i})`, 'router-link-exact-active')
57+
.assert.cssClassPresent(`li:nth-child(${i})`, 'router-link-active')
58+
})
5259
}
5360
}
5461
}

test/e2e/specs/auth-flow.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
const bsStatus = require('../browserstack-send-status')
2+
13
module.exports = {
4+
...bsStatus(),
5+
26
'auth flow': function (browser) {
37
browser
48
.url('http://localhost:8080/auth-flow/')
@@ -20,7 +24,7 @@ module.exports = {
2024
.assert.containsText('#app h2', 'Dashboard')
2125
.assert.containsText('#app p', 'Yay you made it!')
2226

23-
// reload
27+
// reload
2428
.url('http://localhost:8080/auth-flow/')
2529
.waitForElementVisible('#app', 1000)
2630
.assert.containsText('#app p', 'You are logged in')
@@ -31,7 +35,7 @@ module.exports = {
3135
.assert.containsText('#app h2', 'Dashboard')
3236
.assert.containsText('#app p', 'Yay you made it!')
3337

34-
// directly visit dashboard when logged in
38+
// directly visit dashboard when logged in
3539
.url('http://localhost:8080/auth-flow/dashboard')
3640
.waitForElementVisible('#app', 1000)
3741
.assert.urlEquals('http://localhost:8080/auth-flow/dashboard')
@@ -43,7 +47,7 @@ module.exports = {
4347
.assert.urlEquals('http://localhost:8080/auth-flow/')
4448
.assert.containsText('#app p', 'You are logged out')
4549

46-
// directly visit dashboard when logged out
50+
// directly visit dashboard when logged out
4751
.url('http://localhost:8080/auth-flow/dashboard')
4852
.waitForElementVisible('#app', 1000)
4953
.assert.urlEquals('http://localhost:8080/auth-flow/login?redirect=%2Fdashboard')

test/e2e/specs/basic.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
const bsStatus = require('../browserstack-send-status')
2+
13
module.exports = {
4+
...bsStatus(),
5+
26
basic: function (browser) {
37
browser
48
.url('http://localhost:8080/basic/')

test/e2e/specs/data-fetching.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
const bsStatus = require('../browserstack-send-status')
2+
13
module.exports = {
4+
...bsStatus(),
5+
26
'data fetching': function (browser) {
37
browser
48
.url('http://localhost:8080/data-fetching/')

test/e2e/specs/hash-mode.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
const bsStatus = require('../browserstack-send-status')
2+
13
module.exports = {
4+
...bsStatus(),
5+
26
'Hash mode': function (browser) {
37
browser
48
.url('http://localhost:8080/hash-mode/')
@@ -29,7 +33,7 @@ module.exports = {
2933
.assert.urlEquals('http://localhost:8080/hash-mode/#/bar')
3034
.assert.containsText('.view', 'bar')
3135

32-
// check initial visit
36+
// check initial visit
3337
.url('http://localhost:8080/hash-mode/#/foo')
3438
.waitForElementVisible('#app', 1000)
3539
.assert.containsText('.view', 'foo')

0 commit comments

Comments
 (0)