Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(generator): add tests for plugin generator #1235

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -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');
});
});