-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
run.js
178 lines (144 loc) · 3.6 KB
/
run.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* eslint-disable no-console */
const _ = require('lodash')
const chalk = require('chalk')
const minimist = require('minimist')
const execa = require('execa')
const path = require('path')
const os = require('os')
const options = minimist(process.argv.slice(2))
let run = options._
if (options['spec']) {
console.error('NOTE: It is no longer necessary to pass `--spec` to server test commands. Try passing the path directly instead.')
run = [options.spec]
}
if (run[0] && run[0].includes('--inspect-brk')) {
run = run.slice(1)
}
if (options['glob-in-dir']) {
if (run[0]) {
run = [path.join(options['glob-in-dir'], '**', `*${run[0]}*`)]
} else {
run = [path.join(options['glob-in-dir'], '**')]
}
}
function exitErr (msg) {
console.error(chalk.red(msg))
return process.exit(1)
}
const isWindows = () => {
return os.platform() === 'win32'
}
const isGteNode12 = () => {
return Number(process.versions.node.split('.')[0]) >= 12
}
if (!run || !run.length) {
return exitErr(`
Error: A path to a spec file must be specified!
It should look something like this:
$ yarn test ./test/unit/api_spec.js
If you want to run all a specific group of tests:
$ yarn test-unit
$ yarn test-integration
$ yarn test-performance
`)
}
const commandAndArguments = {
command: '',
args: [],
}
if (isWindows()) {
commandAndArguments.command = 'mocha'
commandAndArguments.args = run.slice()
} else {
commandAndArguments.command = 'xvfb-maybe'
// this should always match cli/lib/exec/xvfb.js
commandAndArguments.args = [
`-as`,
`"-screen 0 1280x1024x24"`,
`--`,
'node',
]
}
if (options['inspect-brk']) {
commandAndArguments.args.push(
'--inspect',
`--inspect-brk${options['inspect-brk'] === true ? '' : `=${options['inspect-brk']}`}`,
)
}
if (isGteNode12()) {
// max HTTP header size 8kb -> 1mb
// https://github.com/cypress-io/cypress/issues/76
commandAndArguments.args.push(
`--max-http-header-size=${1024 * 1024}`,
)
}
if (!isWindows()) {
commandAndArguments.args.push(
'node_modules/.bin/_mocha',
)
commandAndArguments.args = commandAndArguments.args.concat(run)
}
if (options.fgrep) {
commandAndArguments.args.push(
'--fgrep',
options.fgrep,
)
}
commandAndArguments.args.push(
'--timeout',
options['inspect-brk'] ? '40000000' : '10000',
'--recursive',
'-r @packages/ts/register',
'--reporter',
'mocha-multi-reporters',
'--reporter-options',
'configFile=../../mocha-reporter-config.json',
'--extension=js,ts',
// restore mocha 2.x behavior to force end process after spec run
'--exit',
)
const env = _.clone(process.env)
env.NODE_ENV = 'test'
env.CYPRESS_INTERNAL_ENV = 'test'
if (env.VERBOSE === '1') {
_.extend(env, {
CYPRESS_DEBUG: true,
NODE_DEBUG: 'request',
BLUEBIRD_DEBUG: 1,
DEBUG: _.chain([
env.DEBUG,
'nock.*',
'-nock.common',
'-nock.scope',
'-nock.interceptor',
'socket.io:*',
'xvfb-maybe',
])
.compact()
.join(','),
})
}
if (options.browser) {
env.BROWSER = options.browser
}
if (options.headed) {
env.HEADED = true
}
if (options.exit === false) {
env.NO_EXIT = '1'
}
if (options['cypress-inspect-brk']) {
env.CYPRESS_INSPECT_BRK = '1'
}
const cmd = `${commandAndArguments.command} ${
commandAndArguments.args.join(' ')}`
console.log('specfiles:', run)
console.log('test command:')
console.log(cmd)
const child = execa.shell(cmd, { env, stdio: 'inherit' })
child.on('exit', (code, signal) => {
if (signal) {
console.error(`tests exited with signal ${signal}`)
}
process.exit(code === null ? 1 : code)
})