Skip to content

Commit 8157190

Browse files
authored
Update init_test.js
1 parent e480890 commit 8157190

File tree

1 file changed

+51
-57
lines changed

1 file changed

+51
-57
lines changed

test/runner/init_test.js

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,78 @@
1-
const { DOWN, ENTER } = require('inquirer-test')
2-
const run = require('inquirer-test')
3-
const path = require('path')
4-
const fs = require('fs')
5-
const mkdirp = require('mkdirp')
1+
const path = require('path');
2+
const fs = require('fs');
3+
const mkdirp = require('mkdirp');
4+
const { createPromptModule } = require('@inquirer/testing');
65

7-
const runner = path.join(__dirname, '../../bin/codecept.js')
8-
const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/init')
6+
const runner = path.join(__dirname, '../../bin/codecept.js');
7+
const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/init');
98

109
describe('Init Command', function () {
11-
this.timeout(20000)
10+
this.timeout(20000);
1211

1312
beforeEach(() => {
14-
mkdirp.sync(codecept_dir)
15-
process.env._INIT_DRY_RUN_INSTALL = true
16-
})
13+
mkdirp.sync(codecept_dir);
14+
process.env._INIT_DRY_RUN_INSTALL = true;
15+
});
1716

1817
afterEach(() => {
1918
try {
20-
fs.unlinkSync(`${codecept_dir}/codecept.conf.ts`)
21-
fs.unlinkSync(`${codecept_dir}/steps_file.ts`)
22-
fs.unlinkSync(`${codecept_dir}/tsconfig.json`)
19+
fs.unlinkSync(`${codecept_dir}/codecept.conf.ts`);
20+
fs.unlinkSync(`${codecept_dir}/steps_file.ts`);
21+
fs.unlinkSync(`${codecept_dir}/tsconfig.json`);
2322
} catch (e) {
2423
// continue regardless of error
2524
}
2625

2726
try {
28-
fs.unlinkSync(`${codecept_dir}/codecept.conf.js`)
29-
fs.unlinkSync(`${codecept_dir}/steps_file.js`)
30-
fs.unlinkSync(`${codecept_dir}/jsconfig.json`)
27+
fs.unlinkSync(`${codecept_dir}/codecept.conf.js`);
28+
fs.unlinkSync(`${codecept_dir}/steps_file.js`);
29+
fs.unlinkSync(`${codecept_dir}/jsconfig.json`);
3130
} catch (e) {
3231
// continue regardless of error
3332
}
3433

35-
delete process.env._INIT_DRY_RUN_INSTALL
36-
})
34+
delete process.env._INIT_DRY_RUN_INSTALL;
35+
});
3736

3837
it('should init Codecept with TypeScript REST JSONResponse English', async () => {
39-
const result = await run(
40-
[runner, 'init', codecept_dir],
41-
['Y', ENTER, ENTER, DOWN, DOWN, DOWN, ENTER, 'y', ENTER, codecept_dir, ENTER, ENTER, ENTER, ENTER],
42-
)
38+
const prompt = createPromptModule();
39+
40+
prompt.inject([
41+
'Y', // Confirm TypeScript usage
42+
'', // Default for test location
43+
'DOWN', 'DOWN', 'DOWN', 'ENTER', // Select REST helper
44+
'y', // Confirm JSONResponse usage
45+
'', // Default for logs/screenshots/reports
46+
'', // Default for localization
47+
]);
4348

44-
result.should.include('Welcome to CodeceptJS initialization tool')
45-
result.should.include('It will prepare and configure a test environment for you')
46-
result.should.include('Installing to')
47-
result.should.include('? Do you plan to write tests in TypeScript? (y/N)')
48-
result.should.include('Where are your tests located? ./*_test.ts')
49-
result.should.include('What helpers do you want to use? REST')
50-
result.should.include('? Do you want to use JSONResponse helper for assertions on JSON responses?')
51-
result.should.include('? Where should logs, screenshots, and reports to be stored?')
52-
result.should.include('? Do you want to enable localization for tests?')
49+
await require(runner).init(codecept_dir);
5350

54-
const config = fs.readFileSync(`${codecept_dir}/codecept.conf.ts`).toString()
55-
config.should.include("I: './steps_file'")
51+
const config = fs.readFileSync(`${codecept_dir}/codecept.conf.ts`).toString();
52+
config.should.include("I: './steps_file'");
5653

57-
fs.accessSync(`${codecept_dir}/steps_file.ts`, fs.constants.R_OK)
58-
fs.accessSync(`${codecept_dir}/tsconfig.json`, fs.constants.R_OK)
59-
})
54+
fs.accessSync(`${codecept_dir}/steps_file.ts`, fs.constants.R_OK);
55+
fs.accessSync(`${codecept_dir}/tsconfig.json`, fs.constants.R_OK);
56+
});
6057

6158
it.skip('should init Codecept with JavaScript REST JSONResponse de-DE', async () => {
62-
const result = await run(
63-
[runner, 'init', codecept_dir],
64-
[ENTER, ENTER, DOWN, DOWN, DOWN, ENTER, 'y', ENTER, codecept_dir, ENTER, DOWN, ENTER, ENTER, ENTER],
65-
)
59+
const prompt = createPromptModule();
6660

67-
result.should.include('Welcome to CodeceptJS initialization tool')
68-
result.should.include('It will prepare and configure a test environment for you')
69-
result.should.include('Installing to')
70-
result.should.include('? Do you plan to write tests in TypeScript? (y/N)')
71-
result.should.include('Where are your tests located? ./*_test.js')
72-
result.should.include('What helpers do you want to use? REST')
73-
result.should.include('? Do you want to use JSONResponse helper for assertions on JSON responses?')
74-
result.should.include('? Where should logs, screenshots, and reports to be stored?')
75-
result.should.include('? Do you want to enable localization for tests?')
76-
result.should.include('de-DE')
61+
prompt.inject([
62+
'', // Default (No TypeScript)
63+
'', // Default for test location
64+
'DOWN', 'DOWN', 'DOWN', 'ENTER', // Select REST helper
65+
'y', // Confirm JSONResponse usage
66+
'', // Default for logs/screenshots/reports
67+
'DOWN', '', // Select de-DE localization
68+
]);
7769

78-
const config = fs.readFileSync(`${codecept_dir}/codecept.conf.js`).toString()
79-
config.should.include("Ich: './steps_file.js'")
70+
await require(runner).init(codecept_dir);
8071

81-
fs.accessSync(`${codecept_dir}/steps_file.js`, fs.constants.R_OK)
82-
fs.accessSync(`${codecept_dir}/jsconfig.json`, fs.constants.R_OK)
83-
})
84-
})
72+
const config = fs.readFileSync(`${codecept_dir}/codecept.conf.js`).toString();
73+
config.should.include("Ich: './steps_file.js'");
74+
75+
fs.accessSync(`${codecept_dir}/steps_file.js`, fs.constants.R_OK);
76+
fs.accessSync(`${codecept_dir}/jsconfig.json`, fs.constants.R_OK);
77+
});
78+
});

0 commit comments

Comments
 (0)