Skip to content

Commit 2c1e34c

Browse files
tests(generator): enhance init generator tests (#1236)
* tests(generator): enahnce init generator tests enhance init generator tests * tests(generator): fix docs typo fix docs typo * tests(init-gen): fix import in init-gen * tests(test): use join in tests use join * tests(tests): add types for yeoman-assert Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
1 parent 6ee61b9 commit 2c1e34c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/generators/__tests__/init-generator.test.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { join } from 'path';
1+
import * as assert from 'yeoman-assert';
22
import { run } from 'yeoman-test';
3+
import { join } from 'path';
34

4-
// fixme: unstable
55
describe('init generator', () => {
66
it('generates a webpack project config', async () => {
77
const outputDir = await run(join(__dirname, '../src/init-generator')).withPrompts({
@@ -12,6 +12,16 @@ describe('init generator', () => {
1212
stylingType: 'No',
1313
useExtractPlugin: 'main',
1414
});
15+
16+
// Check that all the project files are generated with the correct name
17+
const filePaths = ['package.json', 'README.md', 'src/index2.js'];
18+
assert.file(filePaths.map(file => join(outputDir, file)));
19+
20+
// Check generated file contents
21+
assert.fileContent(join(outputDir, 'package.json'), '"name": "my-webpack-project"');
22+
assert.fileContent(join(outputDir, 'README.md'), 'Welcome to your new awesome project!');
23+
assert.fileContent(join(outputDir, 'src', 'index2.js'), 'console.log("Hello World from your main file!");');
24+
1525
const output = require(join(outputDir, '.yo-rc.json'));
1626
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1727
const config = (Object.entries(output)[0][1] as any).configuration.config.webpackOptions;

packages/generators/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
"@types/mkdirp": "0.5.2",
3636
"@types/node": "12.7.2",
3737
"@types/webpack-dev-server": "3.1.7",
38+
"@types/yeoman-assert": "^3.1.1",
3839
"@types/yeoman-generator": "3.1.4",
3940
"@types/yeoman-test": "2.0.3",
40-
"@types/yeoman-assert": "^3.1.1",
4141
"typescript": "3.5.3",
42-
"yeoman-test": "2.1.0",
43-
"yeoman-assert": "^3.1.1"
42+
"yeoman-assert": "^3.1.1",
43+
"yeoman-test": "2.1.0"
4444
},
4545
"scripts": {
4646
"build": "tsc",

0 commit comments

Comments
 (0)