-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
cypress.js
55 lines (45 loc) · 1.32 KB
/
cypress.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
// https://github.com/cypress-io/cypress/issues/316
const Promise = require('bluebird')
const tmp = Promise.promisifyAll(require('tmp'))
const fs = require('./fs')
const open = require('./exec/open')
const run = require('./exec/run')
const util = require('./util')
const cypressModuleApi = {
/**
* Opens Cypress GUI
* @see https://on.cypress.io/module-api#cypress-open
*/
open (options = {}) {
options = util.normalizeModuleOptions(options)
return open.start(options)
},
/**
* Runs Cypress tests in the current project
* @see https://on.cypress.io/module-api#cypress-run
*/
run (options = {}) {
if (!run.isValidProject(options.project)) {
return Promise.reject(new Error(`Invalid project path parameter: ${options.project}`))
}
options = util.normalizeModuleOptions(options)
return tmp.fileAsync()
.then((outputPath) => {
options.outputPath = outputPath
return run.start(options)
.then((failedTests) => {
return fs.readJsonAsync(outputPath, { throws: false })
.then((output) => {
if (!output) {
return {
failures: failedTests,
message: 'Could not find Cypress test run results',
}
}
return output
})
})
})
},
}
module.exports = cypressModuleApi