forked from refinableco/synpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.js
96 lines (87 loc) · 2.9 KB
/
launcher.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
const cypress = require('cypress');
const helpers = require('./helpers');
const synpressConfigPath = `${helpers.getSynpressPath()}/synpress.json`;
process.env.CYPRESS_REMOTE_DEBUGGING_PORT = 9222;
const fixturesFolder = `${helpers.getSynpressPath()}/fixtures`;
const pluginsFile = `${helpers.getSynpressPath()}/plugins/index.js`;
const supportFile = `${helpers.getSynpressPath()}/support/index.js`;
const defaultConfig = `fixturesFolder=${fixturesFolder},pluginsFile=${pluginsFile},supportFile=${supportFile}`;
const defaultArguments = [
'cypress',
'run',
'--headed', // needed for extensions like metamask to work
];
const launcher = {
async open(arguments_) {
await (arguments_.configFile
? cypress.open({ configFile: arguments_.configFile })
: cypress.open({
configFile: synpressConfigPath,
config: defaultConfig,
}));
},
async run(arguments_) {
if (arguments_.configFile) {
defaultArguments.push(`--config-file=${arguments_.configFile}`);
} else {
defaultArguments.push(`--config-file=${synpressConfigPath}`);
}
defaultArguments.push(`--browser=${arguments_.browser}`);
if (arguments_.config) {
defaultArguments.push(`--config=${defaultConfig},${arguments_.config}`);
} else {
defaultArguments.push(`--config=${defaultConfig}`);
}
if (arguments_.env) {
defaultArguments.push(`--env=${arguments_.env}`);
}
if (arguments_.spec) {
defaultArguments.push(`--spec=${arguments_.spec}`);
}
if (arguments_.noExit) {
defaultArguments.push('--no-exit');
}
if (arguments_.project) {
defaultArguments.push(`--project=${arguments_.project}`);
}
if (arguments_.quiet) {
defaultArguments.push('--quiet');
}
if (arguments_.reporter) {
defaultArguments.push(`--reporter=${arguments_.reporter}`);
}
if (arguments_.reporterOptions) {
defaultArguments.push(`--reporter-options=${arguments_.reporterOptions}`);
}
if (arguments_.record) {
defaultArguments.push('--record');
}
if (arguments_.key) {
defaultArguments.push(`--key=${arguments_.key}`);
}
if (arguments_.parallel) {
defaultArguments.push('--parallel');
}
if (arguments_.group) {
defaultArguments.push(`--group=${arguments_.group}`);
}
if (arguments_.tag) {
defaultArguments.push(`--tag=${arguments_.tag}`);
}
const runOptions = await cypress.cli.parseRunArguments(defaultArguments);
const results = await cypress.run(runOptions);
if (results.failures) {
console.error('Failed to run Cypress');
console.error(results.message);
process.exit(results.failures);
}
console.log(
'Cypress run results: %d total tests, %d passed, %d failed',
results.totalTests,
results.totalPassed,
results.totalFailed,
);
process.exit(results.totalFailed);
},
};
module.exports = launcher;