-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress_runner.js
56 lines (51 loc) · 1.55 KB
/
cypress_runner.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
// USAGE: node cypress_runner -b chrome
const cypress = require('cypress')
const yargs = require('yargs')
const { merge } = require('mochawesome-merge')
const marge = require('mochawesome-report-generator')
const rm = require('rimraf')
const cypressConfig = require('./cypress')
const ls = require('ls')
const argv = yargs.options({
'browser': {
alias: 'b',
describe: 'choose browser that you wanna run tests on',
default: 'chrome',
choices: ['chrome', 'electron'],
},
'spec': {
alias: 's',
describe: 'run test with specific spec file',
default: 'cypress/integration/*.spec.js',
},
}).help()
.argv
const reportDir = cypressConfig.reporterOptions.reportDir
const reportFiles = `${reportDir}/*.json`
// list all of existing report files
ls(reportFiles, { recurse: true }, (file) => console.log(`removing ${file.full}`))
// delete all existing report files
rm(reportFiles, (error) => {
if (error) {
console.error(`Error while removing existing report files: ${error}`)
process.exit(1)
}
console.log('Removing all existing report files successfully!')
})
cypress.run({
browser: argv.browser,
spec: argv.spec,
}).then((results) => {
const reporterOptions = {
reportDir: results.config.reporterOptions.reportDir,
}
generateReport(reporterOptions)
}).catch((error) => {
console.error('errors: ', error)
process.exit(1)
})
function generateReport(options) {
return merge(options).then((report) => {
marge.create(report, options)
})
}