Skip to content

Commit

Permalink
tests(generator): add tests for plugin generator (#1235)
Browse files Browse the repository at this point in the history
add tests for plugin generator
  • Loading branch information
anshumanv committed Feb 17, 2020
1 parent d2dd0c1 commit 1ab62d2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
13 changes: 0 additions & 13 deletions packages/generators/__tests__/add-generator.test.ts

This file was deleted.

44 changes: 44 additions & 0 deletions packages/generators/__tests__/plugin-generator.test.ts
@@ -0,0 +1,44 @@
import { join } from 'path';
import { run } from 'yeoman-test';
const assert = require('yeoman-assert');
import { generatePluginName } from '../utils';

describe('plugin generator', () => {
it('generates a default plugin', async () => {
const outputDir = await run(join(__dirname, '../plugin-generator'));
const pluginDir = `${outputDir}/my-webpack-plugin`;
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 for test files
assert.file([...testFiles.map(file => `${pluginDir}/test/${file}`)]);

// assert for example files
assert.file([...exampleFiles.map(file => `${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) {'],
]);

// higher timeout so travis has enough time to execute
}, 10000);
});

describe('generate plugin name', () => {
it('should return webpack Standard Plugin Name for Name : extract-text-webpack-plugin', () => {
const pluginName = generatePluginName('extract-text-webpack-plugin');
expect(pluginName).toEqual('ExtractTextWebpackPlugin');
});

it('should return webpack Standard Plugin Name for Name : webpack.DefinePlugin', () => {
const pluginName = generatePluginName('webpack.DefinePlugin');
expect(pluginName).toEqual('webpack.DefinePlugin');
});
});

0 comments on commit 1ab62d2

Please sign in to comment.