/
runner.js
74 lines (64 loc) 路 1.92 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
require('dotenv').config()
const Nightwatch = require('nightwatch')
const browserstack = require('browserstack-local')
const path = require('path')
const { BROWSERSTACK_ACCESS_KEY } = process.env
const args = process.argv.slice(2)
// allow running browserstack local
// note this works because nighwatch doesn't use this option
const isLocal = args.indexOf('--local') > -1
const getServer =
args.indexOf('--dev') > -1 ? () => null : require('./devServer')
;(async () => {
const server = await getServer()
try {
require.main.filename = path.resolve(
__dirname,
'../../../node_modules/.bin/nightwatch'
)
/** @type {import('browserstack-local').Local} */
let bs_local
if (isLocal) {
if (!BROWSERSTACK_ACCESS_KEY) {
throw new Error(
`
(ONLY FOR MAINTAINERS)
BROWSERSTACK_ACCESS_KEY is not set. Did you create the .env file?
`
)
}
// Code to start browserstack local before start of test
console.log('Connecting local')
bs_local = new browserstack.Local()
Nightwatch.bs_local = bs_local
bs_local.start(
{ key: process.env.BROWSERSTACK_ACCESS_KEY },
async error => {
if (error) throw error
console.log('Connected. Now testing...')
await runNightwatchCli().finally(() => {
// Code to stop browserstack local after end of single test
bs_local.stop(() => {
server?.close()
})
})
}
)
} else {
await runNightwatchCli()
server?.close()
}
} catch (ex) {
console.log('There was an error while starting the test runner:\n\n')
process.stderr.write(ex.stack + '\n')
server?.close()
process.exit(2)
}
})()
function runNightwatchCli() {
return new Promise((resolve, reject) => {
Nightwatch.cli(argv => {
Nightwatch.CliRunner(argv).setup().runTests().then(resolve).catch(reject)
})
})
}