From 87f00ecd04ba408554e8c058b288520b41d4d65f Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Mon, 8 Jun 2026 13:23:46 +0200 Subject: [PATCH 1/2] fix(init): missing file ext of step file when using typescript --- lib/command/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command/init.js b/lib/command/init.js index 0797cee6d..1d98697f4 100644 --- a/lib/command/init.js +++ b/lib/command/init.js @@ -206,7 +206,7 @@ export default async function (initPath, options = {}) { const stepFile = `./steps_file.${extension}` fs.writeFileSync(path.join(testsPath, stepFile), extension === 'ts' ? defaultActorTs : defaultActor) - config.include = { I: isTypeScript ? './steps_file' : stepFile } + config.include = { I: isTypeScript ? './steps_file.ts' : stepFile } print(`Steps file created at ${stepFile}`) From c77f35de69edd9b9298a8df6d5d8b9be08f227aa Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Thu, 11 Jun 2026 15:27:46 +0200 Subject: [PATCH 2/2] add more tests --- lib/command/init.js | 2 ++ test/runner/init_test.js | 49 ++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/lib/command/init.js b/lib/command/init.js index 1d98697f4..c768dbf41 100644 --- a/lib/command/init.js +++ b/lib/command/init.js @@ -317,6 +317,8 @@ export default async function (initPath, options = {}) { return } + if (process.env.CODECEPT_TEST) return + const generatedTest = generateTest(testsPath) if (!generatedTest) return generatedTest.then(() => { diff --git a/test/runner/init_test.js b/test/runner/init_test.js index c05489ff1..ca993356b 100644 --- a/test/runner/init_test.js +++ b/test/runner/init_test.js @@ -4,6 +4,9 @@ import path from 'path' import fs from 'fs' import { mkdirp } from 'mkdirp' import { fileURLToPath } from 'url' +import sinon from 'sinon' +import inquirer from 'inquirer' +import * as initModule from '../../lib/command/init.js' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) @@ -13,29 +16,24 @@ const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/init') describe('Init Command', function () { this.timeout(20000) + let promptStub; + beforeEach(() => { mkdirp.sync(codecept_dir) process.env._INIT_DRY_RUN_INSTALL = true + process.env.CODECEPT_TEST = 'true' + promptStub = sinon.stub(inquirer, 'prompt') }) afterEach(() => { try { - fs.unlinkSync(`${codecept_dir}/codecept.conf.ts`) - fs.unlinkSync(`${codecept_dir}/steps_file.ts`) - fs.unlinkSync(`${codecept_dir}/tsconfig.json`) + fs.rmSync(codecept_dir, { recursive: true, force: true }) } catch (e) { // continue regardless of error } - - try { - fs.unlinkSync(`${codecept_dir}/codecept.conf.js`) - fs.unlinkSync(`${codecept_dir}/steps_file.js`) - fs.unlinkSync(`${codecept_dir}/jsconfig.json`) - } catch (e) { - // continue regardless of error - } - + sinon.restore() delete process.env._INIT_DRY_RUN_INSTALL + delete process.env.CODECEPT_TEST }) it('should have init command available and noTranslation defined', async () => { @@ -63,4 +61,31 @@ describe('Init Command', function () { throw error } }) + + it('should initialize a JS project', async () => { + // When yes: true, it skips prompts + await initModule.default(codecept_dir, { yes: true }) + + fs.existsSync(path.join(codecept_dir, 'codecept.conf.js')).should.be.true + fs.existsSync(path.join(codecept_dir, 'steps_file.js')).should.be.true + }) + + it('should initialize a TS project', async () => { + promptStub.onCall(0).resolves({ + typescript: true, + tests: './tests/*_test.ts', + helper: 'Playwright', + output: './output', + }) + promptStub.onCall(1).resolves({ + Playwright_browser: 'chromium', + Playwright_url: 'http://localhost', + Playwright_show: false, + }) + + await initModule.default(codecept_dir, { yes: false }) + + fs.existsSync(path.join(codecept_dir, 'codecept.conf.ts')).should.be.true + fs.existsSync(path.join(codecept_dir, 'steps_file.ts')).should.be.true + }) })