-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
test-repeat.js
68 lines (53 loc) · 1.76 KB
/
test-repeat.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
/* eslint-disable no-console */
// a small utility script to run Cypress N times
// use (from examples/X folder)
// node ../../test-repeat.js -n 3
// if you want to record, a good idea is to pass a group name
// node ../../test-repeat.js -n 3 --group my-example
// if there is an .env file, lots it and add to process.env
require('dotenv').config()
const arg = require('arg')
const cypress = require('cypress')
const Bluebird = require('bluebird')
const args = arg({
'-n': Number,
'--group': String,
})
const repeatNtimes = args['-n'] ? args['-n'] : 1
console.log('will repeat Cypress run %d time(s)', repeatNtimes)
const allRunOptions = []
for (let k = 0; k < repeatNtimes; k += 1) {
const runOptions = {}
if (process.env.CYPRESS_RECORD_KEY) {
runOptions.record = true
runOptions.group = args['--group']
if (runOptions.group && repeatNtimes > 1) {
// make sure if we are repeating this example
// then the recording has group names on the Dashboard
// like "example-1-of-20", "example-2-of-20", ...
runOptions.group += `-${k + 1}-of-${repeatNtimes}`
}
}
allRunOptions.push(runOptions)
}
const onError = (err) => {
console.error(err)
process.exit(1)
}
Bluebird.mapSeries(allRunOptions, (runOptions, k, n) => {
console.log('***** %d of %d *****', k + 1, n)
const onTestResults = (testResults) => {
if (testResults.failures) {
console.error(testResults.message)
process.exit(testResults.failures)
}
if (testResults.totalFailed) {
console.error('run %d of %d failed', k + 1, n)
process.exit(testResults.totalFailed)
}
}
return cypress.run(runOptions).then(onTestResults)
}).then(() => {
console.log('***** finished %d run(s) successfully *****', repeatNtimes)
})
.catch(onError)