Skip to content

Commit

Permalink
tests(generator): enhance init generator tests (#1236)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
anshumanv and rishabh3112 committed Feb 23, 2020
1 parent 6ee61b9 commit 2c1e34c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions packages/generators/__tests__/init-generator.test.ts
@@ -1,7 +1,7 @@
import { join } from 'path';
import * as assert from 'yeoman-assert';
import { run } from 'yeoman-test';
import { join } from 'path';

// fixme: unstable
describe('init generator', () => {
it('generates a webpack project config', async () => {
const outputDir = await run(join(__dirname, '../src/init-generator')).withPrompts({
Expand All @@ -12,6 +12,16 @@ describe('init generator', () => {
stylingType: 'No',
useExtractPlugin: 'main',
});

// Check that all the project files are generated with the correct name
const filePaths = ['package.json', 'README.md', 'src/index2.js'];
assert.file(filePaths.map(file => join(outputDir, file)));

// Check generated file contents
assert.fileContent(join(outputDir, 'package.json'), '"name": "my-webpack-project"');
assert.fileContent(join(outputDir, 'README.md'), 'Welcome to your new awesome project!');
assert.fileContent(join(outputDir, 'src', 'index2.js'), 'console.log("Hello World from your main file!");');

const output = require(join(outputDir, '.yo-rc.json'));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config = (Object.entries(output)[0][1] as any).configuration.config.webpackOptions;
Expand Down
6 changes: 3 additions & 3 deletions packages/generators/package.json
Expand Up @@ -35,12 +35,12 @@
"@types/mkdirp": "0.5.2",
"@types/node": "12.7.2",
"@types/webpack-dev-server": "3.1.7",
"@types/yeoman-assert": "^3.1.1",
"@types/yeoman-generator": "3.1.4",
"@types/yeoman-test": "2.0.3",
"@types/yeoman-assert": "^3.1.1",
"typescript": "3.5.3",
"yeoman-test": "2.1.0",
"yeoman-assert": "^3.1.1"
"yeoman-assert": "^3.1.1",
"yeoman-test": "2.1.0"
},
"scripts": {
"build": "tsc",
Expand Down

0 comments on commit 2c1e34c

Please sign in to comment.