This repository has been archived by the owner on Jan 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
71 lines (65 loc) · 2.37 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
/* eslint-disable global-require, no-use-before-define */
module.exports = (api) => {
api.registerCommand('test:e2e', {
description: 'Run end-to-end tests with Nightwatch/Cucumber',
usage: 'vue-cli-service test:e2e [options] [<GLOB|DIR|FILE>]',
options: {
'-e, --env': 'specify browser environment to run in (as specified in your `nightwatch.conf.js`)',
},
}, (args, rawArgs) => {
process.env.NIGHTWATCH_ENVIRONMENT = args.e || args.env || 'default';
removeArg(rawArgs, '-e');
removeArg(rawArgs, '--env');
const cucumberArguments = cucumberArgs(rawArgs, args);
const server = api.service.run('serve');
server.then(({ url }) => {
process.env.VUE_DEV_SERVER_URL = url;
const cwd = api.getCwd();
// eslint-disable-next-line import/no-dynamic-require
const CucumberCLI = require(`${cwd}/node_modules/cucumber/lib/cli`).default;
const cucumberCLI = new CucumberCLI({
argv: cucumberArguments,
cwd,
stdout: process.stdout,
});
const cucumber = cucumberCLI.run();
cucumber.then(({ success }) => {
const code = !success;
process.exit(code);
});
});
});
};
module.exports.defaultModes = {
'test:e2e': 'production',
};
function cucumberArgs(rawArgs, args) {
function argsLacking(property) {
return !Object.hasOwnProperty.call(args, property);
}
const cucumberArguments = rawArgs;
// TODO Refactoring
// The order `--require-module`, `--require`, `--format` and `[<GLOB|DIR|FILE>]` is important!
if (argsLacking('format') && argsLacking('f')) {
cucumberArguments.unshift('--format', 'node_modules/cucumber-pretty');
}
if (argsLacking('require') && argsLacking('r')) {
cucumberArguments.unshift('--require', 'tests/step-definitions');
cucumberArguments.unshift('--require', `${__dirname}/tests/support`);
}
if (argsLacking('require-module')) {
cucumberArguments.unshift('--require-module', 'babel-core/register');
}
if (!args._.length) {
cucumberArguments.push('tests/features/**/*.feature');
}
return cucumberArguments;
}
function removeArg(rawArgs, arg, offset = 1) {
const matchRegExp = new RegExp(`^${arg}`);
const equalRegExp = new RegExp(`^${arg}=`);
const index = rawArgs.findIndex(_arg => matchRegExp.test(_arg));
if (index > -1) {
rawArgs.splice(index, offset + (equalRegExp.test(rawArgs[index]) ? 0 : 1));
}
}