diff --git a/packages/generators/__tests__/loader-generator.test.ts b/packages/generators/__tests__/loader-generator.test.ts index 6b5d28fd084..988380c3e87 100644 --- a/packages/generators/__tests__/loader-generator.test.ts +++ b/packages/generators/__tests__/loader-generator.test.ts @@ -6,8 +6,11 @@ import { makeLoaderName } from '../loader-generator'; describe('loader generator', () => { it('generates a default loader', async () => { - const outputDir = await run(join(__dirname, '../loader-generator')); - const loaderDir = join(outputDir, 'my-loader'); + const loaderName = 'my-test-loader'; + const outputDir = await run(join(__dirname, '../loader-generator')).withPrompts({ + name: loaderName, + }); + const loaderDir = join(outputDir, loaderName); const srcFiles = ['cjs.js', 'index.js']; const testFiles = ['functional.test.js', 'test-utils.js', 'unit.test.js', 'fixtures/simple-file.js']; const exampleFiles = ['webpack.config.js', 'src/index.js', 'src/lazy-module.js', 'src/static-esm-module.js']; @@ -26,6 +29,7 @@ describe('loader generator', () => { assert.fileContent([ [join(loaderDir, 'examples/simple/webpack.config.js'), /resolveLoader: {/], [join(loaderDir, 'src/index.js'), /export default function loader\(source\) {/], + [join(loaderDir, 'package.json'), new RegExp(loaderName)], ]); // higher timeout so travis has enough time to execute diff --git a/packages/generators/__tests__/plugin-generator.test.ts b/packages/generators/__tests__/plugin-generator.test.ts index aa4641279ea..11aec456172 100644 --- a/packages/generators/__tests__/plugin-generator.test.ts +++ b/packages/generators/__tests__/plugin-generator.test.ts @@ -1,31 +1,35 @@ import { join } from 'path'; import { run } from 'yeoman-test'; -import assert from 'yeoman-assert'; +import * as assert from 'yeoman-assert'; import { generatePluginName } from '../utils'; describe('plugin generator', () => { - it.skip('generates a default plugin', async () => { - const outputDir = await run(join(__dirname, '../plugin-generator')); - const pluginDir = `${outputDir}/my-webpack-plugin`; + it('generates a default plugin', async () => { + const pluginName = 'my-test-plugin'; + const outputDir = await run(join(__dirname, '../plugin-generator')).withPrompts({ + name: pluginName, + }); + const pluginDir = join(outputDir, pluginName); const srcFiles = ['cjs.js', 'index.js']; const testFiles = ['functional.test.js', 'test-utils.js']; const exampleFiles = ['webpack.config.js', 'src/index.js', 'src/lazy-module.js', 'src/static-esm-module.js']; // Check that files in all folders are scaffolded. Checking them separately so we know which directory has the problem // assert for src files - assert.file([...srcFiles.map(file => `${pluginDir}/src/${file}`)]); + assert.file(srcFiles.map(file => join(pluginDir, 'src', file))); // assert for test files - assert.file([...testFiles.map(file => `${pluginDir}/test/${file}`)]); + assert.file(testFiles.map(file => join(pluginDir, 'test', file))); // assert for example files - assert.file([...exampleFiles.map(file => `${pluginDir}/examples/simple/${file}`)]); + assert.file(exampleFiles.map(file => join(pluginDir, 'examples/simple', file))); // Check the contents of the webpack config and loader file assert.fileContent([ - [`${pluginDir}/examples/simple/webpack.config.js`, /new MyWebpackPlugin()/], - [`${pluginDir}/src/index.js`, /MyWebpackPlugin.prototype.apply = function(compiler) {/], + [join(pluginDir, 'examples/simple/webpack.config.js'), /new MyTestPlugin\(\)/], + [join(pluginDir, 'src/index.js'), /MyTestPlugin\.prototype\.apply = function\(compiler\) {/], + [join(pluginDir, 'package.json'), new RegExp(pluginName)], ]); // higher timeout so travis has enough time to execute diff --git a/packages/generators/addon-generator.ts b/packages/generators/addon-generator.ts index c287fedba90..810f8694290 100644 --- a/packages/generators/addon-generator.ts +++ b/packages/generators/addon-generator.ts @@ -59,6 +59,9 @@ const addonGenerator = ( } public writing(): void { + const packageJsonTemplatePath = "./templates/addon-package.json.js"; + this.fs.extendJSON(this.destinationPath("package.json"), require(packageJsonTemplatePath)(this.props.name)); + this.copy = copyUtils.generatorCopy(this, templateDir); this.copyTpl = copyUtils.generatorCopyTpl(this, templateDir, templateFn(this)); @@ -71,10 +74,6 @@ const addonGenerator = ( "save-dev": true }); } - - public end(): void { - this.spawnCommand("npm", ["run", "defaults"]); - } }; export default addonGenerator; diff --git a/packages/generators/templates/addon-package.json.js b/packages/generators/templates/addon-package.json.js new file mode 100644 index 00000000000..59b500d4317 --- /dev/null +++ b/packages/generators/templates/addon-package.json.js @@ -0,0 +1,7 @@ +module.exports = (name) => { + return { + version: "1.0.0", + description: "webpack loader", + name + }; +};