diff --git a/package.json b/package.json index 52f426738..e556fd0ea 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "fs-extra": "11.2.0", "glob": "6.0.1", "html-minifier-terser": "7.2.0", - "inquirer": "6.5.2", + "inquirer": "11.1.0", "joi": "17.13.3", "js-beautify": "1.15.1", "lodash.clonedeep": "4.5.0", @@ -146,7 +146,7 @@ "express": "4.19.2", "graphql": "16.9.0", "husky": "9.1.6", - "inquirer-test": "2.0.1", + "@inquirer/testing": "2.1.34", "jsdoc": "4.0.3", "jsdoc-typeof-plugin": "1.0.0", "json-server": "0.10.1", diff --git a/test/runner/init_test.js b/test/runner/init_test.js index 1128fbffc..d947b071e 100644 --- a/test/runner/init_test.js +++ b/test/runner/init_test.js @@ -1,84 +1,78 @@ -const { DOWN, ENTER } = require('inquirer-test') -const run = require('inquirer-test') -const path = require('path') -const fs = require('fs') -const mkdirp = require('mkdirp') +const path = require('path'); +const fs = require('fs'); +const mkdirp = require('mkdirp'); +const { PromptUI, inquirerPrompt } = require('@inquirer/testing'); // Correct imports -const runner = path.join(__dirname, '../../bin/codecept.js') -const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/init') +const runner = path.join(__dirname, '../../bin/codecept.js'); +const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/init'); describe('Init Command', function () { - this.timeout(20000) + this.timeout(20000); beforeEach(() => { - mkdirp.sync(codecept_dir) - process.env._INIT_DRY_RUN_INSTALL = true - }) + mkdirp.sync(codecept_dir); + process.env._INIT_DRY_RUN_INSTALL = true; + }); afterEach(() => { try { - fs.unlinkSync(`${codecept_dir}/codecept.conf.ts`) - fs.unlinkSync(`${codecept_dir}/steps_file.ts`) - fs.unlinkSync(`${codecept_dir}/tsconfig.json`) + fs.unlinkSync(`${codecept_dir}/codecept.conf.ts`); + fs.unlinkSync(`${codecept_dir}/steps_file.ts`); + fs.unlinkSync(`${codecept_dir}/tsconfig.json`); } 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`) + 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 } - delete process.env._INIT_DRY_RUN_INSTALL - }) + delete process.env._INIT_DRY_RUN_INSTALL; + }); it('should init Codecept with TypeScript REST JSONResponse English', async () => { - const result = await run( - [runner, 'init', codecept_dir], - ['Y', ENTER, ENTER, DOWN, DOWN, DOWN, ENTER, 'y', ENTER, codecept_dir, ENTER, ENTER, ENTER, ENTER], - ) + const promptUI = new PromptUI({ + input: inquirerPrompt([ + 'Y', // Confirm TypeScript usage + '', // Default for test location + 'DOWN', 'DOWN', 'DOWN', 'ENTER', // Select REST helper + 'y', // Confirm JSONResponse usage + '', // Default for logs/screenshots/reports + '', // Default for localization + ]) + }); - result.should.include('Welcome to CodeceptJS initialization tool') - result.should.include('It will prepare and configure a test environment for you') - result.should.include('Installing to') - result.should.include('? Do you plan to write tests in TypeScript? (y/N)') - result.should.include('Where are your tests located? ./*_test.ts') - result.should.include('What helpers do you want to use? REST') - result.should.include('? Do you want to use JSONResponse helper for assertions on JSON responses?') - result.should.include('? Where should logs, screenshots, and reports to be stored?') - result.should.include('? Do you want to enable localization for tests?') + await require(runner).init(codecept_dir); - const config = fs.readFileSync(`${codecept_dir}/codecept.conf.ts`).toString() - config.should.include("I: './steps_file'") + const config = fs.readFileSync(`${codecept_dir}/codecept.conf.ts`).toString(); + config.should.include("I: './steps_file'"); - fs.accessSync(`${codecept_dir}/steps_file.ts`, fs.constants.R_OK) - fs.accessSync(`${codecept_dir}/tsconfig.json`, fs.constants.R_OK) - }) + fs.accessSync(`${codecept_dir}/steps_file.ts`, fs.constants.R_OK); + fs.accessSync(`${codecept_dir}/tsconfig.json`, fs.constants.R_OK); + }); it.skip('should init Codecept with JavaScript REST JSONResponse de-DE', async () => { - const result = await run( - [runner, 'init', codecept_dir], - [ENTER, ENTER, DOWN, DOWN, DOWN, ENTER, 'y', ENTER, codecept_dir, ENTER, DOWN, ENTER, ENTER, ENTER], - ) + const promptUI = new PromptUI({ + input: inquirerPrompt([ + '', // Default (No TypeScript) + '', // Default for test location + 'DOWN', 'DOWN', 'DOWN', 'ENTER', // Select REST helper + 'y', // Confirm JSONResponse usage + '', // Default for logs/screenshots/reports + 'DOWN', '', // Select de-DE localization + ]) + }); - result.should.include('Welcome to CodeceptJS initialization tool') - result.should.include('It will prepare and configure a test environment for you') - result.should.include('Installing to') - result.should.include('? Do you plan to write tests in TypeScript? (y/N)') - result.should.include('Where are your tests located? ./*_test.js') - result.should.include('What helpers do you want to use? REST') - result.should.include('? Do you want to use JSONResponse helper for assertions on JSON responses?') - result.should.include('? Where should logs, screenshots, and reports to be stored?') - result.should.include('? Do you want to enable localization for tests?') - result.should.include('de-DE') + await require(runner).init(codecept_dir); - const config = fs.readFileSync(`${codecept_dir}/codecept.conf.js`).toString() - config.should.include("Ich: './steps_file.js'") + const config = fs.readFileSync(`${codecept_dir}/codecept.conf.js`).toString(); + config.should.include("Ich: './steps_file.js'"); - fs.accessSync(`${codecept_dir}/steps_file.js`, fs.constants.R_OK) - fs.accessSync(`${codecept_dir}/jsconfig.json`, fs.constants.R_OK) - }) -}) + fs.accessSync(`${codecept_dir}/steps_file.js`, fs.constants.R_OK); + fs.accessSync(`${codecept_dir}/jsconfig.json`, fs.constants.R_OK); + }); +}); \ No newline at end of file