@@ -40,14 +40,31 @@ describe("readCypressConfigUtil", () => {
40
40
41
41
describe ( 'loadJsFile' , ( ) => {
42
42
it ( 'should load js file' , ( ) => {
43
- sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
43
+ const loadCommandStub = sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
44
44
const readFileSyncStub = sandbox . stub ( fs , 'readFileSync' ) . returns ( '{"e2e": {}}' ) ;
45
45
const existsSyncStub = sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
46
46
const unlinkSyncSyncStub = sandbox . stub ( fs , 'unlinkSync' ) ;
47
47
48
48
const result = readCypressConfigUtil . loadJsFile ( 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
49
49
50
50
expect ( result ) . to . eql ( { e2e : { } } ) ;
51
+ sinon . assert . calledOnceWithExactly ( loadCommandStub , `NODE_PATH="path/to/tmpBstackPackages" node "/Users/prajwaldhawarikar/Developer/projects/temp/browserstack-cypress-cli/bin/helpers/requireModule.js" "path/to/cypress.config.ts"` ) ;
52
+ sinon . assert . calledOnce ( readFileSyncStub ) ;
53
+ sinon . assert . calledOnce ( unlinkSyncSyncStub ) ;
54
+ sinon . assert . calledOnce ( existsSyncStub ) ;
55
+ } ) ;
56
+
57
+ it ( 'should load js file for win' , ( ) => {
58
+ sinon . stub ( process , 'platform' ) . value ( 'win32' ) ;
59
+ const loadCommandStub = sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
60
+ const readFileSyncStub = sandbox . stub ( fs , 'readFileSync' ) . returns ( '{"e2e": {}}' ) ;
61
+ const existsSyncStub = sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
62
+ const unlinkSyncSyncStub = sandbox . stub ( fs , 'unlinkSync' ) ;
63
+
64
+ const result = readCypressConfigUtil . loadJsFile ( 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
65
+
66
+ expect ( result ) . to . eql ( { e2e : { } } ) ;
67
+ sinon . assert . calledOnceWithExactly ( loadCommandStub , `set NODE_PATH=path/to/tmpBstackPackages&& node "/Users/prajwaldhawarikar/Developer/projects/temp/browserstack-cypress-cli/bin/helpers/requireModule.js" "path/to/cypress.config.ts"` ) ;
51
68
sinon . assert . calledOnce ( readFileSyncStub ) ;
52
69
sinon . assert . calledOnce ( unlinkSyncSyncStub ) ;
53
70
sinon . assert . calledOnce ( existsSyncStub ) ;
@@ -62,11 +79,28 @@ describe("readCypressConfigUtil", () => {
62
79
cypress_config_filename : 'cypress.config.ts'
63
80
}
64
81
} ;
65
- sandbox . stub ( cp , "execSync" ) . returns ( "TSFILE: path/to/compiled/cypress.config.js" ) ;
82
+ const compileTsStub = sandbox . stub ( cp , "execSync" ) . returns ( "TSFILE: path/to/compiled/cypress.config.js" ) ;
83
+
84
+ const result = readCypressConfigUtil . convertTsConfig ( bsConfig , 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
85
+
86
+ expect ( result ) . to . eql ( 'path/to/compiled/cypress.config.js' ) ;
87
+ 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' } ) ;
88
+ } ) ;
89
+
90
+ it ( 'should compile cypress.config.ts to cypress.config.js for win' , ( ) => {
91
+ sinon . stub ( process , 'platform' ) . value ( 'win32' ) ;
92
+ const bsConfig = {
93
+ run_settings : {
94
+ cypressConfigFilePath : 'path/to/cypress.config.ts' ,
95
+ cypress_config_filename : 'cypress.config.ts'
96
+ }
97
+ } ;
98
+ const compileTsStub = sandbox . stub ( cp , "execSync" ) . returns ( "TSFILE: path/to/compiled/cypress.config.js" ) ;
66
99
67
100
const result = readCypressConfigUtil . convertTsConfig ( bsConfig , 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
68
101
69
102
expect ( result ) . to . eql ( 'path/to/compiled/cypress.config.js' ) ;
103
+ 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
104
} ) ;
71
105
72
106
it ( 'should return null if compilation fails' , ( ) => {
@@ -92,7 +126,7 @@ describe("readCypressConfigUtil", () => {
92
126
} ;
93
127
const execSyncStub = sandbox . stub ( cp , "execSync" )
94
128
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' } )
129
+ . 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
130
. throws ( {
97
131
output : Buffer . from ( "Error: Some Error \n TSFILE: path/to/compiled/cypress.config.js" )
98
132
} ) ;
0 commit comments