forked from Synthetixio/synpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
synpress.js
157 lines (147 loc) · 5.01 KB
/
synpress.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
151
152
153
154
155
156
157
#!/usr/bin/env node
const log = require('debug')('synpress:cli');
const program = require('commander');
const { run, open } = require('./launcher');
const { version } = require('./package.json');
if (process.env.DEBUG && process.env.DEBUG.includes('synpress')) {
log('DEBUG mode is enabled');
process.env.PWDEBUG = 1;
if (!process.env.STABLE_MODE) {
log('Enabling stable mode');
process.env.STABLE_MODE = true;
}
}
if (process.env.SYNPRESS_LOCAL_TEST) {
log('Loading .env config file from root folder');
require('dotenv').config();
} else {
const envFiles = ['.env', '.env.e2e', '.env.local', '.env.dev'];
envFiles.forEach(envFile => {
log(
`Loading ${envFile} config file from first matching config file - root dir, ancestor or home dir`,
);
require('dotenv').config({ path: require('find-config')(envFile) });
});
}
// if user skips metamask install or setup
if (!process.env.SKIP_METAMASK_INSTALL && !process.env.SKIP_METAMASK_SETUP) {
// we don't want to check for presence of SECRET_WORDS or PRIVATE_KEY
if (!process.env.SECRET_WORDS && !process.env.PRIVATE_KEY) {
throw new Error(
'Please provide SECRET_WORDS or PRIVATE_KEY environment variable',
);
}
} else {
log(
'Skipping check for SECRET_WORDS and PRIVATE_KEY as SKIP_METAMASK_INSTALL or SKIP_METAMASK_SETUP is set',
);
}
if (process.env.RPC_URL || process.env.CHAIN_ID || process.env.SYMBOL) {
if (!process.env.RPC_URL) {
throw new Error('Please provide RPC_URL environment variable');
} else if (!process.env.CHAIN_ID) {
throw new Error('Please provide CHAIN_ID environment variable');
} else if (!process.env.SYMBOL) {
throw new Error('Please provide SYMBOL environment variable');
}
if (
!process.env.RPC_URL.startsWith('http://') && //DevSkim: ignore DS137138
!process.env.RPC_URL.startsWith('https://')
) {
throw new Error(
'RPC_URL environment variable should start with "http://" or "https://"', //DevSkim: ignore DS137138
);
}
if (
process.env.BLOCK_EXPLORER &&
!process.env.BLOCK_EXPLORER.startsWith('http://') && //DevSkim: ignore DS137138
!process.env.BLOCK_EXPLORER.startsWith('https://')
) {
throw new Error(
'BLOCK_EXPLORER environment variable should start with "http://" or "https://"', //DevSkim: ignore DS137138
);
}
}
program.version(version, '-v, --version');
program
.command('run')
.requiredOption('-b, --browser <name>', 'run on specified browser', 'chrome')
.option('-h, --headless', 'run tests in headless mode')
.option('-cmp, --component', 'run component tests')
.option(
'-c, --config <config>',
'set configuration values, separate multiple values with a comma',
)
.option(
'-cf, --configFile <path>',
'specify a path to a JSON file where configuration values are set',
)
.option('--e2e', 'run e2e tests (already set as default)')
.option(
'-e, --env <env=val>',
'set environment variables, separate multiple values with comma',
)
.option('-s, --spec <path or glob>', 'run only provided spec files')
.option('-ne, --noExit', 'keep runner open after tests finish')
.option('-pt, --port <value>', 'override default port')
.option('-pr, --project <path>', 'run with specific project path')
.option('-q, --quiet', 'only test runner output in console')
.option('-r, --reporter <reporter>', 'specify mocha reporter')
.option(
'-ro, --reporterOptions <options>',
'specify mocha reporter options, separate multiple values with comma',
)
// dashboard
.option('-cid, --ciBuildId', '[dashboard] add custom ci build id to the run')
.option(
'-r, --record',
'[dashboard] record video of tests running after setting up your project to record',
)
.option('-k, --key <key>', '[dashboard] set record key')
.option(
'-p, --parallel',
'[dashboard] run recorded specs in parallel across multiple machines',
)
.option(
'-g, --group [name]',
'[dashboard] group recorded tests together under a single run',
)
.option('-t, --tag <name>', '[dashboard] add tags to dashboard for test run')
.description('launch tests')
.action(options => {
run({
browser: options.browser,
headless: options.headless,
component: options.component,
config: options.config,
configFile: options.configFile,
e2e: options.e2e,
env: options.env,
spec: options.spec,
noExit: options.noExit,
port: options.port,
project: options.project,
quiet: options.quiet,
reporter: options.reporter,
reporterOptions: options.reporterOptions,
ciBuildId: options.ciBuildId,
record: options.record,
key: options.key,
parallel: options.parallel,
group: options.group,
tag: options.tag,
});
});
program
.command('open')
.description('launch test runner UI')
.option(
'-cf, --configFile <path>',
'specify a path to a JSON file where configuration values are set',
)
.action(options => {
open({
configFile: options.configFile,
});
});
program.parse(process.argv);