forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e-tests.js
68 lines (56 loc) · 1.56 KB
/
e2e-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
60
61
62
63
64
65
66
67
68
// runs Cypress end-to-end tests using Cypress Node module API
// https://on.cypress.io/module-api
/* eslint-disable no-console */
const cypress = require('cypress')
const globby = require('globby')
const Promise = require('bluebird')
const fs = require('fs')
require('console.table')
/**
* Sorts by "time" property, putting larger numbers first
*/
const byTime = (a, b) => b.time - a.time
const sortByLastModified = (filenames) => {
const withTimes = filenames.map((filename) => {
return {
filename,
time: fs.statSync(filename).mtime.getTime(),
}
})
return withTimes.sort(byTime)
}
const runOneSpec = (spec) => {
return cypress.run({
config: {
video: false,
},
spec: spec.filename,
})
}
globby('./cypress/e2e/*-spec.cy.js')
.then(sortByLastModified)
.then((specs) => {
console.table('Running last modified spec first', specs)
return Promise.mapSeries(specs, runOneSpec)
})
.then((runsResults) => {
// information about each test run is available
// see the full NPM API declaration in
// https://github.com/cypress-io/cypress/tree/develop/cli/types
// you can generate your own report,
// email or post a Slack message
// rerun the failing specs, etc.
// for now show just the summary
// by drilling down into specResults objects
const summary = runsResults
.map((oneRun) => oneRun.runs[0])
.map((run) => {
return {
spec: run.spec.name,
tests: run.stats.tests,
passes: run.stats.passes,
failures: run.stats.failures,
}
})
console.table('Test run summary', summary)
})