diff --git a/test/loader/loader.test.js b/test/loader/loader.test.js index bf1638a239d..6ee115a8853 100644 --- a/test/loader/loader.test.js +++ b/test/loader/loader.test.js @@ -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); }); @@ -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}`]); diff --git a/test/plugin/plugin.test.js b/test/plugin/plugin.test.js index ac41d218dd6..bad234e7a83 100644 --- a/test/plugin/plugin.test.js +++ b/test/plugin/plugin.test.js @@ -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); }); @@ -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}`]);