Skip to content

Commit

Permalink
test: default loader name and plugin name (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabh3112 authored Feb 2, 2021
1 parent b50d71b commit 2841cd7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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

0 comments on commit 2841cd7

Please sign in to comment.