forked from vuejs/vue-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.js
155 lines (142 loc) · 4.74 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Running tests
*
* By default tests are run locally on chrome headless
* $ node test/e2e/runner.js
*
* You can run a specific test by passing it, or pass various tests
* $ node test/e2e/runner.js test/e2e/specs/basic.js test/e2e/specs/redirect.js
*
* You can specify a list of browsers to run from nightwatch.config.js with -e separated by a comma
* $ node test/e2e/runner.js -e safari,firefox
*
* If you are already running the dev server with `yarn run serve`, you can pass the --dev option to avoid launching the server
* $ node test/e2e/runner.js --dev
*
* __For maintainers only__
* You can trigger tests on Browserstack on other browsers by passing the --local option
* It's also required to pass the list of browsers to test on to avoid launching too many tests. Available options are located inside nightwatch.browserstack.js
* $ node test/e2e/runner.js --local -e ie,chrome50
*/
require('dotenv').config()
const { resolve } = require('path')
const Nightwatch = require('nightwatch')
const args = process.argv.slice(2)
// if we are running yarn dev locally, we can pass --dev to avoid launching another server instance
const server =
args.indexOf('--dev') > -1 ? null : require('../../examples/server')
// allow running browserstack local
const isLocal = args.indexOf('--local') > -1
const DEFAULT_CONFIG = './nightwatch.json'
const NW_CONFIG = isLocal
? resolve(__dirname, './nightwatch.browserstack.js')
: resolve(__dirname, './nightwatch.config.js')
// check configuration
if (args.indexOf('-c') < 0) {
// check if multiple envs are provided. The way Nightwatch works
// requires to explicitely provide the conf
const envs = args[args.indexOf('-e') + 1]
if (envs && envs.indexOf(',') > -1) {
console.warn(
`Specify the conf when providing multiple browsers:\n$ yarn run test:e2e ${args.join(
' '
)} -c ${NW_CONFIG}`
)
process.exit(1)
}
} else if (isLocal) {
const conf = args[args.indexOf('-c') + 1]
if (resolve('.', conf) !== NW_CONFIG) {
console.warn('The passed config should be', NW_CONFIG)
process.exit(1)
}
}
function adaptArgv (argv) {
// take every remaining argument and treat it as a test file
// this allows to run `node test/e2e/runner.js test/e2e/basic.js`
argv.test = argv['_'].slice(0)
if (argv.c === DEFAULT_CONFIG && argv.config === DEFAULT_CONFIG) {
argv.config = argv.c = NW_CONFIG
}
// Nightwatch does not accept an array with one element
if (argv.test.length === 1) argv.test = argv.test[0]
// debugging easily
// console.log(argv)
// process.exit(0)
}
process.mainModule.filename = resolve(
__dirname,
'../../node_modules/.bin/nightwatch'
)
if (isLocal) {
if (isLocal && (!process.env.BS_USER || !process.env.BS_KEY)) {
console.log(
'Hey!\n',
'You are missing credentials for Browserstack.\n',
'If you are a contributor, this is normal, credentials are private. These tests must be run by a maintainer of vue-router',
'If you are a maintainer, make sure to create your `.env` file with both `BS_USER` and `BS_KEY` variables!'
)
// fail if testing locally
process.exit(process.env.CI ? 0 : 1)
}
let bsLocal
const browserstack = require('browserstack-local')
Nightwatch.bs_local = bsLocal = new browserstack.Local()
bsLocal.start({ key: process.env.BS_KEY }, error => {
if (error) throw error
console.log('Connected. Now testing...')
try {
Nightwatch.cli(argv => {
adaptArgv(argv)
Nightwatch.CliRunner(argv)
.setup(null, () => {
// NOTE: I don't know when this is running or if it does
// Code to stop browserstack local after end of parallel test
bsLocal.stop(() => {
server && server.close()
process.exit(0)
})
})
.runTests()
.then(() => {
// Code to stop browserstack local after end of single test
bsLocal.stop(() => {
server && server.close()
process.exit(0)
})
})
.catch(() => {
server && server.close()
// fail execution
process.exit(1)
})
})
} catch (err) {
console.error(err)
bsLocal.stop(() => {
process.exit(1)
})
}
})
} else {
// create the Nightwatch CLI runner
Nightwatch.cli(argv => {
adaptArgv(argv)
const runner = Nightwatch.CliRunner(argv)
// setup and run tests
runner
.setup()
.startWebDriver()
.then(() => runner.runTests())
.then(() => {
runner.stopWebDriver()
server && server.close()
process.exit(0)
})
.catch(err => {
server && server.close()
console.error(err)
process.exit(1)
})
})
}