-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
150 lines (115 loc) · 4.24 KB
/
index.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
module.exports = (api, options) => {
const { info, chalk, execa, openBrowser } = require('@vue/cli-shared-utils')
api.registerCommand('test:e2e', {
description: 'run e2e tests with CodeceptJS',
usage: 'vue-cli-service test:e2e [options]',
options: {
'--headless': 'run in headless mode',
'-s, --serve': 'run dev server before a test',
'--mode': 'specify the mode the dev server should run in. (default: production)',
},
details:
`All CodeceptJS CLI options are also supported:\n` +
chalk.yellow(`https://codecept.io/commands#run`)
}, async (args, rawArgs) => {
removeArg(rawArgs, 'headless');
removeArg(rawArgs, 'serve');
removeArg(rawArgs, 'mode');
info(`Starting e2e tests...`);
if (args.headless) info('Headless mode enabled');
const server = await runServer(args.serve, args, rawArgs);
const { container, config, codecept } = require('codeceptjs');
const { setHeadlessWhen } = require('@codeceptjs/configure');
const opts = { steps: true };
setHeadlessWhen(args.headless);
config.load(args.config || api.getCwd());
const conf = config.get();
if (server) conf.teardown = () => server.close();
// create runner
let runner = new codecept(conf, { ...opts, ...args });
// initialize codeceptjs in tests/e2e
runner.initGlobals(api.getCwd());
// create helpers, support files, mocha
container.create(conf, opts);
// initialize listeners
runner.runHooks();
// load tests
runner.loadTests();
// run tests
return runner.run();
});
api.registerCommand('test:e2e:parallel', {
description: 'run e2e tests with CodeceptJS in workers',
usage: 'vue-cli-service test:e2e:parallel [options]',
options: {
'-s, --serve': 'run dev server before a test',
'--mode': 'specify the mode the dev server should run in. (default: production)',
},
details:
`All CodeceptJS CLI options are also supported:\n` +
chalk.yellow(`https://codecept.io/commands#run`)
}, async (args, rawArgs) => {
// set default workers
const workers = args._[0] || 2;
removeArg(rawArgs, 'serve');
removeArg(rawArgs, 'mode');
rawArgs.unshift('run-workers')
info(`Starting e2e tests in ${workers} workers...`);
const server = await runServer(args.serve, args, rawArgs);
const codeceptBin = require.resolve('codeceptjs/bin/codecept');
// run tests in headless mode
const runner = execa(codeceptBin, rawArgs, { stdio: 'inherit', env: { HEADLESS: true } })
if (server) {
runner.on('exit', () => server.close());
runner.on('error', () => server.close());
}
if (process.env.VUE_CLI_TEST) {
runner.on('exit', code => {
process.exit(code)
})
}
return runner;
});
api.registerCommand('test:e2e:open', {
description: 'run UI for CodeceptJS',
usage: 'vue-cli-service test:open',
details:
`More about CodeceptUI :\n` +
chalk.yellow(`https://github.com/codecept-js/ui`)
}, async (args, rawArgs) => {
info(`Openning e2e dashboard...`)
const server = await runServer(args.serve, args, rawArgs);
const codeceptBin = require.resolve('@codeceptjs/ui/bin/codecept-ui.js');
const runner = execa(codeceptBin, '', { stdio: 'inherit' });
setTimeout(() => {
info('Launching default browser...');
openBrowser('http://localhost:3001');
}, 2000);
if (server) {
runner.on('exit', () => server.close())
runner.on('error', () => server.close())
}
if (process.env.VUE_CLI_TEST) {
runner.on('exit', code => {
process.exit(code)
})
}
return runner;
});
async function runServer(runServer = false, args = {}, rawArgs = []) {
if (!runServer) return;
const { server } = await api.service.run('serve', args, rawArgs);
return server;
}
}
module.exports.defaultModes = {
'test:e2e': 'production'
}
function removeArg (rawArgs, argToRemove, offset = 1) {
const matchRE = new RegExp(`^--${argToRemove}`)
const equalRE = new RegExp(`^--${argToRemove}=`)
const i = rawArgs.findIndex(arg => matchRE.test(arg))
if (i > -1) {
rawArgs.splice(i, offset + (equalRE.test(rawArgs[i]) ? 0 : 1))
}
}