2
2
const chai = require ( "chai" ) ,
3
3
expect = chai . expect ,
4
4
sinon = require ( "sinon" ) ,
5
+ path = require ( 'path' ) ,
5
6
EventEmitter = require ( 'events' ) ;
6
7
7
8
const logger = require ( "../../../../bin/helpers/logger" ) . winstonLogger ;
@@ -40,14 +41,33 @@ describe("readCypressConfigUtil", () => {
40
41
41
42
describe ( 'loadJsFile' , ( ) => {
42
43
it ( 'should load js file' , ( ) => {
43
- sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
44
+ const loadCommandStub = sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
44
45
const readFileSyncStub = sandbox . stub ( fs , 'readFileSync' ) . returns ( '{"e2e": {}}' ) ;
45
46
const existsSyncStub = sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
46
47
const unlinkSyncSyncStub = sandbox . stub ( fs , 'unlinkSync' ) ;
48
+ const requireModulePath = path . join ( __dirname , '../../../../' , 'bin' , 'helpers' , 'requireModule.js' ) ;
47
49
48
50
const result = readCypressConfigUtil . loadJsFile ( 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
49
51
50
52
expect ( result ) . to . eql ( { e2e : { } } ) ;
53
+ sinon . assert . calledOnceWithExactly ( loadCommandStub , `NODE_PATH="path/to/tmpBstackPackages" node "${ requireModulePath } " "path/to/cypress.config.ts"` ) ;
54
+ sinon . assert . calledOnce ( readFileSyncStub ) ;
55
+ sinon . assert . calledOnce ( unlinkSyncSyncStub ) ;
56
+ sinon . assert . calledOnce ( existsSyncStub ) ;
57
+ } ) ;
58
+
59
+ it ( 'should load js file for win' , ( ) => {
60
+ sinon . stub ( process , 'platform' ) . value ( 'win32' ) ;
61
+ const loadCommandStub = sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
62
+ const readFileSyncStub = sandbox . stub ( fs , 'readFileSync' ) . returns ( '{"e2e": {}}' ) ;
63
+ const existsSyncStub = sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
64
+ const unlinkSyncSyncStub = sandbox . stub ( fs , 'unlinkSync' ) ;
65
+ const requireModulePath = path . join ( __dirname , '../../../../' , 'bin' , 'helpers' , 'requireModule.js' ) ;
66
+
67
+ const result = readCypressConfigUtil . loadJsFile ( 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
68
+
69
+ expect ( result ) . to . eql ( { e2e : { } } ) ;
70
+ sinon . assert . calledOnceWithExactly ( loadCommandStub , `set NODE_PATH=path/to/tmpBstackPackages&& node "${ requireModulePath } " "path/to/cypress.config.ts"` ) ;
51
71
sinon . assert . calledOnce ( readFileSyncStub ) ;
52
72
sinon . assert . calledOnce ( unlinkSyncSyncStub ) ;
53
73
sinon . assert . calledOnce ( existsSyncStub ) ;
@@ -62,11 +82,28 @@ describe("readCypressConfigUtil", () => {
62
82
cypress_config_filename : 'cypress.config.ts'
63
83
}
64
84
} ;
65
- sandbox . stub ( cp , "execSync" ) . returns ( "TSFILE: path/to/compiled/cypress.config.js" ) ;
85
+ const compileTsStub = sandbox . stub ( cp , "execSync" ) . returns ( "TSFILE: path/to/compiled/cypress.config.js" ) ;
86
+
87
+ const result = readCypressConfigUtil . convertTsConfig ( bsConfig , 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
88
+
89
+ expect ( result ) . to . eql ( 'path/to/compiled/cypress.config.js' ) ;
90
+ sinon . assert . calledOnceWithExactly ( compileTsStub , `NODE_PATH=path/to/tmpBstackPackages node "path/to/tmpBstackPackages/typescript/bin/tsc" --outDir "path/to/tmpBstackCompiledJs" --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false "path/to/cypress.config.ts"` , { cwd : 'path/to' } ) ;
91
+ } ) ;
92
+
93
+ it ( 'should compile cypress.config.ts to cypress.config.js for win' , ( ) => {
94
+ sinon . stub ( process , 'platform' ) . value ( 'win32' ) ;
95
+ const bsConfig = {
96
+ run_settings : {
97
+ cypressConfigFilePath : 'path/to/cypress.config.ts' ,
98
+ cypress_config_filename : 'cypress.config.ts'
99
+ }
100
+ } ;
101
+ const compileTsStub = sandbox . stub ( cp , "execSync" ) . returns ( "TSFILE: path/to/compiled/cypress.config.js" ) ;
66
102
67
103
const result = readCypressConfigUtil . convertTsConfig ( bsConfig , 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
68
104
69
105
expect ( result ) . to . eql ( 'path/to/compiled/cypress.config.js' ) ;
106
+ sinon . assert . calledOnceWithExactly ( compileTsStub , `set NODE_PATH=path/to/tmpBstackPackages&& node "path/to/tmpBstackPackages/typescript/bin/tsc" --outDir "path/to/tmpBstackCompiledJs" --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false "path/to/cypress.config.ts"` , { cwd : 'path/to' } ) ;
70
107
} ) ;
71
108
72
109
it ( 'should return null if compilation fails' , ( ) => {
@@ -92,7 +129,7 @@ describe("readCypressConfigUtil", () => {
92
129
} ;
93
130
const execSyncStub = sandbox . stub ( cp , "execSync" )
94
131
execSyncStub
95
- . withArgs ( `NODE_PATH=path/to/tmpBstackPackages path/to/tmpBstackPackages/typescript/bin/tsc --outDir path/to/tmpBstackCompiledJs --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false path/to/cypress.config.ts` , { cwd : 'path/to' } )
132
+ . withArgs ( `NODE_PATH=path/to/tmpBstackPackages node " path/to/tmpBstackPackages/typescript/bin/tsc" --outDir " path/to/tmpBstackCompiledJs" --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false " path/to/cypress.config.ts" ` , { cwd : 'path/to' } )
96
133
. throws ( {
97
134
output : Buffer . from ( "Error: Some Error \n TSFILE: path/to/compiled/cypress.config.js" )
98
135
} ) ;
0 commit comments