-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·70 lines (60 loc) · 1.76 KB
/
index.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
#!/usr/bin/env node
// @ts-check
// runs Cypress with "normal" CLI parameters
// but after the run verifies the expected number of passing tests
const cypress = require('cypress')
const debug = require('debug')('cypress-expect')
const arg = require('arg')
// remove all our arguments to let Cypress only deal with its arguments
const args = arg({
'--passing': Number, // number of total passing tests to expect
})
if (typeof args['--passing'] !== 'number') {
console.error('expected a number of --passing tests', args['--passing'])
process.exit(1)
}
if (args['--passing'] < 0) {
console.error('expected a number of --passing tests', args['--passing'])
process.exit(1)
}
const parseArguments = async () => {
const cliArgs = args._
if (cliArgs[0] !== 'cypress') {
cliArgs.unshift('cypress')
}
if (cliArgs[1] !== 'run') {
cliArgs.splice(1, 0, 'run')
}
debug('parsing Cypress CLI %o', cliArgs)
return await cypress.cli.parseRunArguments(cliArgs)
}
parseArguments()
.then((options) => {
debug('parsed CLI options %o', options)
return cypress.run(options)
})
.then((runResults) => {
// see https://on.cypress.io/module-api
if (runResults.failures) {
console.error(runResults.message)
process.exit(1)
}
if (runResults.totalFailed) {
console.error('%d test(s) failed', runResults.totalFailed)
process.exit(runResults.totalFailed)
}
// make sure the expected number of tests executed
if (runResults.totalPassed !== args['--passing']) {
console.error(
'expected %d passing tests, got %d',
args['--passing'],
runResults.totalPassed,
)
process.exit(1)
}
})
.catch((e) => {
console.log('error: %s', e.message)
console.error(e)
process.exit(1)
})