@@ -4,6 +4,9 @@ import path from 'path'
44import fs from 'fs'
55import { mkdirp } from 'mkdirp'
66import { fileURLToPath } from 'url'
7+ import sinon from 'sinon'
8+ import inquirer from 'inquirer'
9+ import * as initModule from '../../lib/command/init.js'
710
811const __filename = fileURLToPath ( import . meta. url )
912const __dirname = path . dirname ( __filename )
@@ -13,29 +16,24 @@ const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/init')
1316describe ( 'Init Command' , function ( ) {
1417 this . timeout ( 20000 )
1518
19+ let promptStub ;
20+
1621 beforeEach ( ( ) => {
1722 mkdirp . sync ( codecept_dir )
1823 process . env . _INIT_DRY_RUN_INSTALL = true
24+ process . env . CODECEPT_TEST = 'true'
25+ promptStub = sinon . stub ( inquirer , 'prompt' )
1926 } )
2027
2128 afterEach ( ( ) => {
2229 try {
23- fs . unlinkSync ( `${ codecept_dir } /codecept.conf.ts` )
24- fs . unlinkSync ( `${ codecept_dir } /steps_file.ts` )
25- fs . unlinkSync ( `${ codecept_dir } /tsconfig.json` )
30+ fs . rmSync ( codecept_dir , { recursive : true , force : true } )
2631 } catch ( e ) {
2732 // continue regardless of error
2833 }
29-
30- try {
31- fs . unlinkSync ( `${ codecept_dir } /codecept.conf.js` )
32- fs . unlinkSync ( `${ codecept_dir } /steps_file.js` )
33- fs . unlinkSync ( `${ codecept_dir } /jsconfig.json` )
34- } catch ( e ) {
35- // continue regardless of error
36- }
37-
34+ sinon . restore ( )
3835 delete process . env . _INIT_DRY_RUN_INSTALL
36+ delete process . env . CODECEPT_TEST
3937 } )
4038
4139 it ( 'should have init command available and noTranslation defined' , async ( ) => {
@@ -63,4 +61,31 @@ describe('Init Command', function () {
6361 throw error
6462 }
6563 } )
64+
65+ it ( 'should initialize a JS project' , async ( ) => {
66+ // When yes: true, it skips prompts
67+ await initModule . default ( codecept_dir , { yes : true } )
68+
69+ fs . existsSync ( path . join ( codecept_dir , 'codecept.conf.js' ) ) . should . be . true
70+ fs . existsSync ( path . join ( codecept_dir , 'steps_file.js' ) ) . should . be . true
71+ } )
72+
73+ it ( 'should initialize a TS project' , async ( ) => {
74+ promptStub . onCall ( 0 ) . resolves ( {
75+ typescript : true ,
76+ tests : './tests/*_test.ts' ,
77+ helper : 'Playwright' ,
78+ output : './output' ,
79+ } )
80+ promptStub . onCall ( 1 ) . resolves ( {
81+ Playwright_browser : 'chromium' ,
82+ Playwright_url : 'http://localhost' ,
83+ Playwright_show : false ,
84+ } )
85+
86+ await initModule . default ( codecept_dir , { yes : false } )
87+
88+ fs . existsSync ( path . join ( codecept_dir , 'codecept.conf.ts' ) ) . should . be . true
89+ fs . existsSync ( path . join ( codecept_dir , 'steps_file.ts' ) ) . should . be . true
90+ } )
6691} )
0 commit comments