From 2c1e34c1b9095df77a3453b0286d4c4489e3e8c3 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sun, 23 Feb 2020 13:07:32 +0530 Subject: [PATCH] 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 --- .../generators/__tests__/init-generator.test.ts | 14 ++++++++++++-- packages/generators/package.json | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/generators/__tests__/init-generator.test.ts b/packages/generators/__tests__/init-generator.test.ts index 0b294ab2554..20cc421642d 100644 --- a/packages/generators/__tests__/init-generator.test.ts +++ b/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({ @@ -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; diff --git a/packages/generators/package.json b/packages/generators/package.json index c884a5f9480..8a6107df536 100644 --- a/packages/generators/package.json +++ b/packages/generators/package.json @@ -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",