22const chai = require ( "chai" ) ,
33 expect = chai . expect ,
44 sinon = require ( "sinon" ) ,
5+ path = require ( 'path' ) ,
56 EventEmitter = require ( 'events' ) ;
67
78const logger = require ( "../../../../bin/helpers/logger" ) . winstonLogger ;
@@ -40,14 +41,33 @@ describe("readCypressConfigUtil", () => {
4041
4142 describe ( 'loadJsFile' , ( ) => {
4243 it ( 'should load js file' , ( ) => {
43- sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
44+ const loadCommandStub = sandbox . stub ( cp , "execSync" ) . returns ( "random string" ) ;
4445 const readFileSyncStub = sandbox . stub ( fs , 'readFileSync' ) . returns ( '{"e2e": {}}' ) ;
4546 const existsSyncStub = sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
4647 const unlinkSyncSyncStub = sandbox . stub ( fs , 'unlinkSync' ) ;
48+ const requireModulePath = path . join ( __dirname , '../../../../' , 'bin' , 'helpers' , 'requireModule.js' ) ;
4749
4850 const result = readCypressConfigUtil . loadJsFile ( 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
4951
5052 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"` ) ;
5171 sinon . assert . calledOnce ( readFileSyncStub ) ;
5272 sinon . assert . calledOnce ( unlinkSyncSyncStub ) ;
5373 sinon . assert . calledOnce ( existsSyncStub ) ;
@@ -62,11 +82,28 @@ describe("readCypressConfigUtil", () => {
6282 cypress_config_filename : 'cypress.config.ts'
6383 }
6484 } ;
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" ) ;
66102
67103 const result = readCypressConfigUtil . convertTsConfig ( bsConfig , 'path/to/cypress.config.ts' , 'path/to/tmpBstackPackages' ) ;
68104
69105 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' } ) ;
70107 } ) ;
71108
72109 it ( 'should return null if compilation fails' , ( ) => {
@@ -92,7 +129,7 @@ describe("readCypressConfigUtil", () => {
92129 } ;
93130 const execSyncStub = sandbox . stub ( cp , "execSync" )
94131 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' } )
96133 . throws ( {
97134 output : Buffer . from ( "Error: Some Error \n TSFILE: path/to/compiled/cypress.config.js" )
98135 } ) ;
0 commit comments