-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathe2e-run-tests.js
59 lines (52 loc) · 1.18 KB
/
e2e-run-tests.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
const cypress = require('cypress')
const fs = require('fs')
const path = require('path')
cypress.run().then(({
status,
startedTestsAt,
endedTestsAt,
totalDuration,
totalTests,
totalPassed,
totalPending,
totalFailed,
totalSkipped,
browserName,
browserVersion,
osName,
osVersion,
cypressVersion,
runs,
}) => {
let testResultsObj = {
status,
startedTestsAt,
endedTestsAt,
totalDuration: `${totalDuration / 1000} seconds`,
totalTests,
totalPassed,
totalPending,
totalFailed,
totalSkipped,
browserName,
browserVersion,
osName,
osVersion,
cypressVersion,
}
const testCases = runs[0].tests.map((({ title }) => title[title.length - 1]))
testResultsObj.testCases = testCases
testResultsObj = JSON.stringify(testResultsObj)
const testReportDir = path.resolve(`${__dirname}/test-report`)
if (!fs.existsSync(testReportDir)){
fs.mkdirSync(testReportDir)
}
const testResultsFile = `${testReportDir}/testResults.json`
fs.writeFile(testResultsFile, testResultsObj, err => {
if (err) {
console.error(err)
} else {
console.log(`\nTest report available at: ${testResultsFile}\n`)
}
})
})