|
| 1 | +import { join } from 'path'; |
| 2 | +import { run } from 'yeoman-test'; |
| 3 | +const assert = require('yeoman-assert'); |
| 4 | +import { generatePluginName } from '../utils'; |
| 5 | + |
| 6 | +describe('plugin generator', () => { |
| 7 | + it('generates a default plugin', async () => { |
| 8 | + const outputDir = await run(join(__dirname, '../plugin-generator')); |
| 9 | + const pluginDir = `${outputDir}/my-webpack-plugin`; |
| 10 | + const srcFiles = ['cjs.js', 'index.js']; |
| 11 | + const testFiles = ['functional.test.js', 'test-utils.js']; |
| 12 | + const exampleFiles = ['webpack.config.js', 'src/index.js', 'src/lazy-module.js', 'src/static-esm-module.js']; |
| 13 | + |
| 14 | + // Check that files in all folders are scaffolded. Checking them separately so we know which directory has the problem |
| 15 | + // assert for src files |
| 16 | + assert.file([...srcFiles.map(file => `${pluginDir}/src/${file}`)]); |
| 17 | + |
| 18 | + // assert for test files |
| 19 | + assert.file([...testFiles.map(file => `${pluginDir}/test/${file}`)]); |
| 20 | + |
| 21 | + // assert for example files |
| 22 | + assert.file([...exampleFiles.map(file => `${pluginDir}/examples/simple/${file}`)]); |
| 23 | + |
| 24 | + // Check the contents of the webpack config and loader file |
| 25 | + assert.fileContent([ |
| 26 | + [`${pluginDir}/examples/simple/webpack.config.js`, 'new MyWebpackPlugin()'], |
| 27 | + [`${pluginDir}/src/index.js`, 'MyWebpackPlugin.prototype.apply = function(compiler) {'], |
| 28 | + ]); |
| 29 | + |
| 30 | + // higher timeout so travis has enough time to execute |
| 31 | + }, 10000); |
| 32 | +}); |
| 33 | + |
| 34 | +describe('generate plugin name', () => { |
| 35 | + it('should return webpack Standard Plugin Name for Name : extract-text-webpack-plugin', () => { |
| 36 | + const pluginName = generatePluginName('extract-text-webpack-plugin'); |
| 37 | + expect(pluginName).toEqual('ExtractTextWebpackPlugin'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should return webpack Standard Plugin Name for Name : webpack.DefinePlugin', () => { |
| 41 | + const pluginName = generatePluginName('webpack.DefinePlugin'); |
| 42 | + expect(pluginName).toEqual('webpack.DefinePlugin'); |
| 43 | + }); |
| 44 | +}); |
0 commit comments