forked from Synthetixio/synpress
-
Notifications
You must be signed in to change notification settings - Fork 5
/
launcher.js
135 lines (128 loc) · 4.5 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
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
const log = require('debug')('synpress:launcher');
const cypress = require('cypress');
const helpers = require('./helpers');
const synpressConfigPath = `${helpers.getSynpressPath()}/synpress.config.js`;
log(`Detected synpress config path is: ${synpressConfigPath}`);
process.env.CYPRESS_REMOTE_DEBUGGING_PORT = 9222;
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,
}));
},
async run(arguments_) {
if (arguments_.configFile) {
log(`Custom config file arg detected: ${arguments_.configFile}`);
defaultArguments.push(`--config-file=${arguments_.configFile}`);
} else {
log('Using default config file');
defaultArguments.push(`--config-file=${synpressConfigPath}`);
}
log(`Tests will run on ${arguments_.browser} browser`);
defaultArguments.push(`--browser=${arguments_.browser}`);
if (arguments_.headless) {
log(`headless arg enabled`);
process.env.HEADLESS_MODE = true;
}
if (arguments_.component) {
log(`component arg enabled`);
defaultArguments.push('--component');
}
if (arguments_.config) {
log(`Custom config arg detected: ${arguments_.config}`);
defaultArguments.push(`--config=${arguments_.config}`);
}
if (arguments_.e2e) {
log(`e2e arg enabled`);
defaultArguments.push('--e2e');
}
if (arguments_.env) {
log(`Custom env arg detected: ${arguments_.env}`);
defaultArguments.push(`--env=${arguments_.env}`);
}
if (arguments_.spec) {
log(`Custom spec arg detected: ${arguments_.spec}`);
defaultArguments.push(`--spec=${arguments_.spec}`);
}
if (arguments_.noExit) {
log(`noExit arg enabled`);
defaultArguments.push('--no-exit');
}
if (arguments_.port) {
log(`Custom port arg detected: ${arguments_.port}`);
defaultArguments.push(`--port=${arguments_.port}`);
}
if (arguments_.project) {
log(`Custom project arg detected: ${arguments_.project}`);
defaultArguments.push(`--project=${arguments_.project}`);
}
if (arguments_.quiet) {
log(`quiet arg enabled`);
defaultArguments.push('--quiet');
}
if (arguments_.reporter) {
log(`Custom reporter arg detected: ${arguments_.reporter}`);
defaultArguments.push(`--reporter=${arguments_.reporter}`);
}
if (arguments_.reporterOptions) {
log(`Custom reporterOptions arg detected: ${arguments_.reporterOptions}`);
defaultArguments.push(`--reporter-options=${arguments_.reporterOptions}`);
}
if (arguments_.ciBuildId) {
log(`Custom ciBuildId arg detected: ${arguments_.ciBuildId}`);
defaultArguments.push(`--ci-build-id=${arguments_.ciBuildId}`);
}
if (arguments_.record) {
log(`record arg enabled`);
defaultArguments.push('--record');
}
if (arguments_.key) {
log(`Custom key arg detected: ${arguments_.key}`);
defaultArguments.push(`--key=${arguments_.key}`);
}
if (arguments_.parallel) {
log(`parallel arg enabled`);
defaultArguments.push('--parallel');
}
if (arguments_.group) {
log(`Custom group arg detected: ${arguments_.group}`);
if (process.env.CYPRESS_GROUP) {
log(
`Custom group arg detected (from env var): ${process.env.CYPRESS_GROUP}`,
);
defaultArguments.push(`--group=${process.env.CYPRESS_GROUP}`);
} else if (arguments_.group === true) {
throw new Error('Please provide CYPRESS_GROUP environment variable');
} else {
defaultArguments.push(`--group=${arguments_.group}`);
}
}
if (arguments_.tag) {
log(`Custom tag arg detected: ${arguments_.tag}`);
defaultArguments.push(`--tag=${arguments_.tag}`);
}
const runOptions = await cypress.cli.parseRunArguments(defaultArguments);
log('Running synpress with following options', runOptions);
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;