1 | module.exports = (program, addArgs, spawnCommand) => {
|
2 | const fs = require('fs');
|
3 | const path = require('path');
|
4 |
|
5 | const e2e = program
|
6 | .command('e2e')
|
7 | .description('E2E-Testing (https://nightwatchjs.org/)')
|
8 | .option('-e, --env <env>', 'test running environment')
|
9 | .option('--headless', 'run tests in the headless mode')
|
10 | .action((opts) => {
|
11 | const spawnArgs = ['nightwatch'];
|
12 | if (opts.env) {
|
13 | spawnArgs.push(`--env=${opts.env}`);
|
14 | }
|
15 | if (opts.headless) {
|
16 | spawnArgs.push('--headless');
|
17 | }
|
18 | addArgs(e2e, opts, spawnArgs);
|
19 | spawnCommand(spawnArgs, opts.silent);
|
20 | });
|
21 |
|
22 | const cucumber = program
|
23 | .command('cucumber')
|
24 | .description('E2E-Testing (https://cucumber.io/)')
|
25 | .option('-e, --env <env>', 'test running environment')
|
26 | .option('--headless', 'run tests in the headless mode')
|
27 | .action((opts) => {
|
28 | let reportDir = path.resolve(process.cwd(), '.reports');
|
29 | if (!fs.existsSync(reportDir)) {
|
30 | fs.mkdirSync(reportDir);
|
31 | }
|
32 | reportDir = path.resolve(reportDir, 'cucumber');
|
33 | if (!fs.existsSync(reportDir)) {
|
34 | fs.mkdirSync(reportDir);
|
35 | }
|
36 | let spawnArgs = ['cross-env'];
|
37 | if (opts.env) {
|
38 | spawnArgs.push(`NIGHTWATCH_ENV=${opts.env}`);
|
39 | }
|
40 | spawnArgs = spawnArgs.concat([
|
41 | 'cucumber-js',
|
42 | 'tests/cucumber/features/**/*.feature',
|
43 | '--require',
|
44 | '@babel/register',
|
45 | '--require',
|
46 | 'cucumber.conf.js',
|
47 | '--require',
|
48 | 'tests/cucumber/step-definitions',
|
49 | '--format',
|
50 | 'node_modules/cucumber-pretty',
|
51 | '--format',
|
52 | 'json:.reports/cucumber/report.json',
|
53 | ]);
|
54 | if (opts.headless) {
|
55 | spawnArgs.push('--headless');
|
56 | }
|
57 | addArgs(cucumber, opts, spawnArgs);
|
58 | spawnCommand(spawnArgs, opts.silent);
|
59 | });
|
60 | };
|