1
1
// https://github.com/cypress-io/cypress/issues/316
2
-
3
- import Bluebird from 'bluebird'
4
2
import tmpModule from 'tmp'
5
- import fs from './fs '
3
+ import fs from 'fs-extra '
6
4
import openModule from './exec/open'
7
5
import runModule from './exec/run'
8
6
import util from './util'
9
7
import cli from './cli'
10
8
11
- const tmp = Bluebird . promisifyAll ( tmpModule ) as any
12
-
13
9
const cypressModuleApi = {
14
10
/**
15
11
* Opens Cypress GUI
@@ -25,35 +21,30 @@ const cypressModuleApi = {
25
21
* Runs Cypress tests in the current project
26
22
* @see https://on.cypress.io/module-api#cypress-run
27
23
*/
28
- run ( options : any = { } ) : any {
24
+ async run ( options : any = { } ) : Promise < any > {
29
25
if ( ! runModule . isValidProject ( options . project ) ) {
30
- return Bluebird . reject ( new Error ( `Invalid project path parameter: ${ options . project } ` ) )
26
+ throw new Error ( `Invalid project path parameter: ${ options . project } ` )
31
27
}
32
28
33
29
options = util . normalizeModuleOptions ( options )
30
+ tmpModule . setGracefulCleanup ( )
34
31
35
- tmp . setGracefulCleanup ( )
32
+ const outputPath : string = tmpModule . file ( )
36
33
37
- return tmp . fileAsync ( )
38
- . then ( ( outputPath : string ) => {
39
- options . outputPath = outputPath
34
+ options . outputPath = outputPath
40
35
41
- return runModule . start ( options )
42
- . then ( ( failedTests : any ) => {
43
- return fs . readJsonAsync ( outputPath , { throws : false } )
44
- . then ( ( output : any ) => {
45
- if ( ! output ) {
46
- return {
47
- status : 'failed' ,
48
- failures : failedTests ,
49
- message : 'Could not find Cypress test run results' ,
50
- }
51
- }
36
+ const failedTests = await runModule . start ( options )
37
+ const output = fs . readJson ( outputPath , { throws : false } )
38
+
39
+ if ( ! output ) {
40
+ return {
41
+ status : 'failed' ,
42
+ failures : failedTests ,
43
+ message : 'Could not find Cypress test run results' ,
44
+ }
45
+ }
52
46
53
- return output
54
- } )
55
- } )
56
- } )
47
+ return output
57
48
} ,
58
49
59
50
cli : {
0 commit comments