@@ -40,14 +40,31 @@ describe("readCypressConfigUtil", () => {
4040
4141 describe ( 'loadJsFile' , ( ) => {
4242 it ( 'should load js file' , ( ) => {
43- sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
43+ const loadCommandStub = sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
4444 const readFileSyncStub = sandbox . stub ( fs , 'readFileSync' ) . returns ( '{"e2e": {}}' ) ;
4545 const existsSyncStub = sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
4646 const unlinkSyncSyncStub = sandbox . stub ( fs , 'unlinkSync' ) ;
4747
4848 const result = readCypressConfigUtil . loadJsFile ( 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
4949
5050 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"` ) ;
5168 sinon . assert . calledOnce ( readFileSyncStub ) ;
5269 sinon . assert . calledOnce ( unlinkSyncSyncStub ) ;
5370 sinon . assert . calledOnce ( existsSyncStub ) ;
@@ -62,11 +79,28 @@ describe("readCypressConfigUtil", () => {
6279 cypress_config_filename : 'cypress.config.ts'
6380 }
6481 } ;
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" ) ;
6699
67100 const result = readCypressConfigUtil . convertTsConfig ( bsConfig , 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
68101
69102 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' } ) ;
70104 } ) ;
71105
72106 it ( 'should return null if compilation fails' , ( ) => {
@@ -92,7 +126,7 @@ describe("readCypressConfigUtil", () => {
92126 } ;
93127 const execSyncStub = sandbox . stub ( cp , "execSync" )
94128 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' } )
96130 . throws ( {
97131 output : Buffer . from ( "Error: Some Error \n TSFILE: path/to/compiled/cypress.config.js" )
98132 } ) ;
0 commit comments