Skip to content

Commit

Permalink
test: add cases for alias (#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed May 13, 2021
1 parent 7ab5468 commit 4f383e0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/loader/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,34 @@ describe('loader command', () => {

expect(stderr).toContain('unknown is not a valid template');
});

it("recognizes '-t' as an alias for '--template'", async () => {
const assetsPath = await uniqueDirectoryForTest();
const { defaultLoaderPath } = dataForTests(assetsPath);
let { stdout } = await runPromptWithAnswers(assetsPath, ['loader', '-t', 'default'], [`${ENTER}`]);

expect(normalizeStdout(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 } = await run(path, []));

expect(stdout).toContain('my-loader');
});
});
21 changes: 21 additions & 0 deletions test/plugin/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,25 @@ describe('plugin command', () => {

expect(stderr).toContain('unknown is not a valid template');
});

it("recognizes '-t' as an alias for '--template'", async () => {
const assetsPath = await uniqueDirectoryForTest();
const { defaultPluginPath } = dataForTests(assetsPath);
const { stdout } = await runPromptWithAnswers(assetsPath, ['plugin', '-t', 'default'], [`${ENTER}`]);
expect(normalizeStdout(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
const { stdout: stdout2 } = await run(__dirname, ['--config', './my-webpack-plugin/examples/simple/webpack.config.js']);
expect(normalizeStdout(stdout2)).toContain('Hello World!');
});
});

0 comments on commit 4f383e0

Please sign in to comment.