Skip to content

test: default loader name and plugin name #2392

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

Merged
merged 4 commits into from
Feb 2, 2021
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
28 changes: 28 additions & 0 deletions test/loader/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ const firstPrompt = '? Loader name (my-loader)';
const ENTER = '\x0D';
const loaderName = 'test-loader';
const loaderPath = join(__dirname, loaderName);
const defaultLoaderPath = join(__dirname, 'my-loader');
const genPath = join(__dirname, 'test-assets');
const customLoaderPath = join(genPath, loaderName);

describe('loader command', () => {
beforeEach(() => {
rimraf.sync(defaultLoaderPath);
rimraf.sync(loaderPath);
rimraf.sync(genPath);
});
Expand All @@ -26,6 +28,32 @@ describe('loader command', () => {
expect(stripAnsi(stdout)).toContain(firstPrompt);
});

it('should scaffold loader with default name if no loader name provided', async () => {
let { stdout } = await runPromptWithAnswers(__dirname, ['loader'], [`${ENTER}`]);

expect(stripAnsi(stdout)).toContain(firstPrompt);

// Skip test in case installation fails
if (!existsSync(resolve(defaultLoaderPath, './yarn.lock'))) {
return;
}

// Check if the output directory exists with the appropriate loader name
expect(existsSync(defaultLoaderPath)).toBeTruthy();

// All test files are scaffolded
const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js'];

files.forEach((file) => {
expect(existsSync(defaultLoaderPath, file)).toBeTruthy();
});

// Check if the the generated loader works successfully
const path = resolve(__dirname, './my-loader/examples/simple/');
({ stdout } = run(path, [], false));
expect(stdout).toContain('my-loader');
});

it('should scaffold loader template with a given name', async () => {
let { stdout } = await runPromptWithAnswers(__dirname, ['loader'], [`${loaderName}${ENTER}`]);

Expand Down
27 changes: 27 additions & 0 deletions test/plugin/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ const firstPrompt = '? Plugin name';
const pluginName = 'test-plugin';

const pluginPath = join(__dirname, pluginName);
const defaultPluginPath = join(__dirname, 'my-webpack-plugin');
const genPath = join(__dirname, 'test-assets');
const customPluginPath = join(genPath, pluginName);

describe('plugin command', () => {
beforeEach(() => {
rimraf.sync(defaultPluginPath);
rimraf.sync(pluginPath);
rimraf.sync(genPath);
});
Expand All @@ -26,6 +28,31 @@ describe('plugin command', () => {
expect(stripAnsi(stdout)).toContain(firstPrompt);
});

it('should scaffold plugin with default name if no plugin name provided', async () => {
let { stdout } = await runPromptWithAnswers(__dirname, ['plugin'], [`${ENTER}`]);

expect(stripAnsi(stdout)).toContain(firstPrompt);

// Check if the output directory exists with the appropriate plugin name
expect(existsSync(defaultPluginPath)).toBeTruthy();

// Skip test in case installation fails
if (!existsSync(resolve(defaultPluginPath, './yarn.lock'))) {
return;
}

// Test regressively files are scaffolded
const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js'];

files.forEach((file) => {
expect(existsSync(join(defaultPluginPath, file))).toBeTruthy();
});

// Check if the the generated plugin works successfully
stdout = run(__dirname, ['--config', './my-webpack-plugin/examples/simple/webpack.config.js'], false).stdout;
expect(stdout).toContain('Hello World!');
});

it('should scaffold plugin template with a given name', async () => {
let { stdout } = await runPromptWithAnswers(__dirname, ['plugin'], [`${pluginName}${ENTER}`]);

Expand Down