diff --git a/packages/utils/__tests__/run-prettier.test.ts b/packages/utils/__tests__/run-prettier.test.ts index 8a04fa6ab3a..b407e54b77c 100644 --- a/packages/utils/__tests__/run-prettier.test.ts +++ b/packages/utils/__tests__/run-prettier.test.ts @@ -5,10 +5,13 @@ import path from 'path'; //eslint-disable-next-line node/no-extraneous-import import rimraf from 'rimraf'; import { runPrettier } from '../src/run-prettier'; +import { utils } from 'webpack-cli'; +const { logger } = utils; const outputPath = path.join(__dirname, 'test-assets'); const outputFile = path.join(outputPath, 'test.js'); -const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(); + +const consoleSpy = jest.spyOn(logger, 'warn').mockImplementation(); describe('runPrettier', () => { beforeEach(() => { diff --git a/packages/webpack-cli/__tests__/info.test.js b/packages/webpack-cli/__tests__/info.test.js index a09309e7311..44a6f1fc2d2 100644 --- a/packages/webpack-cli/__tests__/info.test.js +++ b/packages/webpack-cli/__tests__/info.test.js @@ -3,18 +3,17 @@ const path = require('path'); describe('Info', () => { it('should run with cli', () => { - const { stdout, stderr } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['info'], { + const { stdout } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['info'], { cwd: path.resolve(__dirname), reject: false, }); expect(stdout).toContain('System'); expect(stdout).toContain('Binaries'); expect(stdout).toContain('OS'); - expect(stderr).toBeFalsy(); }); it('should work with flags', () => { - const { stdout, stderr } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['info', '--output=json'], { + const { stdout } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['info', '--output=json'], { cwd: path.resolve(__dirname), reject: false, }); @@ -25,6 +24,5 @@ describe('Info', () => { expect(output['System']['OS']).toBeTruthy(); }; expect(testJSON).not.toThrow(); - expect(stderr).toBeFalsy(); }); }); diff --git a/packages/webpack-cli/__tests__/init.test.js b/packages/webpack-cli/__tests__/init.test.js index 26db5236f37..a43381eff41 100644 --- a/packages/webpack-cli/__tests__/init.test.js +++ b/packages/webpack-cli/__tests__/init.test.js @@ -18,12 +18,11 @@ describe('init', () => { }); it('should work with cli', () => { - const { stdout, stderr } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['init'], { + const { stdout } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['init'], { cwd: genPath, reject: false, }); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); + expect(stdout).toContain(firstPrompt); }); it('should run with cli when auto is supplied', () => { @@ -32,7 +31,7 @@ describe('init', () => { reject: false, }); // Test no prompts are present - expect(stdout).toBeTruthy(); + expect(stdout).not.toContain(firstPrompt); // Skip test in case installation fails diff --git a/packages/webpack-cli/__tests__/serve/serve.test.js b/packages/webpack-cli/__tests__/serve/serve.test.js index edebe9bd2a5..a5f2541c5ad 100644 --- a/packages/webpack-cli/__tests__/serve/serve.test.js +++ b/packages/webpack-cli/__tests__/serve/serve.test.js @@ -12,16 +12,14 @@ describe('Serve', () => { } it('should run with cli', async () => { - const { stdout, stderr } = await runServe([], __dirname); + const { stdout } = await runServe([], __dirname); expect(stdout).toContain('main.js'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); it('should work with flags', async () => { - const { stdout, stderr } = await runServe(['--hot'], __dirname); + const { stdout } = await runServe(['--hot'], __dirname); expect(stdout).toContain('main.js'); expect(stdout).toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); }); diff --git a/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js b/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js index 764c8e2b070..1e7dcd684d0 100644 --- a/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js +++ b/packages/webpack-cli/lib/plugins/WebpackCLIPlugin.js @@ -1,63 +1,120 @@ const packageExists = require('../utils/package-exists'); const webpack = packageExists('webpack') ? require('webpack') : undefined; -const logger = require('../utils/logger'); - -const PluginName = 'webpack-cli'; +const { getStatsOptions } = require('../utils/stats-options'); +const { PluginName } = require('../utils/name'); class WebpackCLIPlugin { constructor(options) { this.options = options; + + this.isWatch = false; } async apply(compiler) { - const compilers = compiler.compilers || [compiler]; + const { progress } = this.options; + if (progress) { + this.appendProgressPlugin(compiler, progress); + } - for (const compiler of compilers) { - if (this.options.progress) { - const { ProgressPlugin } = compiler.webpack || webpack; + const isWebpack5 = Boolean(compiler.webpack); - let progressPluginExists; + const logger = compiler.getInfrastructureLogger(PluginName); - if (compiler.options.plugins) { - progressPluginExists = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin)); - } + const resolveName = (obj) => (obj.name ? `${obj.name} ` : ''); - if (!progressPluginExists) { - if (typeof this.options.progress === 'string' && this.options.progress !== 'profile') { - logger.error( - `'${this.options.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`, - ); - process.exit(2); - } + const done = (stats) => { + const printStats = (childCompiler, childStats) => { + const name = resolveName(childCompiler); + + const status = childStats.toString({ + all: false, + version: true, + timings: true, + }); + + const normalizedStatus = (() => { + if (isWebpack5) { + return status; + } else { + const [version, time] = status.split('\n').map((line) => { + const value = line.split(':')[1] || ''; + return value.trim(); + }); - const isProfile = this.options.progress === 'profile'; + return `${name ? name + `(${version})` : version} compiled in ${time}`; + } + })(); - new ProgressPlugin({ profile: isProfile }).apply(compiler); + if (childStats.hasErrors()) { + logger.error(normalizedStatus); + } else if (childStats.hasWarnings()) { + logger.warn(normalizedStatus); + } else { + logger.info(normalizedStatus); } - } - } - const compilationName = (compilation) => (compilation.name ? ` ${compilation.name}` : ''); + const statsString = childStats.toString(getStatsOptions(childCompiler)); + process.stdout.write(statsString + '\n'); - compiler.hooks.watchRun.tap(PluginName, (compilation) => { - const { bail, watch } = compilation.options; - if (bail && watch) { - logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.'); + if (this.isWatch) { + logger.info(name + 'watching files for updates...'); + } + }; + + if (compiler.compilers) { + compiler.compilers.forEach((compilerFromMultiCompileMode, index) => { + printStats(compilerFromMultiCompileMode, stats.stats[index]); + }); + } else { + printStats(compiler, stats); } + }; - logger.success(`Compilation${compilationName(compilation)} starting...`); + compiler.hooks.run.tap(PluginName, (compilation) => { + logger.info(resolveName(compilation) + 'compilation starting...'); }); + compiler.hooks.watchRun.tap(PluginName, (compilation) => { + logger.info(resolveName(compilation) + 'compilation starting...'); - compiler.hooks.done.tap(PluginName, (compilation) => { - logger.success(`Compilation${compilationName(compilation)} finished`); - + if (compilation.options.bail) { + logger.warn('you are using "bail" with "watch". "bail" will still exit webpack when the first error is found.'); + } + this.isWatch = true; + }); + compiler.hooks.done.tap(PluginName, (stats) => { process.nextTick(() => { - if (compiler.watchMode) { - logger.success('watching files for updates...'); - } + done(stats); }); }); } + + appendProgressPlugin(compiler, progress) { + const { ProgressPlugin } = compiler.webpack || webpack; + + const logger = compiler.getInfrastructureLogger(PluginName); + + const compilers = compiler.compilers || [compiler]; + + for (const compiler of compilers) { + let progressPluginExists; + + if (compiler.options.plugins) { + progressPluginExists = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin)); + } + + if (!progressPluginExists) { + if (typeof progress === 'string' && progress !== 'profile') { + logger.error(`'${progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`); + + process.exit(2); + } + + const isProfile = progress === 'profile'; + + new ProgressPlugin({ profile: isProfile }).apply(compiler); + } + } + } } module.exports = WebpackCLIPlugin; diff --git a/packages/webpack-cli/lib/utils/name.js b/packages/webpack-cli/lib/utils/name.js new file mode 100644 index 00000000000..ce906bf7db0 --- /dev/null +++ b/packages/webpack-cli/lib/utils/name.js @@ -0,0 +1,5 @@ +const PluginName = 'webpack-cli'; + +module.exports = { + PluginName, +}; diff --git a/packages/webpack-cli/lib/utils/stats-options.js b/packages/webpack-cli/lib/utils/stats-options.js new file mode 100644 index 00000000000..a180a2bbd60 --- /dev/null +++ b/packages/webpack-cli/lib/utils/stats-options.js @@ -0,0 +1,26 @@ +const packageExists = require('./package-exists'); +const webpack = packageExists('webpack') ? require('webpack') : undefined; +const { options: coloretteOptions } = require('colorette'); + +const getStatsOptions = (compiler) => { + let options = compiler.options + ? typeof compiler.options.stats === 'object' + ? Object.assign({}, compiler.options.stats) + : compiler.options.stats + : undefined; + + // TODO remove after drop webpack@4 + if (webpack.Stats && webpack.Stats.presetToOptions) { + if (!options) { + options = {}; + } else if (typeof options === 'boolean' || typeof options === 'string') { + options = webpack.Stats.presetToOptions(options); + } + } + + options.colors = typeof options.colors !== 'undefined' ? options.colors : coloretteOptions.enabled; + + return options; +}; + +module.exports = { getStatsOptions }; diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index d661a7cb865..2ae6c39de57 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -3,7 +3,7 @@ const packageExists = require('./utils/package-exists'); const webpack = packageExists('webpack') ? require('webpack') : undefined; const webpackMerge = require('webpack-merge'); const { writeFileSync } = require('fs'); -const { options: coloretteOptions, yellow } = require('colorette'); +const { yellow } = require('colorette'); const logger = require('./utils/logger'); const { core, groups, coreFlagMap } = require('./utils/cli-flags'); @@ -11,6 +11,7 @@ const argParser = require('./utils/arg-parser'); const assignFlagDefaults = require('./utils/flag-defaults'); const WebpackCLIPlugin = require('./plugins/WebpackCLIPlugin'); const promptInstallation = require('./utils/prompt-installation'); +const { getStatsOptions } = require('./utils/stats-options'); // CLI arg resolvers const handleConfigResolution = require('./groups/resolveConfig'); @@ -327,9 +328,9 @@ class WebpackCLI { let options = this.compilerConfiguration; let outputOptions = this.outputConfiguration; - const isRawOutput = typeof outputOptions.json === 'undefined'; + const isJsonOutput = typeof outputOptions.json !== 'undefined'; - if (isRawOutput) { + if (!isJsonOutput) { const webpackCLIPlugin = new WebpackCLIPlugin({ progress: outputOptions.progress, }); @@ -357,43 +358,28 @@ class WebpackCLI { process.exitCode = 1; } - const getStatsOptions = (stats) => { - // TODO remove after drop webpack@4 - if (webpack.Stats && webpack.Stats.presetToOptions) { - if (!stats) { - stats = {}; - } else if (typeof stats === 'boolean' || typeof stats === 'string') { - stats = webpack.Stats.presetToOptions(stats); - } - } - - stats.colors = typeof stats.colors !== 'undefined' ? stats.colors : coloretteOptions.enabled; - - return stats; - }; - - const getStatsOptionsFromCompiler = (compiler) => getStatsOptions(compiler.options ? compiler.options.stats : undefined); + if (isJsonOutput) { + process.nextTick(() => { + const statsOptions = compiler.compilers + ? { children: compiler.compilers.map(getStatsOptions) } + : getStatsOptions(compiler); - const foundStats = compiler.compilers - ? { children: compiler.compilers.map(getStatsOptionsFromCompiler) } - : getStatsOptionsFromCompiler(compiler); + const json = JSON.stringify(stats.toJson(statsOptions), null, 2); - if (outputOptions.json === true) { - process.stdout.write(JSON.stringify(stats.toJson(foundStats), null, 2) + '\n'); - } else if (typeof outputOptions.json === 'string') { - const JSONStats = JSON.stringify(stats.toJson(foundStats), null, 2); + if (typeof outputOptions.json === 'string') { + try { + writeFileSync(outputOptions.json, json); - try { - writeFileSync(outputOptions.json, JSONStats); + logger.info(`stats are successfully stored as json to ${outputOptions.json}`); + } catch (error) { + logger.error(error); - logger.success(`stats are successfully stored as json to ${outputOptions.json}`); - } catch (error) { - logger.error(error); - - process.exit(2); - } - } else { - logger.raw(`${stats.toString(foundStats)}`); + process.exit(2); + } + } else { + process.stdout.write(json + '\n'); + } + }); } }; diff --git a/test/analyze/analyze-flag.test.js b/test/analyze/analyze-flag.test.js index 54cac5d97a8..f7c9ef790fa 100644 --- a/test/analyze/analyze-flag.test.js +++ b/test/analyze/analyze-flag.test.js @@ -1,5 +1,6 @@ 'use strict'; +const stripAnsi = require('strip-ansi'); const { runAndGetWatchProc } = require('../utils/test-utils'); describe('--analyze flag', () => { @@ -7,10 +8,11 @@ describe('--analyze flag', () => { const proc = runAndGetWatchProc(__dirname, ['--analyze'], false, '', true); proc.stdout.on('data', (chunk) => { - const data = chunk.toString(); + const data = stripAnsi(chunk.toString()); + const str = 'Webpack Bundle Analyzer is started at'; - if (data.includes('Webpack Bundle Analyzer is started at')) { - expect(data).toContain('Webpack Bundle Analyzer is started at'); + if (data.includes(str)) { + expect(data).toContain(str); proc.kill(); done(); diff --git a/test/bail/bail.test.js b/test/bail/bail.test.js index c848403eb09..7c83391b9b2 100644 --- a/test/bail/bail.test.js +++ b/test/bail/bail.test.js @@ -2,62 +2,56 @@ const { run, runWatch } = require('../utils/test-utils'); +const str = `you are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`; + describe('bail and watch warning', () => { it('should not log warning in not watch mode', async () => { - const { stderr, stdout, exitCode } = await run(__dirname, ['-c', 'bail-webpack.config.js']); + const { stderr, exitCode } = await run(__dirname, ['-c', 'bail-webpack.config.js']); expect(exitCode).toEqual(0); - expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).not.toContain(str); }); it('should not log warning in not watch mode without the "bail" option', async () => { - const { stderr, stdout, exitCode } = await run(__dirname, ['-c', 'no-bail-webpack.config.js']); + const { stderr, exitCode } = await run(__dirname, ['-c', 'no-bail-webpack.config.js']); expect(exitCode).toEqual(0); - expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).not.toContain(str); }); it('should not log warning in not watch mode without the "watch" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'watch-webpack.config.js']); + const { stderr } = await runWatch(__dirname, ['-c', 'watch-webpack.config.js']); - expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).not.toContain(str); }); it('should not log warning without the "bail" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); + const { stderr } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); - expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).not.toContain(str); }); it('should not log warning without the "bail" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); + const { stderr } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); - expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).not.toContain(str); }); it('should log warning in watch mode', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-webpack.config.js', '--watch']); + const { stderr } = await runWatch(__dirname, ['-c', 'bail-webpack.config.js', '--watch']); - expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).toContain(str); }); it('should log warning in watch mode', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-and-watch-webpack.config.js']); + const { stderr } = await runWatch(__dirname, ['-c', 'bail-and-watch-webpack.config.js']); - expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).toContain(str); }); it('should log warning in case of multiple compilers', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'multi-webpack.config.js']); + const { stderr } = await runWatch(__dirname, ['-c', 'multi-webpack.config.js']); - expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); - expect(stdout).toBeTruthy(); + expect(stderr).toContain(str); }); }); diff --git a/test/colors/colors.test.js b/test/colors/colors.test.js index 4bc9e30fbfb..7a7a01e763a 100644 --- a/test/colors/colors.test.js +++ b/test/colors/colors.test.js @@ -5,86 +5,73 @@ const { options: coloretteOptions } = require('colorette'); describe('colorts', () => { it('should output by default', () => { - const { stderr, stdout, exitCode } = run(__dirname); + const { stdout, exitCode } = run(__dirname); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from flags', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose']); + const { stdout, exitCode } = run(__dirname, ['--stats=verbose']); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from flags and from configuration', () => { - const { stderr, stdout, exitCode } = run(__dirname, [ - '--stats=verbose', - `--config=${resolve(__dirname, './no-stats.webpack.config.js')}`, - ]); + const { stdout, exitCode } = run(__dirname, ['--stats=verbose', `--config=${resolve(__dirname, './no-stats.webpack.config.js')}`]); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from flags and from configuration #2', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--config=stats-string.webpack.config.js']); + const { stdout, exitCode } = run(__dirname, ['--stats=verbose', '--config=stats-string.webpack.config.js']); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from the configuration', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=stats-string.webpack.config.js']); + const { stdout, exitCode } = run(__dirname, ['--config=stats-string.webpack.config.js']); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from the configuration #1', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=stats-boolean.webpack.config.js']); + const { stdout, exitCode } = run(__dirname, ['--config=stats-boolean.webpack.config.js']); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from the configuration #2', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=no-stats.webpack.config.js']); + const { stdout, exitCode } = run(__dirname, ['--config=no-stats.webpack.config.js']); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from the configuration #3', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-true.webpack.config.js']); + const { stdout, exitCode } = run(__dirname, ['--config=colors-true.webpack.config.js']); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output); expect(exitCode).toBe(0); }); it('should work with the "stats" option from the configuration #4', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-false.webpack.config.js']); + const { stdout, exitCode } = run(__dirname, ['--config=colors-false.webpack.config.js']); - expect(stderr).toBeFalsy(); const output = isWebpack5 ? 'successfully' : 'main.js'; - console.log(stdout); expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(stdout).toContain(output); expect(exitCode).toBe(0); diff --git a/test/config-format/coffee/coffee.test.js b/test/config-format/coffee/coffee.test.js index ccb8b46cd16..e3d7541ad3c 100644 --- a/test/config-format/coffee/coffee.test.js +++ b/test/config-format/coffee/coffee.test.js @@ -5,19 +5,15 @@ const { resolve } = require('path'); describe('webpack cli', () => { it('should support coffeescript file as flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', 'webpack.config.coffee'], false); + const { exitCode } = run(__dirname, ['-c', 'webpack.config.coffee'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy(); }); it('should load coffeescript file by default', () => { - const { stderr, stdout, exitCode } = run(__dirname, [], false); + const { exitCode } = run(__dirname, [], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy(); }); diff --git a/test/config-format/commonjs/commonjs.test.js b/test/config-format/commonjs/commonjs.test.js index 0a60b8ffd02..d5de5848695 100644 --- a/test/config-format/commonjs/commonjs.test.js +++ b/test/config-format/commonjs/commonjs.test.js @@ -4,10 +4,8 @@ const { resolve } = require('path'); describe('webpack cli', () => { it('should support CommonJS file', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', 'webpack.config.cjs'], false); + const { exitCode } = run(__dirname, ['-c', 'webpack.config.cjs'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy(); }); diff --git a/test/config-format/typescript/typescript.test.js b/test/config-format/typescript/typescript.test.js index e7f7bcfd696..bee1acd5458 100644 --- a/test/config-format/typescript/typescript.test.js +++ b/test/config-format/typescript/typescript.test.js @@ -8,10 +8,8 @@ describe('webpack cli', () => { 'should support typescript file', async () => { await runInstall(__dirname); - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.config.ts']); + const { exitCode } = run(__dirname, ['-c', './webpack.config.ts']); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); stat(resolve(__dirname, 'bin/foo.bundle.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config-lookup/custom-name/custom-name.test.js b/test/config-lookup/custom-name/custom-name.test.js index 66ecfe8a93a..f891da2fbae 100644 --- a/test/config-lookup/custom-name/custom-name.test.js +++ b/test/config-lookup/custom-name/custom-name.test.js @@ -5,9 +5,8 @@ const { run } = require('../../utils/test-utils'); describe('custom config file', () => { it('should work', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'config.webpack.js')], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--config', resolve(__dirname, 'config.webpack.js')], false); + expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy(); }); diff --git a/test/config-lookup/relative/basic-config.test.js b/test/config-lookup/relative/basic-config.test.js index ad568ba330d..33cf9236d90 100644 --- a/test/config-lookup/relative/basic-config.test.js +++ b/test/config-lookup/relative/basic-config.test.js @@ -5,17 +5,15 @@ const { run } = require('../../utils/test-utils'); describe('relative path to config', () => { it('should work', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', 'webpack.config.js', '--output-path', './binary/a'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['-c', 'webpack.config.js', '--output-path', './binary/a'], false); + expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, './binary/a/a.bundle.js'))).toBeTruthy(); }); it('should work #2', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', './webpack.config.js', '--output-path', './binary/b'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['-c', './webpack.config.js', '--output-path', './binary/b'], false); + expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, './binary/b/a.bundle.js'))).toBeTruthy(); }); diff --git a/test/config-name/config-name.test.js b/test/config-name/config-name.test.js index deee81523b7..2854dbf8025 100644 --- a/test/config-name/config-name.test.js +++ b/test/config-name/config-name.test.js @@ -6,11 +6,11 @@ const { resolve } = require('path'); describe('--config-name flag', () => { it('should select only the config whose name is passed with --config-name', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config-name', 'first'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).not.toContain('third'); + const { stderr, exitCode } = run(__dirname, ['--config-name', 'first'], false); + + expect(stderr).toContain('first'); + expect(stderr).not.toContain('second'); + expect(stderr).not.toContain('third'); expect(exitCode).toBe(0); stat(resolve(__dirname, './dist/dist-first.js'), (err, stats) => { @@ -21,11 +21,11 @@ describe('--config-name flag', () => { }); it('should work with multiple values for --config-name', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config-name', 'first', '--config-name', 'third'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).toContain('third'); + const { stderr, exitCode } = run(__dirname, ['--config-name', 'first', '--config-name', 'third'], false); + + expect(stderr).toContain('first'); + expect(stderr).not.toContain('second'); + expect(stderr).toContain('third'); expect(exitCode).toBe(0); stat(resolve(__dirname, './dist/dist-third.js'), (err, stats) => { @@ -83,11 +83,11 @@ describe('--config-name flag', () => { }); it('should work with config as a function', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config', 'function-config.js', '--config-name', 'first'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).not.toContain('third'); + const { stderr, exitCode } = run(__dirname, ['--config', 'function-config.js', '--config-name', 'first'], false); + + expect(stderr).toContain('first'); + expect(stderr).not.toContain('second'); + expect(stderr).not.toContain('third'); expect(exitCode).toBe(0); stat(resolve(__dirname, './dist/dist-first.js'), (err, stats) => { @@ -98,15 +98,15 @@ describe('--config-name flag', () => { }); it('should work with multiple values for --config-name when the config is a function', (done) => { - const { stderr, stdout, exitCode } = run( + const { stderr, exitCode } = run( __dirname, ['--config', 'function-config.js', '--config-name', 'first', '--config-name', 'third'], false, ); - expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).toContain('third'); + + expect(stderr).toContain('first'); + expect(stderr).not.toContain('second'); + expect(stderr).toContain('third'); expect(exitCode).toBe(0); stat(resolve(__dirname, './dist/dist-third.js'), (err, stats) => { diff --git a/test/config/basic/basic-config.test.js b/test/config/basic/basic-config.test.js index 6372c65afa9..35f053b561a 100644 --- a/test/config/basic/basic-config.test.js +++ b/test/config/basic/basic-config.test.js @@ -5,13 +5,8 @@ const { run } = require('../../utils/test-utils'); describe('basic config file', () => { it('is able to understand and parse a very basic configuration file', () => { - const { stdout, stderr, exitCode } = run( - __dirname, - ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], - false, - ); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false); + expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy(); }); diff --git a/test/config/defaults/all/multiple-config.test.js b/test/config/defaults/all/multiple-config.test.js index 9b4d00e975b..79b9cf3a466 100644 --- a/test/config/defaults/all/multiple-config.test.js +++ b/test/config/defaults/all/multiple-config.test.js @@ -5,8 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('Default configuration files: ', () => { it('Uses prod config from dot folder if present', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, [], false); + expect(exitCode).toBe(0); expect(stdout).not.toBe(undefined); stat(resolve(__dirname, './binary/prod.bundle.js'), (err, stats) => { diff --git a/test/config/defaults/basic-config/default-js-config.test.js b/test/config/defaults/basic-config/default-js-config.test.js index c01f5b54b52..2641bba6532 100644 --- a/test/config/defaults/basic-config/default-js-config.test.js +++ b/test/config/defaults/basic-config/default-js-config.test.js @@ -4,7 +4,7 @@ const { run, isWebpack5 } = require('../../../utils/test-utils'); describe('Zero Config', () => { it('runs when config is present but not supplied via flag', () => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + const { stdout, exitCode } = run(__dirname, [], false); // default entry should be used expect(stdout).toContain('./src/index.js'); // should pick up the output path from config @@ -19,6 +19,5 @@ describe('Zero Config', () => { expect(exitCode).toEqual(0); // check that the output file exists expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); }); }); diff --git a/test/config/defaults/cjs-config/default-cjs-config.test.js b/test/config/defaults/cjs-config/default-cjs-config.test.js index 81e4077347c..66332c49d52 100644 --- a/test/config/defaults/cjs-config/default-cjs-config.test.js +++ b/test/config/defaults/cjs-config/default-cjs-config.test.js @@ -4,7 +4,7 @@ const { run, isWebpack5 } = require('../../../utils/test-utils'); describe('Default Config:', () => { it('Should be able to pick cjs config by default', () => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + const { stdout, exitCode } = run(__dirname, [], false); // default entry should be used expect(stdout).toContain('./src/index.js'); // should pick up the output path from config @@ -19,6 +19,5 @@ describe('Default Config:', () => { expect(exitCode).toEqual(0); // check that the output file exists expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); }); }); diff --git a/test/config/defaults/multiple-location/multiple-location-config.test.js b/test/config/defaults/multiple-location/multiple-location-config.test.js index a366a0165a9..3f834976bd5 100644 --- a/test/config/defaults/multiple-location/multiple-location-config.test.js +++ b/test/config/defaults/multiple-location/multiple-location-config.test.js @@ -5,8 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('multiple dev config files with webpack.config.js', () => { it('Uses webpack.config.development.js', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, [], false); + expect(exitCode).toEqual(0); expect(stdout).not.toBe(undefined); stat(resolve(__dirname, './binary/dev.folder.js'), (err, stats) => { diff --git a/test/config/defaults/none and dev/dev-none-config.test.js b/test/config/defaults/none and dev/dev-none-config.test.js index 6c2a8778bbd..90aef4241f1 100644 --- a/test/config/defaults/none and dev/dev-none-config.test.js +++ b/test/config/defaults/none and dev/dev-none-config.test.js @@ -5,8 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('multiple config files', () => { it('Uses dev config when both dev and none are present', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, [], false); + expect(exitCode).toEqual(0); expect(stdout).not.toBe(undefined); stat(resolve(__dirname, './binary/dev.bundle.js'), (err, stats) => { diff --git a/test/config/defaults/with-mode/multiple-config.test.js b/test/config/defaults/with-mode/multiple-config.test.js index 75c1ce693a7..13e44870015 100644 --- a/test/config/defaults/with-mode/multiple-config.test.js +++ b/test/config/defaults/with-mode/multiple-config.test.js @@ -5,8 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('multiple config files', () => { it('Uses dev config when development mode is supplied', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['--mode', 'development'], false); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, ['--mode', 'development'], false); + expect(exitCode).toEqual(0); expect(stdout).not.toBe(undefined); stat(resolve(__dirname, './binary/dev.bundle.js'), (err, stats) => { diff --git a/test/config/empty-array/empty-array.test.js b/test/config/empty-array/empty-array.test.js index 0c34474487d..c464d405d8f 100644 --- a/test/config/empty-array/empty-array.test.js +++ b/test/config/empty-array/empty-array.test.js @@ -4,9 +4,8 @@ const { run } = require('../../utils/test-utils'); describe('config flag with empty config file', () => { it('should throw error with no configuration or index file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); }); }); diff --git a/test/config/empty-function/empty-function.test.js b/test/config/empty-function/empty-function.test.js index 0c34474487d..c464d405d8f 100644 --- a/test/config/empty-function/empty-function.test.js +++ b/test/config/empty-function/empty-function.test.js @@ -4,9 +4,8 @@ const { run } = require('../../utils/test-utils'); describe('config flag with empty config file', () => { it('should throw error with no configuration or index file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); }); }); diff --git a/test/config/empty-promise/empty-promise.test.js b/test/config/empty-promise/empty-promise.test.js index 0c34474487d..c464d405d8f 100644 --- a/test/config/empty-promise/empty-promise.test.js +++ b/test/config/empty-promise/empty-promise.test.js @@ -4,9 +4,8 @@ const { run } = require('../../utils/test-utils'); describe('config flag with empty config file', () => { it('should throw error with no configuration or index file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); }); }); diff --git a/test/config/empty/empty.test.js b/test/config/empty/empty.test.js index 0c34474487d..c464d405d8f 100644 --- a/test/config/empty/empty.test.js +++ b/test/config/empty/empty.test.js @@ -4,9 +4,8 @@ const { run } = require('../../utils/test-utils'); describe('config flag with empty config file', () => { it('should throw error with no configuration or index file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); }); }); diff --git a/test/config/function/functional-config.test.js b/test/config/function/functional-config.test.js index ccc79d6aec1..fed3dd5d621 100644 --- a/test/config/function/functional-config.test.js +++ b/test/config/function/functional-config.test.js @@ -5,9 +5,8 @@ const { run } = require('../../utils/test-utils'); describe('functional config', () => { it('should work as expected in case of single config', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'single-webpack.config.js')]); + const { stdout, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'single-webpack.config.js')]); - expect(stderr).toBeFalsy(); expect(stdout).toContain('./src/index.js'); expect(exitCode).toBe(0); @@ -19,11 +18,10 @@ describe('functional config', () => { }); it('should work as expected in case of multiple config', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'multi-webpack.config.js')]); + const { stderr, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'multi-webpack.config.js')]); - expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).toContain('second'); + expect(stderr).toContain('first'); + expect(stderr).toContain('second'); expect(exitCode).toBe(0); stat(resolve(__dirname, './bin/dist-first.js'), (err, stats) => { diff --git a/test/config/multiple/multiple-config.test.js b/test/config/multiple/multiple-config.test.js index f29651bf8ef..a6127999830 100644 --- a/test/config/multiple/multiple-config.test.js +++ b/test/config/multiple/multiple-config.test.js @@ -4,14 +4,12 @@ const { run } = require('../../utils/test-utils'); describe('Multiple config flag: ', () => { it('spawns multiple compilers for multiple configs', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', 'webpack1.config.js', '-c', 'webpack2.config.js'], false); + const { stderr, exitCode } = run(__dirname, ['-c', 'webpack1.config.js', '-c', 'webpack2.config.js'], false); // Should contain the correct exit code expect(exitCode).toEqual(0); // Should spawn multiple compilers - expect(stdout).toContain('amd:'); - expect(stdout).toContain('commonjs:'); - - expect(stderr).toBeFalsy(); + expect(stderr).toContain('amd'); + expect(stderr).toContain('commonjs'); // should generate the correct output files expect(existsSync(resolve(__dirname, './dist/dist-commonjs.js'))).toBeTruthy(); diff --git a/test/config/type/array-function-with-argv/function-with-argv.test.js b/test/config/type/array-function-with-argv/function-with-argv.test.js index 1685a9a110c..3af62e72023 100644 --- a/test/config/type/array-function-with-argv/function-with-argv.test.js +++ b/test/config/type/array-function-with-argv/function-with-argv.test.js @@ -5,9 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('array of function with args', () => { it('is able to understand a configuration file as a function', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'development'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--mode', 'development'], false); + expect(exitCode).toBe(0); expect(existsSync(resolve(__dirname, './dist/a-dev.js'))).toBeTruthy(); expect(existsSync(resolve(__dirname, './dist/b-dev.js'))).toBeTruthy(); diff --git a/test/config/type/array-function-with-env/array-function-with-env.test.js b/test/config/type/array-function-with-env/array-function-with-env.test.js index c51cef8e060..be9fd42ca97 100644 --- a/test/config/type/array-function-with-env/array-function-with-env.test.js +++ b/test/config/type/array-function-with-env/array-function-with-env.test.js @@ -5,9 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('array of functions with env', () => { it('is able to understand a configuration file as a function', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'development'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--mode', 'development'], false); + expect(exitCode).toBe(0); // Should generate the appropriate files diff --git a/test/config/type/array-functions/array-functions.test.js b/test/config/type/array-functions/array-functions.test.js index 920852f4aa0..267a637d985 100644 --- a/test/config/type/array-functions/array-functions.test.js +++ b/test/config/type/array-functions/array-functions.test.js @@ -5,9 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('array of functions', () => { it('is able to understand a configuration file as a function', (done) => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/a-functor.js'), (err, stats) => { diff --git a/test/config/type/array-promises/array-promises.test.js b/test/config/type/array-promises/array-promises.test.js index b9527b1f2e2..7ac5651683d 100644 --- a/test/config/type/array-promises/array-promises.test.js +++ b/test/config/type/array-promises/array-promises.test.js @@ -5,10 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('array of promises', () => { it('is able to understand a configuration file as a promise', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); + const { exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/a-promise.js'), (err, stats) => { diff --git a/test/config/type/array/array.test.js b/test/config/type/array/array.test.js index 6fa581f100d..8bc59657543 100644 --- a/test/config/type/array/array.test.js +++ b/test/config/type/array/array.test.js @@ -5,11 +5,10 @@ const { run } = require('../../../utils/test-utils'); describe('array', () => { it('is able to understand a configuration file in array format', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); - expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './dist/dist-commonjs.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/config/type/function-array/function-array.test.js b/test/config/type/function-array/function-array.test.js index c7312b734e5..dbbdddb3a12 100644 --- a/test/config/type/function-array/function-array.test.js +++ b/test/config/type/function-array/function-array.test.js @@ -5,9 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('function array', () => { it('is able to understand a configuration file as a function', (done) => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/a-functor.js'), (err, stats) => { diff --git a/test/config/type/function-async/function-async.test.js b/test/config/type/function-async/function-async.test.js index 3b8fa277d98..f55294fbc3d 100644 --- a/test/config/type/function-async/function-async.test.js +++ b/test/config/type/function-async/function-async.test.js @@ -5,9 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('function async', () => { it('is able to understand a configuration file as a function', (done) => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/functor.js'), (err, stats) => { diff --git a/test/config/type/function-promise/function-promise.test.js b/test/config/type/function-promise/function-promise.test.js index ba42b3c57e5..941bea2706d 100644 --- a/test/config/type/function-promise/function-promise.test.js +++ b/test/config/type/function-promise/function-promise.test.js @@ -5,9 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('function promise', () => { it('is able to understand a configuration file as a function', (done) => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/functor.js'), (err, stats) => { diff --git a/test/config/type/function-with-argv/function-with-argv.test.js b/test/config/type/function-with-argv/function-with-argv.test.js index 26d7cb94240..27729ea3f10 100644 --- a/test/config/type/function-with-argv/function-with-argv.test.js +++ b/test/config/type/function-with-argv/function-with-argv.test.js @@ -5,9 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('function configuration', () => { it('is able to understand a configuration file as a function', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'development'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { stdout, exitCode } = run(__dirname, ['--mode', 'development'], false); + expect(exitCode).toBe(0); expect(stdout).toContain("argv: { color: true, mode: 'development' }"); // Should generate the appropriate files diff --git a/test/config/type/function-with-env/function-with-env.test.js b/test/config/type/function-with-env/function-with-env.test.js index 491d85fa9c3..74130fa1302 100644 --- a/test/config/type/function-with-env/function-with-env.test.js +++ b/test/config/type/function-with-env/function-with-env.test.js @@ -12,38 +12,28 @@ describe('function configuration', () => { expect(exitCode).toEqual(1); }); it('is able to understand a configuration file as a function', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--env', 'isProd']); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--env', 'isProd']); + expect(exitCode).toBe(0); // Should generate the appropriate files expect(existsSync(resolve(__dirname, './bin/prod.js'))).toBeTruthy(); }); it('is able to understand a configuration file as a function', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--env', 'isDev']); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--env', 'isDev']); + expect(exitCode).toBe(0); // Should generate the appropriate files expect(existsSync(resolve(__dirname, './bin/dev.js'))).toBeTruthy(); }); it('Supports passing string in env', () => { - const { stderr, stdout, exitCode } = run(__dirname, [ - '--env', - 'environment=production', - '--env', - 'app.title=Luffy', - '-c', - 'webpack.env.config.js', - ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--env', 'environment=production', '--env', 'app.title=Luffy', '-c', 'webpack.env.config.js']); + expect(exitCode).toBe(0); // Should generate the appropriate files expect(existsSync(resolve(__dirname, './bin/Luffy.js'))).toBeTruthy(); }); it('Supports long nested values in env', () => { - const { stderr, stdout, exitCode } = run(__dirname, [ + const { exitCode } = run(__dirname, [ '--env', 'file.name.is.this=Atsumu', '--env', @@ -51,14 +41,13 @@ describe('function configuration', () => { '-c', 'webpack.env.config.js', ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(exitCode).toBe(0); // Should generate the appropriate files expect(existsSync(resolve(__dirname, './bin/Atsumu.js'))).toBeTruthy(); }); it('Supports multiple equal in a string', () => { - const { stderr, stdout, exitCode } = run(__dirname, [ + const { exitCode } = run(__dirname, [ '--env', 'file=name=is=Eren', '--env', @@ -66,39 +55,28 @@ describe('function configuration', () => { '-c', 'webpack.env.config.js', ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(exitCode).toBe(0); // Should generate the appropriate files expect(existsSync(resolve(__dirname, './bin/name=is=Eren.js'))).toBeTruthy(); }); it('Supports dot at the end', () => { - const { stderr, stdout, exitCode } = run(__dirname, [ - '--env', - 'name.=Hisoka', - '--env', - 'environment=dot', - '-c', - 'webpack.env.config.js', - ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--env', 'name.=Hisoka', '--env', 'environment=dot', '-c', 'webpack.env.config.js']); + expect(exitCode).toBe(0); // Should generate the appropriate files expect(existsSync(resolve(__dirname, './bin/Hisoka.js'))).toBeTruthy(); }); it('Supports dot at the end', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--env', 'name.', '--env', 'environment=dot', '-c', 'webpack.env.config.js']); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { exitCode } = run(__dirname, ['--env', 'name.', '--env', 'environment=dot', '-c', 'webpack.env.config.js']); + expect(exitCode).toBe(0); // Should generate the appropriate files expect(existsSync(resolve(__dirname, './bin/true.js'))).toBeTruthy(); }); it('is able to understand multiple env flags', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--env', 'isDev', '--env', 'verboseStats', '--env', 'envMessage']); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + const { stdout, exitCode } = run(__dirname, ['--env', 'isDev', '--env', 'verboseStats', '--env', 'envMessage']); + expect(exitCode).toBe(0); // check that the verbose env is respected expect(stdout).toContain('LOG from webpack'); diff --git a/test/config/type/function/function.test.js b/test/config/type/function/function.test.js index 8c782889fbf..7f2fe83d1ef 100644 --- a/test/config/type/function/function.test.js +++ b/test/config/type/function/function.test.js @@ -5,10 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('function', () => { it('is able to understand a configuration file as a function', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/functor.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config/type/promise-array/promise-array.test.js b/test/config/type/promise-array/promise-array.test.js index e83d7875038..d0966f51d30 100644 --- a/test/config/type/promise-array/promise-array.test.js +++ b/test/config/type/promise-array/promise-array.test.js @@ -5,10 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('promise array', () => { it('is able to understand a configuration file as a promise', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); + const { exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/a-promise.js'), (err, stats) => { diff --git a/test/config/type/promise-function/promise-function.test.js b/test/config/type/promise-function/promise-function.test.js index 2fea09bce8e..99c82405095 100644 --- a/test/config/type/promise-function/promise-function.test.js +++ b/test/config/type/promise-function/promise-function.test.js @@ -5,10 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('promise function', () => { it('is able to understand a configuration file as a promise', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); + const { exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/promise.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config/type/promise/promise.test.js b/test/config/type/promise/promise.test.js index 20a766f279b..b6237177848 100644 --- a/test/config/type/promise/promise.test.js +++ b/test/config/type/promise/promise.test.js @@ -5,10 +5,8 @@ const { run } = require('../../../utils/test-utils'); describe('promise', () => { it('is able to understand a configuration file as a promise', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); + const { exitCode } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); stat(resolve(__dirname, './binary/promise.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/core-flags/amd-flag.test.js b/test/core-flags/amd-flag.test.js index 67c3df8ce37..d4f2f20a122 100644 --- a/test/core-flags/amd-flag.test.js +++ b/test/core-flags/amd-flag.test.js @@ -4,9 +4,8 @@ const { run } = require('../utils/test-utils'); describe('--no-amd flag', () => { it('should accept --no-amd', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-amd']); + const { stdout, exitCode } = run(__dirname, ['--no-amd']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('amd: false'); }); diff --git a/test/core-flags/bail-flag.test.js b/test/core-flags/bail-flag.test.js index 23e953038e3..e5bd7f71a7e 100644 --- a/test/core-flags/bail-flag.test.js +++ b/test/core-flags/bail-flag.test.js @@ -4,17 +4,15 @@ const { run } = require('../utils/test-utils'); describe('--bail flag', () => { it('should set bail to true', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--bail']); + const { stdout, exitCode } = run(__dirname, ['--bail']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('bail: true'); }); it('should set bail to false', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-bail']); + const { stdout, exitCode } = run(__dirname, ['--no-bail']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('bail: false'); }); diff --git a/test/core-flags/cache-flags.test.js b/test/core-flags/cache-flags.test.js index 767c61d924e..85037a10009 100644 --- a/test/core-flags/cache-flags.test.js +++ b/test/core-flags/cache-flags.test.js @@ -14,79 +14,66 @@ describe('cache related flags from core', () => { }); it('should be successful with --cache ', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache']); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, ['--cache']); + expect(exitCode).toBe(0); expect(stdout).toContain(`type: 'memory'`); }); it('should be successful with --no-cache ', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-cache']); + const { stdout, exitCode } = run(__dirname, ['--no-cache']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('cache: false'); }); it('should set cache.type', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem']); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`type: 'filesystem'`); }); it('should set cache.cacheDirectory with --cache-cache-directory', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-directory', './test-cache-path']); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-directory', './test-cache-path']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('test-cache-path'); expect(existsSync(resolve(__dirname, './test-cache-path'))).toBeTruthy(); }); it('should set cache.cacheLocation with --cache-cache-locations', () => { - const { stderr, stdout, exitCode } = run(__dirname, [ - '--cache-type', - 'filesystem', - '--cache-cache-location', - './test-locate-cache', - ]); - - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-location', './test-locate-cache']); + expect(exitCode).toBe(0); expect(stdout).toContain('test-locate-cache'); expect(existsSync(resolve(__dirname, './test-locate-cache'))).toBeTruthy(); }); it('should set cache.hashAlgorithm with --cache-hash-algorithm', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-hash-algorithm', 'sha256']); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-hash-algorithm', 'sha256']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`hashAlgorithm: 'sha256'`); }); it('should set cache.name with --cache-name', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-name', 'cli-test']); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-name', 'cli-test']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`name: 'cli-test'`); }); it('should set cache.store with --cache-store', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-store', 'pack']); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-store', 'pack']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`store: 'pack'`); }); it('should set cache.version with --cache-version', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-version', '1.1.3']); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '--cache-version', '1.1.3']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`version: '1.1.3'`); }); @@ -94,9 +81,8 @@ describe('cache related flags from core', () => { it('should assign cache build dependencies correctly when cache type is filesystem', () => { // TODO: Fix on windows if (isWindows) return; - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.config.js']); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.config.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('buildDependencies'); expect(stdout).toContain("config: [ './webpack.config.js' ]"); @@ -104,16 +90,14 @@ describe('cache related flags from core', () => { // Run again to check for cache const newRun = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.config.js']); expect(newRun.stdout).toContain('[cached]'); - expect(newRun.stderr).toBeFalsy(); expect(newRun.exitCode).toEqual(0); }); it('should assign cache build dependencies correctly when cache type is filesystem in config', () => { // TODO: Fix on windows if (isWindows) return; - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js']); + const { stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('buildDependencies'); expect(stdout).toContain("config: [ './webpack.cache.config.js' ]"); @@ -121,15 +105,14 @@ describe('cache related flags from core', () => { // Run again to check for cache const newRun = run(__dirname, ['-c', './webpack.cache.config.js']); expect(newRun.stdout).toContain('[cached]'); - expect(newRun.stderr).toBeFalsy(); expect(newRun.exitCode).toEqual(0); }); it('should assign cache build dependencies with multiple configs', () => { // TODO: Fix on windows if (isWindows) return; - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js']); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js']); + expect(stdout).toContain('buildDependencies'); expect(stdout).toContain("config: [ './webpack.cache.config.js', './webpack.config.js' ]"); expect(stdout).toContain("type: 'filesystem'"); @@ -139,8 +122,8 @@ describe('cache related flags from core', () => { it('should assign cache build dependencies with default config', () => { // TODO: Fix on windows if (isWindows) return; - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem']); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem']); + expect(stdout).toContain('buildDependencies'); expect(stdout).toContain(`'${path.join(__dirname, './webpack.config.js')}'`); expect(stdout).toContain("type: 'filesystem'"); @@ -150,8 +133,8 @@ describe('cache related flags from core', () => { it('should assign cache build dependencies with merged configs', () => { // TODO: Fix on windows if (isWindows) return; - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js', '--merge']); - expect(stderr).toBeFalsy(); + const { stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js', '--merge']); + expect(stdout).toContain('buildDependencies'); expect(stdout).toContain("config: [ './webpack.cache.config.js', './webpack.config.js' ]"); expect(stdout).toContain("type: 'filesystem'"); @@ -163,8 +146,8 @@ describe('cache related flags from core', () => { if (isWindows) return; // Creating a temporary webpack config writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "development"}'); - const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); - expect(stderr).toBeFalsy(); + const { stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); + expect(stdout).not.toContain('[cached]'); // Running again should use the cache diff --git a/test/core-flags/context-flag.test.js b/test/core-flags/context-flag.test.js index f725b129d00..6b2e0ce09f9 100644 --- a/test/core-flags/context-flag.test.js +++ b/test/core-flags/context-flag.test.js @@ -5,9 +5,8 @@ const { run, isWindows } = require('../utils/test-utils'); describe('--context flag', () => { it('should allow to set context', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--context', './']); + const { stdout, exitCode } = run(__dirname, ['--context', './']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (isWindows) { const windowsPath = resolve(__dirname, './').replace(/\\/g, '\\\\'); @@ -18,9 +17,8 @@ describe('--context flag', () => { }); it('should throw module not found error for invalid context', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--context', '/invalid-context-path']); + const { stdout, exitCode } = run(__dirname, ['--context', '/invalid-context-path']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(1); expect(stdout).toContain(`Module not found: Error: Can't resolve './src/main.js'`); }); diff --git a/test/core-flags/dependencies-flag.test.js b/test/core-flags/dependencies-flag.test.js index 5b3ba3244fe..a57fb4c60d6 100644 --- a/test/core-flags/dependencies-flag.test.js +++ b/test/core-flags/dependencies-flag.test.js @@ -4,17 +4,15 @@ const { run } = require('../utils/test-utils'); describe('--dependencies and related flags', () => { it('should allow to set dependencies option', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--dependencies', 'lodash']); + const { stdout, exitCode } = run(__dirname, ['--dependencies', 'lodash']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`dependencies: [ 'lodash' ]`); }); it('should reset dependencies option', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--dependencies-reset']); + const { stdout, exitCode } = run(__dirname, ['--dependencies-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('dependencies: []'); }); diff --git a/test/core-flags/devtool-flag.test.js b/test/core-flags/devtool-flag.test.js index 387c642bea5..16a41e8e8c8 100644 --- a/test/core-flags/devtool-flag.test.js +++ b/test/core-flags/devtool-flag.test.js @@ -4,9 +4,8 @@ const { run } = require('../utils/test-utils'); describe('--devtool flag', () => { it('should set devtool option', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--devtool', 'source-map']); + const { stdout, exitCode } = run(__dirname, ['--devtool', 'source-map']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`devtool: 'source-map'`); }); diff --git a/test/core-flags/entry-reset-flag.test.js b/test/core-flags/entry-reset-flag.test.js index 07818863adc..2f912616012 100644 --- a/test/core-flags/entry-reset-flag.test.js +++ b/test/core-flags/entry-reset-flag.test.js @@ -4,9 +4,8 @@ const { run } = require('../utils/test-utils'); describe('--entry-reset flag', () => { it('should reset entry correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entry-reset', '--entry', './src/entry.js']); + const { stdout, exitCode } = run(__dirname, ['--entry-reset', '--entry', './src/entry.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('src/entry.js'); expect(stdout).not.toContain('src/main.js'); diff --git a/test/core-flags/experiments-flag.test.js b/test/core-flags/experiments-flag.test.js index f30059f7528..60abb385179 100644 --- a/test/core-flags/experiments-flag.test.js +++ b/test/core-flags/experiments-flag.test.js @@ -12,17 +12,15 @@ describe('experiments option related flag', () => { const propName = hyphenToUpperCase(property); it(`should config ${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: true`); }); it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: false`); }); diff --git a/test/core-flags/externals-flags.test.js b/test/core-flags/externals-flags.test.js index 83dafd5fc76..6a140b65d46 100644 --- a/test/core-flags/externals-flags.test.js +++ b/test/core-flags/externals-flags.test.js @@ -4,33 +4,29 @@ const { run } = require('../utils/test-utils'); describe('externals related flag', () => { it('should set externals properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals', './main.js']); + const { stdout, exitCode } = run(__dirname, ['--externals', './main.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`externals: [ './main.js' ]`); }); it('should set externalsType properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals', 'var']); + const { stdout, exitCode } = run(__dirname, ['--externals', 'var']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`externalsType: 'var'`); }); it('should accept --external-type values', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals-type', 'var']); + const { stdout, exitCode } = run(__dirname, ['--externals-type', 'var']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`externalsType: 'var'`); }); it('should reset externals', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals-reset']); + const { stdout, exitCode } = run(__dirname, ['--externals-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`externals: []`); }); diff --git a/test/core-flags/infrastructure-logging.test.js b/test/core-flags/infrastructure-logging.test.js index 3c2c0e9b3c8..b0fb11c71b3 100644 --- a/test/core-flags/infrastructure-logging.test.js +++ b/test/core-flags/infrastructure-logging.test.js @@ -4,25 +4,22 @@ const { run } = require('../utils/test-utils'); describe('externals related flag', () => { it('should set infrastructureLogging.debug properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--infrastructure-logging-debug', 'myPlugin']); + const { stdout, exitCode } = run(__dirname, ['--infrastructure-logging-debug', 'myPlugin']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`debug: [ 'myPlugin' ]`); }); it('should reset infrastructureLogging.debug to []', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--infrastructure-logging-debug-reset']); + const { stdout, exitCode } = run(__dirname, ['--infrastructure-logging-debug-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`debug: []`); }); it('should set infrastructureLogging.level properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--infrastructure-logging-level', 'log']); + const { stdout, exitCode } = run(__dirname, ['--infrastructure-logging-level', 'log']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`level: 'log'`); }); diff --git a/test/core-flags/module-flags.test.js b/test/core-flags/module-flags.test.js index d65e712d765..af46c394e74 100644 --- a/test/core-flags/module-flags.test.js +++ b/test/core-flags/module-flags.test.js @@ -16,9 +16,8 @@ describe('module config related flag', () => { if (flag.type === Boolean && !flag.name.includes('module-no-parse')) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name.includes('-reset')) { const option = propName.split('Reset')[0]; @@ -32,10 +31,10 @@ describe('module config related flag', () => { if (!flag.name.endsWith('-reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (flag.name.includes('rules-')) { expect(stdout).toContain('sideEffects: false'); } else { @@ -47,19 +46,17 @@ describe('module config related flag', () => { if (flag.type === String) { it(`should config --${flag.name} correctly`, () => { - let { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'value']); + let { stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'value']); if (flag.name === 'module-no-parse') { - expect(stderr).toBeFalsy(); expect(stdout).toContain('value'); } else if (flag.name.includes('reg-exp')) { - ({ stdout, stderr, exitCode } = run(__dirname, [`--${flag.name}`, '/ab?c*/'])); + ({ stdout, exitCode } = run(__dirname, [`--${flag.name}`, '/ab?c*/'])); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: /ab?c*/`); } else if (flag.name.includes('module-rules-')) { - ({ stdout, stderr, exitCode } = run(__dirname, [`--${flag.name}`, 'javascript/auto'])); + ({ stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'javascript/auto'])); if (propName === 'use' || propName === 'type') { expect(stdout).toContain(`${propName}: 'javascript/auto'`); diff --git a/test/core-flags/node-flags.test.js b/test/core-flags/node-flags.test.js index 7b6f9cc1005..022957e8161 100644 --- a/test/core-flags/node-flags.test.js +++ b/test/core-flags/node-flags.test.js @@ -4,41 +4,36 @@ const { run } = require('../utils/test-utils'); describe('node option related flags', () => { it('should config node option', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--node']); + const { stdout, exitCode } = run(__dirname, ['--node']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`node: { global: true, __filename: 'mock', __dirname: 'mock' }`); }); it('should config node option to false', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-node']); + const { stdout, exitCode } = run(__dirname, ['--no-node']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('node: false'); }); it('should set node.global equals to true', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--node']); + const { stdout, exitCode } = run(__dirname, ['--node']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('global: true'); }); it('should set node.filename correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--node-filename', 'mock']); + const { stdout, exitCode } = run(__dirname, ['--node-filename', 'mock']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`__filename: 'mock'`); }); it('should set node.filename correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--node-dirname', 'mock']); + const { stdout, exitCode } = run(__dirname, ['--node-dirname', 'mock']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`__dirname: 'mock'`); }); diff --git a/test/core-flags/optimization-flags.test.js b/test/core-flags/optimization-flags.test.js index 4485865f567..61b7a031e27 100644 --- a/test/core-flags/optimization-flags.test.js +++ b/test/core-flags/optimization-flags.test.js @@ -20,9 +20,8 @@ describe('optimization config related flag', () => { if (flag.type === Boolean) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name === 'optimization-split-chunks') { expect(stdout).toContain(`chunks: 'async'`); @@ -36,9 +35,8 @@ describe('optimization config related flag', () => { if (!flag.name.includes('reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name === 'optimization-split-chunks') { expect(stdout).toContain('splitChunks: false'); @@ -53,9 +51,8 @@ describe('optimization config related flag', () => { // need improve the plugin to log for multi-level options i.e, optimization.runtime if (flag.type === String && !flag.name.includes('runtime-') && !flag.name.includes('fallback-')) { it(`should config --${flag.name} correctly`, () => { - let { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'named']); + let { stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'named']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name === 'optimization-split-chunks-chunks') { stdout = run(__dirname, [`--${flag.name}`, 'initial']).stdout; @@ -78,10 +75,10 @@ describe('optimization config related flag', () => { if (flag.type === Number && !flag.name.includes('fallback-')) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (flag.name === 'optimization-split-chunks') { expect(stdout).toContain(`chunks: 'async'`); expect(stdout).toContain(`minChunks: 1`); diff --git a/test/core-flags/output-flags.test.js b/test/core-flags/output-flags.test.js index d1bfc94f392..670d7696d81 100644 --- a/test/core-flags/output-flags.test.js +++ b/test/core-flags/output-flags.test.js @@ -16,7 +16,7 @@ describe('output config related flag', () => { if (flag.type === Boolean && !flag.name.includes('output-library')) { it(`should config --${flag.name} correctly`, () => { - let { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + let { stdout, exitCode } = run(__dirname, [`--${flag.name}`]); if (flag.name === 'output-module') { //'output.module: true' is only allowed when 'experiments.outputModule' is enabled @@ -25,10 +25,9 @@ describe('output config related flag', () => { expect(stdout).toContain('module: true'); } else if (flag.name.includes('-reset')) { const option = propName.split('Reset')[0]; - expect(stderr).toBeFalsy(); + expect(stdout).toContain(`${option}: []`); } else { - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: true`); } @@ -36,9 +35,8 @@ describe('output config related flag', () => { if (!flag.name.endsWith('-reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: false`); }); @@ -47,9 +45,8 @@ describe('output config related flag', () => { if (flag.type === Number) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: 10`); }); @@ -57,12 +54,11 @@ describe('output config related flag', () => { if (flag.type === String && !flag.name.includes('output-library')) { it(`should config --${flag.name} correctly`, () => { - let { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'test']); + let { stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'test']); if (flag.name === 'output-cross-origin-loading') { ({ stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'anonymous'])); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: 'anonymous'`); } else if (flag.name === 'output-chunk-format') { @@ -83,19 +79,16 @@ describe('output config related flag', () => { } else if (flag.name === 'output-enabled-library-type') { ({ stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'amd'])); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: 'amd'`); } else if (flag.name === 'output-hash-function') { - ({ stdout, stderr, exitCode } = run(__dirname, [`--${flag.name}`, 'sha256'])); + ({ stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'sha256'])); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`hashFunction: 'sha256'`); } else if (flag.name === 'output-script-type') { ({ stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'module'])); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: 'module'`); } else if (flag.name === 'output-enabled-library-types') { @@ -111,7 +104,6 @@ describe('output config related flag', () => { stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout; expect(stdout).toContain(`${propName}: 'async-node'`); } else { - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: 'test'`); } @@ -120,7 +112,7 @@ describe('output config related flag', () => { if (flag.name.includes('output-library')) { it(`should config name, type and export correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [ + const { stdout, exitCode } = run(__dirname, [ '--output-library-name', 'myLibrary', '--output-library-type', @@ -132,7 +124,6 @@ describe('output config related flag', () => { '--output-library-umd-named-define', ]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('myLibrary'); expect(stdout).toContain(`type: 'var'`); @@ -142,9 +133,8 @@ describe('output config related flag', () => { }); it('should be succesful with --output-library-reset correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--output-library-reset']); + const { stdout, exitCode } = run(__dirname, ['--output-library-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('name: []'); }); diff --git a/test/core-flags/parallelism-flag.test.js b/test/core-flags/parallelism-flag.test.js index 9c0d1ee7eea..b9c4a104422 100644 --- a/test/core-flags/parallelism-flag.test.js +++ b/test/core-flags/parallelism-flag.test.js @@ -4,9 +4,8 @@ const { run } = require('../utils/test-utils'); describe('--parallelism flag', () => { it('should set parallelism to the value passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--parallelism', '50']); + const { stdout, exitCode } = run(__dirname, ['--parallelism', '50']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('parallelism: 50'); }); diff --git a/test/core-flags/performance-flags.test.js b/test/core-flags/performance-flags.test.js index ea27e0b1d5c..958da705b1c 100644 --- a/test/core-flags/performance-flags.test.js +++ b/test/core-flags/performance-flags.test.js @@ -7,9 +7,8 @@ const performanceFlags = flagsFromCore.filter(({ name }) => name.startsWith('per describe('module config related flag', () => { it(`should config --performance option correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-performance`]); + const { stdout, exitCode } = run(__dirname, [`--no-performance`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('performance: false'); }); @@ -21,9 +20,8 @@ describe('module config related flag', () => { if (flag.type === Number) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: 10`); }); @@ -31,9 +29,8 @@ describe('module config related flag', () => { if (flag.type === String) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'warning']); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'warning']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`${propName}: 'warning'`); }); diff --git a/test/core-flags/profile-flag.test.js b/test/core-flags/profile-flag.test.js index 9be89d464cf..2a4c8e8dd7f 100644 --- a/test/core-flags/profile-flag.test.js +++ b/test/core-flags/profile-flag.test.js @@ -4,17 +4,15 @@ const { run } = require('../utils/test-utils'); describe('--profile flag', () => { it('should set profile to true', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--profile']); + const { stdout, exitCode } = run(__dirname, ['--profile']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('profile: true'); }); it('should set profile to false', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-profile']); + const { stdout, exitCode } = run(__dirname, ['--no-profile']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('profile: false'); }); diff --git a/test/core-flags/records-flag.test.js b/test/core-flags/records-flag.test.js index db9b9308da2..4c537d67639 100644 --- a/test/core-flags/records-flag.test.js +++ b/test/core-flags/records-flag.test.js @@ -4,25 +4,22 @@ const { run } = require('../utils/test-utils'); describe('module config related flag', () => { it('should config records-path correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--records-path', './bin/records.json']); + const { stdout, exitCode } = run(__dirname, ['--records-path', './bin/records.json']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('records.json'); }); it('should config records-input-path correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--records-input-path', './bin/records.json']); + const { stdout, exitCode } = run(__dirname, ['--records-input-path', './bin/records.json']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('records.json'); }); it('should config records-output-path correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--records-output-path', './bin/records.json']); + const { stdout, exitCode } = run(__dirname, ['--records-output-path', './bin/records.json']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('records.json'); }); diff --git a/test/core-flags/resolve-flags.test.js b/test/core-flags/resolve-flags.test.js index abfaa74379f..1cbfe7e216f 100644 --- a/test/core-flags/resolve-flags.test.js +++ b/test/core-flags/resolve-flags.test.js @@ -16,9 +16,8 @@ describe('resolve config related flags', () => { if (flag.type === Boolean && !flag.name.includes('alias-') && !flag.name.includes('fallback-')) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout } = run(__dirname, [`--${flag.name}`]); + const { stdout } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); if (flag.name.includes('reset')) { const option = propName.split('Reset')[0]; expect(stdout).toContain(`${option}: []`); @@ -30,9 +29,8 @@ describe('resolve config related flags', () => { if (flag.type === String && !flag.name.includes('alias-') && !flag.name.includes('fallback-')) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'browser']); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'browser']); - expect(stderr).toBeFalsy(); if (propName === 'restrictions') { expect(stdout).toContain('browser'); } else { @@ -44,7 +42,7 @@ describe('resolve config related flags', () => { if (flag.name.includes('alias-') || flag.name.includes('fallback-')) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [ + const { stdout, exitCode } = run(__dirname, [ `--resolve-alias-alias`, 'alias', '--resolve-alias-name', @@ -67,7 +65,6 @@ describe('resolve config related flags', () => { 'loader-fall-name', ]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`alias: [ { alias: 'alias', name: 'name' } ]`); expect(stdout).toContain(`aliasFields: [ 'aliasField' ]`); @@ -81,7 +78,7 @@ describe('resolve config related flags', () => { if (flag.name.includes('reset')) { it(`should config --${flag.name} alias-reset flags correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [ + const { stdout, exitCode } = run(__dirname, [ '--resolve-alias-reset', '--resolve-fallback-reset', '--resolve-alias-fields-reset', @@ -90,7 +87,6 @@ describe('resolve config related flags', () => { '--resolve-loader-fallback-reset', ]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`alias: []`); expect(stdout).toContain(`aliasFields: []`); diff --git a/test/core-flags/snapshot-flags.test.js b/test/core-flags/snapshot-flags.test.js index bcaa517f900..014f18bd09b 100644 --- a/test/core-flags/snapshot-flags.test.js +++ b/test/core-flags/snapshot-flags.test.js @@ -13,9 +13,8 @@ describe('snapshot config related flags', () => { if (flag.type === Boolean) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name.includes('reset')) { const option = propName.split('Reset')[0]; @@ -30,9 +29,8 @@ describe('snapshot config related flags', () => { if (flag.type === String) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'test-snap-path']); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'test-snap-path']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain('test-snap-path'); }); diff --git a/test/core-flags/stats-flags.test.js b/test/core-flags/stats-flags.test.js index 6deb653fd19..a36586cabb5 100644 --- a/test/core-flags/stats-flags.test.js +++ b/test/core-flags/stats-flags.test.js @@ -13,9 +13,8 @@ describe('stats config related flag', () => { if (flag.type === Boolean) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name.includes('reset')) { const option = propName.split('Reset')[0]; @@ -27,9 +26,8 @@ describe('stats config related flag', () => { if (!flag.name.endsWith('-reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`stats: { ${propName}: false }`); }); @@ -38,9 +36,8 @@ describe('stats config related flag', () => { if (flag.type === Number) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`stats: { ${propName}: 10 }`); }); @@ -50,9 +47,8 @@ describe('stats config related flag', () => { const acceptsSingleValue = ['preset', 'modulesSort', 'logging', 'chunksSort', 'assetsSort']; it(`should config --${flag.name} correctly`, () => { - let { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'log']); + let { stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'log']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name.includes('stats-colors')) { const option = flag.name.split('stats-colors-')[1]; diff --git a/test/core-flags/watch-flags.test.js b/test/core-flags/watch-flags.test.js index 16576aaf013..ecf0a23ed0b 100644 --- a/test/core-flags/watch-flags.test.js +++ b/test/core-flags/watch-flags.test.js @@ -13,9 +13,8 @@ describe('watch config related flag', () => { if (flag.type === Boolean) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); if (flag.name.includes('reset')) { expect(stdout).toContain(`watchOptions: { ignored: [] }`); @@ -26,9 +25,8 @@ describe('watch config related flag', () => { if (!flag.name.endsWith('-reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain(`watchOptions: { ${propName}: false }`); }); @@ -37,17 +35,16 @@ describe('watch config related flag', () => { if (flag.type === Number) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']); + const { stdout } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); expect(stdout).toContain(`watchOptions: { ${propName}: 10 }`); }); } if (flag.type === String) { it(`should config --${flag.name} correctly`, () => { - let { stderr, stdout } = run(__dirname, [`--${flag.name}`, 'ignore.js']); - expect(stderr).toBeFalsy(); + let { stdout } = run(__dirname, [`--${flag.name}`, 'ignore.js']); + if (propName === 'poll') { stdout = run(__dirname, [`--${flag.name}`, '10']).stdout; expect(stdout).toContain(`watchOptions: { ${propName}: 10 }`); diff --git a/test/defaults/output-defaults.test.js b/test/defaults/output-defaults.test.js index 6166d346ab9..b6207d9c622 100644 --- a/test/defaults/output-defaults.test.js +++ b/test/defaults/output-defaults.test.js @@ -5,9 +5,8 @@ const { run } = require('../utils/test-utils'); describe('output flag defaults', () => { it('should create default file for a given directory', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['--entry', './a.js', '--output-path', './binary'], false); + const { stdout, exitCode } = run(__dirname, ['--entry', './a.js', '--output-path', './binary'], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); // Should not print warning about config fallback, as we have production as default expect(stdout).not.toContain('option has not been set, webpack will fallback to'); diff --git a/test/devtool/array/source-map-array.test.js b/test/devtool/array/source-map-array.test.js index c5b72c2b80b..80266839caf 100644 --- a/test/devtool/array/source-map-array.test.js +++ b/test/devtool/array/source-map-array.test.js @@ -5,10 +5,8 @@ const { run } = require('../../utils/test-utils'); describe('source-map object', () => { it('should treat source-map settings right', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, [], false); + const { exitCode } = run(__dirname, [], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); readdir(resolve(__dirname, 'dist'), (err, files) => { expect(err).toBe(null); @@ -17,10 +15,8 @@ describe('source-map object', () => { }); }); it('should override entire array on flag', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--devtool', 'source-map', '--output-path', './binary'], false); + const { exitCode } = run(__dirname, ['--devtool', 'source-map', '--output-path', './binary'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); readdir(resolve(__dirname, 'binary'), (err, files) => { expect(err).toBe(null); diff --git a/test/devtool/object/source-map-object.test.js b/test/devtool/object/source-map-object.test.js index c73ce7b2aa2..8ff00015aa0 100644 --- a/test/devtool/object/source-map-object.test.js +++ b/test/devtool/object/source-map-object.test.js @@ -5,10 +5,8 @@ const { run } = require('../../utils/test-utils'); describe('source-map object', () => { it('should not write a source map for obj config', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.eval.config.js']); + const { exitCode } = run(__dirname, ['-c', './webpack.eval.config.js']); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); readdir(resolve(__dirname, 'bin'), (err, files) => { expect(files.length).toBeGreaterThanOrEqual(1); @@ -18,10 +16,8 @@ describe('source-map object', () => { }); it('should write a sourcemap file', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.source.config.js'], false); + const { exitCode } = run(__dirname, ['-c', './webpack.source.config.js'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); stat(resolve(__dirname, 'dist/dist-amd.js.map'), (err, stats) => { expect(err).toBe(null); diff --git a/test/entry/config-entry/entry-with-command/entry-with-command.test.js b/test/entry/config-entry/entry-with-command/entry-with-command.test.js index e8ae1a2c741..76738c0b139 100644 --- a/test/entry/config-entry/entry-with-command/entry-with-command.test.js +++ b/test/entry/config-entry/entry-with-command/entry-with-command.test.js @@ -5,10 +5,10 @@ const { run } = require('../../../utils/test-utils'); describe('config entry and command entry all exist', () => { it('should use command entry if config command existed', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', '../1.js', './index.js'], false); + const { stdout, exitCode } = run(__dirname, ['-c', '../1.js', './index.js'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain('./index.js'); stat(resolve(__dirname, './binary/main.bundle.js'), (err, stats) => { expect(err).toBeFalsy(); diff --git a/test/entry/config-entry/entry-with-config/entry-with-config.test.js b/test/entry/config-entry/entry-with-config/entry-with-config.test.js index d25ff38a830..27842da20e9 100644 --- a/test/entry/config-entry/entry-with-config/entry-with-config.test.js +++ b/test/entry/config-entry/entry-with-config/entry-with-config.test.js @@ -5,10 +5,10 @@ const { run } = require('../../../utils/test-utils'); describe('default entry and config entry all exist', () => { it('should use config entry if config entry existed', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', '../1.js'], false); + const { stdout, exitCode } = run(__dirname, ['-c', '../1.js'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain('./a.js'); stat(resolve(__dirname, './binary/index.bundle.js'), (err, stats) => { expect(err).toBeFalsy(); diff --git a/test/entry/config-entry/entry-with-index/entry-with-config.test.js b/test/entry/config-entry/entry-with-index/entry-with-config.test.js index d83ee8ab6b5..49dc4d7e1fd 100644 --- a/test/entry/config-entry/entry-with-index/entry-with-config.test.js +++ b/test/entry/config-entry/entry-with-index/entry-with-config.test.js @@ -5,10 +5,10 @@ const { run } = require('../../../utils/test-utils'); describe('default entry and config entry all exist', () => { it('should use config entry if config entry existed', () => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + const { stdout, exitCode } = run(__dirname, [], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + // Should contain the relevant entry expect(stdout).toContain('./src/app.js'); expect(stdout).toContain('./src/print.js'); @@ -22,6 +22,5 @@ describe('default entry and config entry all exist', () => { expect(existsSync(join(__dirname, '/dist/print.bundle.js'))).toBeTruthy(); // index fallback should not be used even when the file is present expect(existsSync(join(__dirname, '/dist/index.bundle.js'))).toBeFalsy(); - expect(stderr).toBeFalsy(); }); }); diff --git a/test/entry/defaults-empty/entry-single-arg.test.js b/test/entry/defaults-empty/entry-single-arg.test.js index b56c6808074..de5c40315d7 100644 --- a/test/entry/defaults-empty/entry-single-arg.test.js +++ b/test/entry/defaults-empty/entry-single-arg.test.js @@ -4,10 +4,9 @@ const { run } = require('../../utils/test-utils'); describe('single entry flag empty project', () => { it('sets default entry, compiles but throw missing module error', () => { - const { stdout, stderr, exitCode } = run(__dirname); + const { stdout, exitCode } = run(__dirname); expect(exitCode).toBe(1); - expect(stderr).toBeFalsy(); expect(stdout).toContain(`not found: Error: Can't resolve`); }); }); diff --git a/test/entry/defaults-index/entry-multi-args.test.js b/test/entry/defaults-index/entry-multi-args.test.js index 9f900848637..1428edd6cec 100644 --- a/test/entry/defaults-index/entry-multi-args.test.js +++ b/test/entry/defaults-index/entry-multi-args.test.js @@ -7,11 +7,11 @@ const { run } = require('../../utils/test-utils'); describe('single entry flag index present', () => { it('finds default index file and compiles successfully', (done) => { - const { stderr, stdout, exitCode } = run(__dirname); + const { stderr, exitCode } = run(__dirname); expect(stderr).not.toContain('Module not found'); expect(exitCode).toBe(0); - expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); @@ -20,8 +20,7 @@ describe('single entry flag index present', () => { }); it('finds default index file, compiles and overrides with flags successfully', (done) => { - const { stderr } = run(__dirname, ['--output-path', 'bin']); - expect(stderr).toBeFalsy(); + run(__dirname, ['--output-path', 'bin']); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/entry/flag-entry/entry-with-flag.test.js b/test/entry/flag-entry/entry-with-flag.test.js index 63798d5281f..b644be31564 100644 --- a/test/entry/flag-entry/entry-with-flag.test.js +++ b/test/entry/flag-entry/entry-with-flag.test.js @@ -6,11 +6,9 @@ const { resolve } = require('path'); describe('entry flag', () => { it('should resolve the path to src/index.cjs', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entry', './src/index.cjs', '-o', './dist/'], false); + const { exitCode } = run(__dirname, ['--entry', './src/index.cjs', '-o', './dist/'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); stat(resolve(__dirname, './dist/main.js'), (err, stats) => { expect(err).toBe(null); @@ -25,11 +23,9 @@ describe('entry flag', () => { }); it('should load ./src/a.js as entry', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entry', './src/a.js']); + const { exitCode } = run(__dirname, ['--entry', './src/a.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { expect(err).toBe(null); @@ -44,7 +40,7 @@ describe('entry flag', () => { }); it('should resolve the path to /src/a.js as ./src/a.js for webpack-5 only', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entry', '/src/a.js']); + const { stdout, exitCode } = run(__dirname, ['--entry', '/src/a.js']); if (!isWebpack5) { expect(exitCode).toBe(1); @@ -52,8 +48,6 @@ describe('entry flag', () => { done(); } else { expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { expect(err).toBe(null); @@ -69,9 +63,8 @@ describe('entry flag', () => { }); it('should throw error for invalid entry file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--entry', './src/test.js']); + const { stdout, exitCode } = run(__dirname, ['--entry', './src/test.js']); expect(stdout).toContain("Module not found: Error: Can't resolve"); expect(exitCode).toEqual(1); - expect(stderr).toBeFalsy(); }); }); diff --git a/test/entry/multiple-entries/multi-entries.test.js b/test/entry/multiple-entries/multi-entries.test.js index c0f1bc24d41..2d61a338087 100644 --- a/test/entry/multiple-entries/multi-entries.test.js +++ b/test/entry/multiple-entries/multi-entries.test.js @@ -6,11 +6,9 @@ const { resolve } = require('path'); describe(' multiple entries', () => { it('should allow multiple entry files', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['./src/a.js', './src/b.js']); + const { exitCode } = run(__dirname, ['./src/a.js', './src/b.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { expect(err).toBe(null); @@ -26,11 +24,9 @@ describe(' multiple entries', () => { }); it('should allow multiple entry flags', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entry', './src/a.js', '--entry', './src/b.js']); + const { exitCode } = run(__dirname, ['--entry', './src/a.js', '--entry', './src/b.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/entry/scss/scss.test.js b/test/entry/scss/scss.test.js index 565fb273c10..2b921835483 100644 --- a/test/entry/scss/scss.test.js +++ b/test/entry/scss/scss.test.js @@ -5,7 +5,7 @@ describe('entry point', () => { it('should support SCSS files', async () => { await runInstall(__dirname); const { stdout } = run(__dirname); - expect(stdout).toBeTruthy(); + expect(stdout).toContain('home.scss'); expect(stdout).toContain('home.js'); }); diff --git a/test/env/array/array-env.test.js b/test/env/array/array-env.test.js index 2b4f7b4ba1c..d47ebb46ccb 100644 --- a/test/env/array/array-env.test.js +++ b/test/env/array/array-env.test.js @@ -11,11 +11,9 @@ const prodFile = path.join(__dirname, './bin/prod.js'); describe('env array', () => { it('is able to set two different environments for an array configuration', () => { - const { stderr, stdout, exitCode } = run(__dirname); + const { exitCode } = run(__dirname); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); const devScript = spawnSync('node', [devFile]); const prodScript = spawnSync('node', [prodFile]); diff --git a/test/env/object/object-env.test.js b/test/env/object/object-env.test.js index b5a3a5878f6..df7b6a6399e 100644 --- a/test/env/object/object-env.test.js +++ b/test/env/object/object-env.test.js @@ -8,11 +8,9 @@ const { run } = require('../../utils/test-utils'); describe('env object', () => { it('is able to set env for an object', () => { - const { stderr, stdout, exitCode } = run(__dirname); + const { exitCode } = run(__dirname); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); const executable = path.join(__dirname, './bin/main.js'); const bundledScript = spawnSync('node', [executable]); diff --git a/test/help/help-commands.test.js b/test/help/help-commands.test.js index a129994fd35..198d17422de 100644 --- a/test/help/help-commands.test.js +++ b/test/help/help-commands.test.js @@ -5,23 +5,21 @@ const helpHeader = 'The build tool for modern web applications'; describe('commands help', () => { it('shows help for subcommands', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['serve', 'help'], false); + const { stdout, exitCode } = run(__dirname, ['serve', 'help'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); expect(stdout).toContain('webpack s | serve'); }); it('shows help information with subcommands as an arg', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['help', 'serve'], false); + const { stdout, exitCode } = run(__dirname, ['help', 'serve'], false); expect(exitCode).toBe(0); expect(stdout).toContain('webpack s | serve'); - expect(stderr).toHaveLength(0); }); it('shows warning for invalid command with --help flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--help', 'myCommand'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['--help', 'myCommand'], false); expect(exitCode).toBe(0); expect(stderr).toContain(`You provided an invalid command 'myCommand'`); @@ -29,7 +27,7 @@ describe('commands help', () => { }); it('shows warning for invalid command with help command', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['help', 'myCommand'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['help', 'myCommand'], false); expect(exitCode).toBe(0); expect(stderr).toContain(`You provided an invalid command 'myCommand'`); @@ -37,11 +35,10 @@ describe('commands help', () => { }); it('gives precedence to earlier command in case of multiple commands', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help', 'init', 'info'], false); + const { stdout, exitCode } = run(__dirname, ['--help', 'init', 'info'], false); expect(exitCode).toBe(0); expect(stdout).not.toContain(helpHeader); expect(stdout).toContain('webpack c | init [scaffold]'); - expect(stderr).toHaveLength(0); }); }); diff --git a/test/help/help-flags.test.js b/test/help/help-flags.test.js index 4257f9a0781..621cdc02370 100644 --- a/test/help/help-flags.test.js +++ b/test/help/help-flags.test.js @@ -5,7 +5,7 @@ const helpHeader = 'The build tool for modern web applications'; describe('commands help', () => { it('log warning for invalid flag with --help flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--help', '--my-flag'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--my-flag'], false); expect(exitCode).toBe(0); expect(stderr).toContain(`You provided an invalid option '--my-flag'`); @@ -13,7 +13,7 @@ describe('commands help', () => { }); it('log warning for invalid flag with help command', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['help', '--my-flag'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['help', '--my-flag'], false); expect(exitCode).toBe(0); expect(stderr).toContain(`You provided an invalid option '--my-flag'`); @@ -24,27 +24,24 @@ describe('commands help', () => { const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--merge'], false); expect(exitCode).toBe(0); - expect(stdout).not.toContain(helpHeader); + expect(stderr).not.toContain(helpHeader); expect(stdout).toContain('webpack -m, --merge'); - expect(stderr).toHaveLength(0); }); it('should show help for --mode', () => { const { stdout, stderr, exitCode } = run(__dirname, ['--mode', '--help'], false); expect(exitCode).toBe(0); - expect(stdout).not.toContain(helpHeader); + expect(stderr).not.toContain(helpHeader); expect(stdout).toContain('webpack --mode '); expect(stdout).toContain('Defines the mode to pass to webpack'); - expect(stderr).toHaveLength(0); }); it('gives precedence to earlier flag in case of multiple flags', () => { const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--entry', '--merge'], false); expect(exitCode).toBe(0); - expect(stdout).not.toContain(helpHeader); + expect(stderr).not.toContain(helpHeader); expect(stdout).toContain('webpack --entry '); - expect(stderr).toHaveLength(0); }); }); diff --git a/test/help/help-multi-args.test.js b/test/help/help-multi-args.test.js index bddba916b41..34944ad129b 100644 --- a/test/help/help-multi-args.test.js +++ b/test/help/help-multi-args.test.js @@ -10,11 +10,10 @@ describe('help cmd with multiple arguments', () => { const { stdout, stderr, exitCode } = run(__dirname, ['--help', `${cmd.name}`], false); expect(exitCode).toBe(0); - expect(stdout).not.toContain(helpHeader); + expect(stderr).not.toContain(helpHeader); expect(stdout).toContain(`${cmd.name}`); expect(stdout).toContain(`${cmd.usage}`); expect(stdout).toContain(`${cmd.description}`); - expect(stderr).toHaveLength(0); }); }); @@ -22,8 +21,7 @@ describe('help cmd with multiple arguments', () => { const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--version'], false); expect(exitCode).toBe(0); - expect(stdout).not.toContain(helpHeader); + expect(stderr).not.toContain(helpHeader); expect(stdout).toContain('webpack -v, --version'); - expect(stderr).toHaveLength(0); }); }); diff --git a/test/help/help-single-arg.test.js b/test/help/help-single-arg.test.js index a92326eefce..532e8178a47 100644 --- a/test/help/help-single-arg.test.js +++ b/test/help/help-single-arg.test.js @@ -12,35 +12,30 @@ describe('single help flag', () => { options.enabled = true; expect(exitCode).toBe(0); - expect(stdout).not.toContain(yellow(usage)); - expect(stdout).not.toContain(yellow(example)); + expect(stderr).not.toContain(yellow(usage)); + expect(stderr).not.toContain(yellow(example)); expect(stdout).toContain(usage); expect(stdout).toContain(example); - expect(stderr).toHaveLength(0); }); it('outputs help info with command syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['help'], false); + const { stdout, exitCode } = run(__dirname, ['help'], false); expect(exitCode).toBe(0); expect(stdout).toContain(helpHeader); - expect(stderr).toHaveLength(0); }); it('outputs help info with dashed syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help'], false); + const { stdout, exitCode } = run(__dirname, ['--help'], false); expect(exitCode).toBe(0); expect(stdout).toContain(helpHeader); - expect(stderr).toHaveLength(0); }); it('creates a readable snapshot', () => { - const { stderr } = run(__dirname, ['--help'], false); + run(__dirname, ['--help'], false); const serializer = require('jest-serializer-ansi'); expect.addSnapshotSerializer(serializer); - - expect(stderr).toHaveLength(0); }); }); diff --git a/test/hot/hot-flag.test.js b/test/hot/hot-flag.test.js index c7b75436954..02efbe5dc54 100644 --- a/test/hot/hot-flag.test.js +++ b/test/hot/hot-flag.test.js @@ -6,10 +6,9 @@ const { yellow } = require('colorette'); describe('--hot flag', () => { it('should be successful when --hot is passed', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--hot']); + const { stdout, exitCode } = run(__dirname, ['--hot']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); expect(stdout).toContain('HotModuleReplacementPlugin'); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { diff --git a/test/info/info-help.test.js b/test/info/info-help.test.js index 7b77f3e0d83..b82b95de4ba 100644 --- a/test/info/info-help.test.js +++ b/test/info/info-help.test.js @@ -11,29 +11,27 @@ const descriptionText = 'Outputs information about your system and dependencies' describe('should print help for info command', () => { it('shows usage information on supplying help flag', () => { - const { stdout, stderr, exitCode } = runInfo(['--help'], __dirname); + const { stdout, exitCode } = runInfo(['--help'], __dirname); expect(exitCode).toBe(0); expect(stdout).toContain(usageText); expect(stdout).toContain(descriptionText); - expect(stderr).toHaveLength(0); }); it('should respect the --no-color flag', () => { - const { stdout, stderr, exitCode } = runInfo(['--help', '--no-color'], __dirname); + const { stdout, exitCode } = runInfo(['--help', '--no-color'], __dirname); options.enabled = true; expect(exitCode).toBe(0); expect(stdout).not.toContain(yellow(usageText)); expect(stdout).toContain(descriptionText); - expect(stderr).toHaveLength(0); }); it('should output all cli flags', () => { - const { stdout, stderr, exitCode } = runInfo(['--help'], __dirname); + const { stdout, exitCode } = runInfo(['--help'], __dirname); infoFlags.forEach((flag) => expect(stdout).toContain(`--${flag.name}`)); - expect(stderr).toHaveLength(0); + expect(exitCode).toBe(0); }); }); diff --git a/test/info/info-output.test.js b/test/info/info-output.test.js index 8742416eae6..8878212caad 100644 --- a/test/info/info-output.test.js +++ b/test/info/info-output.test.js @@ -1,25 +1,20 @@ 'use strict'; -const { red } = require('colorette'); - +const stripAnsi = require('strip-ansi'); const { runInfo } = require('../utils/test-utils'); describe('basic info usage', () => { it('gets info without flags', () => { - const { stdout, stderr } = runInfo([], __dirname); - // stdout should include many details which will be - // unique for each computer + const { stdout } = runInfo([], __dirname); expect(stdout).toContain('System:'); expect(stdout).toContain('Node'); expect(stdout).toContain('npm'); expect(stdout).toContain('Yarn'); - expect(stderr).toHaveLength(0); }); it('gets info as json', () => { - const { stdout, stderr } = runInfo(['--output="json"'], __dirname); + const { stdout } = runInfo(['--output="json"'], __dirname); expect(stdout).toContain('"System":'); - expect(stderr).toHaveLength(0); const parse = () => { const output = JSON.parse(stdout); @@ -33,16 +28,15 @@ describe('basic info usage', () => { }); it('gets info as markdown', () => { - const { stdout, stderr } = runInfo(['--output="markdown"'], __dirname); + const { stdout } = runInfo(['--output="markdown"'], __dirname); expect(stdout).toContain('## System:'); - expect(stderr).toHaveLength(0); }); it('shows a warning if an invalid value is supplied', () => { const { stdout, stderr, exitCode } = runInfo(['--output=unknown'], __dirname); expect(exitCode).toBe(2); - expect(stderr).toContain(`[webpack-cli] ${red(`'unknown' is not a valid value for output`)}`); + expect(stripAnsi(stderr)).toContain("[webpack-cli] 'unknown' is not a valid value for output"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/info/info-unknown.test.js b/test/info/info-unknown.test.js index 2cd8f8c7593..42062108eea 100644 --- a/test/info/info-unknown.test.js +++ b/test/info/info-unknown.test.js @@ -1,12 +1,11 @@ -const { red } = require('colorette'); +const stripAnsi = require('strip-ansi'); const { runInfo } = require('../utils/test-utils'); describe('should handle unknown args', () => { it('shows an appropriate warning on supplying unknown args', () => { - const { stderr, stdout, exitCode } = runInfo(['--unknown'], __dirname); + const { stderr, exitCode } = runInfo(['--unknown'], __dirname); expect(exitCode).toBe(2); - expect(stderr).toContain(`[webpack-cli] ${red('Unknown argument: --unknown')}`); - expect(stdout).toBeFalsy(); + expect(stripAnsi(stderr)).toContain('[webpack-cli] Unknown argument: --unknown'); }); }); diff --git a/test/init/auto/init-auto.test.js b/test/init/auto/init-auto.test.js index 11705a3d38c..0a456f3c0ec 100644 --- a/test/init/auto/init-auto.test.js +++ b/test/init/auto/init-auto.test.js @@ -15,16 +15,15 @@ describe('init auto flag', () => { }); it('should prompt with w/o auto flag', () => { - const { stdout, stderr } = run(genPath, ['init'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); + const { stdout } = run(genPath, ['init'], false); + expect(stdout).toContain(firstPrompt); }); it('should scaffold and not prompt with auto flag', () => { const { stdout } = run(genPath, ['init', '--auto'], false); // Test no prompts are present - expect(stdout).toBeTruthy(); + expect(stdout).not.toContain(firstPrompt); // Skip test in case installation fails diff --git a/test/init/coreFlags/init-flags.test.js b/test/init/coreFlags/init-flags.test.js index d9234cacb4d..3885b0a8c0d 100644 --- a/test/init/coreFlags/init-flags.test.js +++ b/test/init/coreFlags/init-flags.test.js @@ -6,17 +6,14 @@ const firstPrompt = 'Will your application have multiple bundles?'; describe('init with core flags', () => { it('should output help with --help flag', () => { - const { stdout, stderr } = run(__dirname, ['init', '--help'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); + const { stdout } = run(__dirname, ['init', '--help'], false); + expect(stdout).not.toContain(firstPrompt); expect(stdout).toContain('Initialize a new webpack configuration'); }); it('should throw error with invalid scaffolder package', () => { - const { stdout, stderr } = run(__dirname, ['init', 'webpack-rocks'], false); + const { stderr } = run(__dirname, ['init', 'webpack-rocks'], false); - expect(stdout).toBeFalsy(); - expect(stderr).toBeTruthy(); expect(stderr).toContain(`It should be prefixed with 'webpack-scaffold', but have different suffix`); }); }); diff --git a/test/init/force/init-force.test.js b/test/init/force/init-force.test.js index 90060387ea1..3a462208f6c 100644 --- a/test/init/force/init-force.test.js +++ b/test/init/force/init-force.test.js @@ -18,7 +18,6 @@ describe('init force flag', () => { it('should scaffold webpack config', async () => { const { stdout } = await runPromptWithAnswers(genPath, ['init', '--force'], [`N${ENTER}`, ENTER, ENTER, ENTER, ENTER, ENTER]); - expect(stdout).toBeTruthy(); expect(stdout).toContain(firstPrompt); // Skip test in case installation fails diff --git a/test/init/generator/init-inquirer.test.js b/test/init/generator/init-inquirer.test.js index 27af589ee4b..ab6e86b94ae 100644 --- a/test/init/generator/init-inquirer.test.js +++ b/test/init/generator/init-inquirer.test.js @@ -18,7 +18,6 @@ describe('init', () => { it('should scaffold when given answers', async () => { const { stdout } = await runPromptWithAnswers(genPath, ['init'], [`N${ENTER}`, ENTER, ENTER, ENTER, ENTER, ENTER]); - expect(stdout).toBeTruthy(); expect(stdout).toContain(firstPrompt); // Skip test in case installation fails diff --git a/test/init/language/css/init-language-css.test.js b/test/init/language/css/init-language-css.test.js index 7e28f3ff3bf..46bf80f21c9 100644 --- a/test/init/language/css/init-language-css.test.js +++ b/test/init/language/css/init-language-css.test.js @@ -23,7 +23,6 @@ describe('init with SCSS', () => { [`N${ENTER}`, ENTER, ENTER, ENTER, `${DOWN}${DOWN}${ENTER}`, `Y${ENTER}`, `apple${ENTER}`], ); - expect(stdout).toBeTruthy(); expect(stdout).toContain(firstPrompt); // Skip test in case installation fails diff --git a/test/init/language/js/init-language-js.test.js b/test/init/language/js/init-language-js.test.js index 1400f8861a5..4d9df8c737b 100644 --- a/test/init/language/js/init-language-js.test.js +++ b/test/init/language/js/init-language-js.test.js @@ -19,7 +19,6 @@ describe('init with Typescript', () => { it('should use typescript', async () => { const { stdout } = await runPromptWithAnswers(genPath, ['init'], [`N${ENTER}`, ENTER, ENTER, `${DOWN}${DOWN}${ENTER}`, ENTER]); - expect(stdout).toBeTruthy(); expect(stdout).toContain(firstPrompt); // Skip test in case installation fails diff --git a/test/init/multipleEntries/init-multipleEntries.test.js b/test/init/multipleEntries/init-multipleEntries.test.js index f7c1d9abc2b..7b5e57747f4 100644 --- a/test/init/multipleEntries/init-multipleEntries.test.js +++ b/test/init/multipleEntries/init-multipleEntries.test.js @@ -21,8 +21,7 @@ describe('init with multiple entries', () => { ['init'], [`Y${ENTER}`, `a, b${ENTER}`, ENTER, ENTER, ENTER, ENTER, ENTER, ENTER], ); - - expect(stdout).toBeTruthy(); + console.log(stdout); expect(stdout).toContain(firstPrompt); // Skip test in case installation fails diff --git a/test/loader/loader.test.js b/test/loader/loader.test.js index 239e69247d2..de33b6a0d02 100644 --- a/test/loader/loader.test.js +++ b/test/loader/loader.test.js @@ -17,9 +17,8 @@ describe('loader command', () => { }); it('Should ask the loader name when invoked', () => { - const { stdout, stderr } = run(__dirname, ['loader'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); + const { stdout } = run(__dirname, ['loader'], false); + expect(stripAnsi(stdout)).toContain(firstPrompt); }); diff --git a/test/merge/config/merge-config.test.js b/test/merge/config/merge-config.test.js index 926ff5e4bbb..5e31e1b643f 100644 --- a/test/merge/config/merge-config.test.js +++ b/test/merge/config/merge-config.test.js @@ -7,17 +7,17 @@ const { run } = require('../../utils/test-utils'); describe('merge flag configuration', () => { it('merges two configurations together', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--config', './1.js', '-c', './2.js', '--merge'], false); + const { stdout, exitCode } = run(__dirname, ['--config', './1.js', '-c', './2.js', '--merge'], false); expect(stdout).not.toContain('option has not been set, webpack will fallback to'); expect(existsSync(resolve(__dirname, './dist/merged.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); }); it('merges two configurations together with flag alias', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--config', './1.js', '--config', './2.js', '-m'], false); + const { stdout, exitCode } = run(__dirname, ['--config', './1.js', '--config', './2.js', '-m'], false); expect(stdout).toContain('merged.js'); expect(existsSync(resolve(__dirname, './dist/merged.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); }); it('fails when there are less than 2 configurations to merge', () => { diff --git a/test/migrate/config/migrate-config.test.js b/test/migrate/config/migrate-config.test.js index 732906f1f5b..2af07bef2bc 100644 --- a/test/migrate/config/migrate-config.test.js +++ b/test/migrate/config/migrate-config.test.js @@ -42,16 +42,10 @@ describe('migrate command', () => { }); it('should generate an updated config file when an output path is provided', async () => { - const { stdout, stderr } = await runPromptWithAnswers( - __dirname, - ['migrate', 'webpack.config.js', outputFile], - [ENTER, ENTER], - true, - ); + const { stdout } = await runPromptWithAnswers(__dirname, ['migrate', 'webpack.config.js', outputFile], [ENTER, ENTER], true); expect(stripAnsi(stdout)).toContain('? Do you want to validate your configuration?'); // should show the diff of the config file expect(stdout).toContain('rules: ['); - expect(stderr).toBeFalsy(); expect(fs.existsSync(outputFilePath)).toBeTruthy(); // the output file should be a valid config file diff --git a/test/mode/mode-single-arg/mode-single-arg.test.js b/test/mode/mode-single-arg/mode-single-arg.test.js index c3577ac844c..b4099d190fb 100644 --- a/test/mode/mode-single-arg/mode-single-arg.test.js +++ b/test/mode/mode-single-arg/mode-single-arg.test.js @@ -3,41 +3,41 @@ const { run } = require('../../utils/test-utils'); describe('mode flags', () => { it('should set mode=production by default', () => { - const { stderr, stdout, exitCode } = run(__dirname); + const { stdout, exitCode } = run(__dirname); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain(`mode: 'production'`); }); it('should load a development config when --mode=development is passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'development']); + const { stdout, exitCode } = run(__dirname, ['--mode', 'development']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain(`mode: 'development'`); }); it('should load a production config when --mode=production is passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'production']); + const { stdout, exitCode } = run(__dirname, ['--mode', 'production']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain(`mode: 'production'`); }); it('should load a none config when --mode=none is passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'none']); + const { stdout, exitCode } = run(__dirname, ['--mode', 'none']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain(`mode: 'none'`); }); it('should pick mode form NODE_ENV', () => { - const { stderr, stdout, exitCode } = run(__dirname, [], false, [], { NODE_ENV: 'development' }); + const { stdout, exitCode } = run(__dirname, [], false, [], { NODE_ENV: 'development' }); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain(`mode: 'development'`); }); diff --git a/test/mode/mode-with-config/mode-with-config.test.js b/test/mode/mode-with-config/mode-with-config.test.js index 9eee9f6f8d4..bf6e6a45f9c 100644 --- a/test/mode/mode-with-config/mode-with-config.test.js +++ b/test/mode/mode-with-config/mode-with-config.test.js @@ -6,11 +6,9 @@ const { run } = require('../../utils/test-utils'); describe('mode flags with config', () => { it('should run in production mode when --mode=production is passed', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'production', '--config', './webpack.config.js']); + const { exitCode } = run(__dirname, ['--mode', 'production', '--config', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); // Should generate the appropriate files stat(resolve(__dirname, './bin/main.js.OTHER.LICENSE.txt'), (err, stats) => { @@ -37,11 +35,9 @@ describe('mode flags with config', () => { }); it('should run in development mode when --mode=development is passed', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'development', '--config', './webpack.config.js']); + const { exitCode } = run(__dirname, ['--mode', 'development', '--config', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); // Should generate the appropriate files stat(resolve(__dirname, './bin/main.js.OTHER.LICENSE.txt'), (err, stats) => { @@ -68,11 +64,9 @@ describe('mode flags with config', () => { }); it('should run in none mode when --mode=none is passed', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'none', '--config', './webpack.config.js']); + const { exitCode } = run(__dirname, ['--mode', 'none', '--config', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); // Should generate the appropriate files stat(resolve(__dirname, './bin/main.js.OTHER.LICENSE.txt'), (err, stats) => { @@ -99,54 +93,48 @@ describe('mode flags with config', () => { }); it('should use mode flag over config', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--mode', 'production', '-c', 'webpack.config2.js']); + const { stdout, exitCode } = run(__dirname, ['--mode', 'production', '-c', 'webpack.config2.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); expect(stdout).toContain(`mode: 'production'`); }); it('should use mode from flag over NODE_ENV', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--mode', 'none', '-c', 'webpack.config2.js'], false, [], { + const { stdout, exitCode } = run(__dirname, ['--mode', 'none', '-c', 'webpack.config2.js'], false, [], { NODE_ENV: 'production', }); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); expect(stdout).toContain(`mode: 'none'`); }); it('should use mode from config over NODE_ENV', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', 'webpack.config2.js']); + const { stdout, exitCode } = run(__dirname, ['-c', 'webpack.config2.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); expect(stdout).toContain(`mode: 'development'`); }); it('should use mode from config when multiple config are supplied', () => { - const { stdout, stderr } = run(__dirname, ['-c', 'webpack.config3.js', '-c', 'webpack.config2.js']); + const { stdout } = run(__dirname, ['-c', 'webpack.config3.js', '-c', 'webpack.config2.js']); - expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'development'`); expect(stdout.match(new RegExp("mode: 'development'", 'g')).length).toEqual(1); }); it('mode flag should apply to all configs', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--mode', 'none', '-c', './webpack.config3.js', '-c', './webpack.config2.js']); + const { stdout, exitCode } = run(__dirname, ['--mode', 'none', '-c', './webpack.config3.js', '-c', './webpack.config2.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); expect(stdout).toContain(`mode: 'none'`); expect(stdout.match(new RegExp("mode: 'none'", 'g')).length).toEqual(2); }); it('only config where mode is absent pick up from NODE_ENV', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', './webpack.config3.js', '-c', './webpack.config2.js'], false, [], { + const { stdout, exitCode } = run(__dirname, ['-c', './webpack.config3.js', '-c', './webpack.config2.js'], false, [], { NODE_ENV: 'production', }); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); expect(stdout).toContain(`mode: 'production'`); expect(stdout).toContain(`mode: 'development'`); diff --git a/test/name/name.test.js b/test/name/name.test.js index d615a55ee3f..e04ca4f138c 100644 --- a/test/name/name.test.js +++ b/test/name/name.test.js @@ -3,9 +3,8 @@ const { run } = require('../utils/test-utils'); describe('name flag', () => { it('should set the flag in the config', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--name', 'config-name'], false); + const { stdout, exitCode } = run(__dirname, ['--name', 'config-name'], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); expect(stdout).toContain("name: 'config-name'"); }); diff --git a/test/no-hot/no-hot.test.js b/test/no-hot/no-hot.test.js index bd80177cd9a..eaa6e10484a 100644 --- a/test/no-hot/no-hot.test.js +++ b/test/no-hot/no-hot.test.js @@ -6,11 +6,10 @@ const { yellow } = require('colorette'); describe('no-hot flag', () => { it('should be successful when --no-hot is passed', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-hot']); + const { stdout, exitCode } = run(__dirname, ['--no-hot']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(stdout).not.toContain('webpack/runtime/hot module replacement'); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { @@ -27,7 +26,7 @@ describe('no-hot flag', () => { }); it('should warn when --hot and --no-hot both are passed', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--hot', '--no-hot']); + const { stderr, exitCode } = run(__dirname, ['--hot', '--no-hot']); expect(exitCode).toBe(0); expect(stderr).toContain( @@ -35,7 +34,6 @@ describe('no-hot flag', () => { 'You provided both --hot and --no-hot. We will use only the last of these flags that you provided in your CLI arguments', )}`, ); - expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/no-stats/with-config/no-stats-with-config.test.js b/test/no-stats/with-config/no-stats-with-config.test.js index 5b7031253f1..8457bd9769b 100644 --- a/test/no-stats/with-config/no-stats-with-config.test.js +++ b/test/no-stats/with-config/no-stats-with-config.test.js @@ -5,9 +5,8 @@ const { version } = require('webpack'); describe('stats flag', () => { it(`should use stats 'detailed' as defined in webpack config`, () => { - const { stderr, stdout } = run(__dirname, []); + const { stdout } = run(__dirname, []); - expect(stderr).toBeFalsy(); if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'detailed' }`); } else { @@ -16,9 +15,8 @@ describe('stats flag', () => { }); it(`should use --no-stats and override value in config`, () => { - const { stderr, stdout } = run(__dirname, ['--no-stats']); + const { stdout } = run(__dirname, ['--no-stats']); - expect(stderr).toBeFalsy(); if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'none' }`); } else { diff --git a/test/no-stats/with-flags/no-stats.test.js b/test/no-stats/with-flags/no-stats.test.js index 34ae453eb69..732a2ceff64 100644 --- a/test/no-stats/with-flags/no-stats.test.js +++ b/test/no-stats/with-flags/no-stats.test.js @@ -5,9 +5,8 @@ const { version } = require('webpack'); describe('stats flag', () => { it('should accept --no-stats as boolean', () => { - const { stderr, stdout } = run(__dirname, ['--no-stats']); + const { stdout } = run(__dirname, ['--no-stats']); - expect(stderr).toBeFalsy(); if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'none' }`); } else { diff --git a/test/node/node.test.js b/test/node/node.test.js index 077e34044a4..6219a4ad1f4 100644 --- a/test/node/node.test.js +++ b/test/node/node.test.js @@ -8,7 +8,7 @@ const { run } = require('../utils/test-utils'); // throws different error from what we manually see describe('node flags', () => { it('is able to pass the options flags to node js', async (done) => { - const { stdout, stderr, exitCode } = await run(__dirname, ['--output-path', './bin'], false, [ + const { stdout, exitCode } = await run(__dirname, ['--output-path', './bin'], false, [ `--require=${resolve(__dirname, 'bootstrap.js')}`, `--require=${resolve(__dirname, 'bootstrap2.js')}`, ]); @@ -16,7 +16,7 @@ describe('node flags', () => { expect(exitCode).toBe(0); expect(stdout).toContain('---from bootstrap.js---'); expect(stdout).toContain('---from bootstrap2.js---'); - expect(stderr).toBeFalsy(); + stat(resolve(__dirname, './bin/main.bundle.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/optimization/optimization.test.js b/test/optimization/optimization.test.js index 74e97f03e7f..d187d784ffe 100644 --- a/test/optimization/optimization.test.js +++ b/test/optimization/optimization.test.js @@ -15,7 +15,7 @@ describe('optimization option in config', () => { expect(stdout).toContain('mangleExports: false'); // check that the output file exists expect(fs.existsSync(join(__dirname, '/dist/main.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); } }); diff --git a/test/output/named-bundles/output-named-bundles.test.js b/test/output/named-bundles/output-named-bundles.test.js index 0743bb84f67..b45fbcda053 100644 --- a/test/output/named-bundles/output-named-bundles.test.js +++ b/test/output/named-bundles/output-named-bundles.test.js @@ -5,34 +5,27 @@ const { run } = require('../../utils/test-utils'); describe('output flag named bundles', () => { it('should output file given as flag instead of in configuration', () => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); const stats = statSync(resolve(__dirname, './binary/a.bundle.js')); expect(stats.isFile()).toBe(true); }); it('should resolve the path to binary/a.bundle.js as ./binary/a.bundle.js', () => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', 'binary'], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', 'binary'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); const stats = statSync(resolve(__dirname, './binary/a.bundle.js')); expect(stats.isFile()).toBe(true); }); it('should create multiple bundles with an overriding flag', () => { - const { stderr, exitCode } = run( - __dirname, - ['-c', resolve(__dirname, 'webpack.single.config.js'), '--output-path', './bin'], - false, - ); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.single.config.js'), '--output-path', './bin'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); let stats = statSync(resolve(__dirname, './bin/b.bundle.js')); expect(stats.isFile()).toBe(true); @@ -41,10 +34,9 @@ describe('output flag named bundles', () => { }); it('should successfully compile multiple entries', () => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.multiple.config.js')], false); + const { exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.multiple.config.js')], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); let stats = statSync(resolve(__dirname, './bin/b.bundle.js')); expect(stats.isFile()).toBe(true); diff --git a/test/plugin/plugin.test.js b/test/plugin/plugin.test.js index 7d4055adff1..56de05bb1f3 100644 --- a/test/plugin/plugin.test.js +++ b/test/plugin/plugin.test.js @@ -14,9 +14,8 @@ describe('plugin command', () => { }); it('Should ask the plugin name when invoked', () => { - const { stdout, stderr } = run(__dirname, ['plugin'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); + const { stdout } = run(__dirname, ['plugin'], false); + expect(stripAnsi(stdout)).toContain(firstPrompt); }); diff --git a/test/prefetch/prefetch.test.js b/test/prefetch/prefetch.test.js index 2c5eafad51c..af48ce90b48 100644 --- a/test/prefetch/prefetch.test.js +++ b/test/prefetch/prefetch.test.js @@ -9,32 +9,30 @@ describe('Prefetch Flag', () => { }); it('Should load the prefetched file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--prefetch', './src/p.js'], false); + const { stdout, exitCode } = run(__dirname, ['--prefetch', './src/p.js'], false); // Should be able to find the entry file expect(stdout).toContain('./src/index.js'); // Should invoke the PrefetchPlugin with correct params expect(stdout).toContain(`PrefetchPlugin { context: null, request: './src/p.js' }`); // check that the output file exists expect(fs.existsSync(join(__dirname, '/dist/main.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); }); it('Should err when the prefetched file is absent', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--prefetch', './src/somefile.js'], false); + const { stdout, exitCode } = run(__dirname, ['--prefetch', './src/somefile.js'], false); // Should contain the error message expect(stdout).toContain(`Error: Can't resolve './src/somefile.js'`); expect(exitCode).toBe(1); // check that the output file does not exist since prefetched file is not found expect(fs.existsSync(join(__dirname, '/dist/main.js'))).toBeFalsy(); - expect(stderr).toBeFalsy(); }); it('Should err when flag value is not supplied', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--prefetch'], false); + const { stderr, exitCode } = run(__dirname, ['--prefetch'], false); // Should contain the error message expect(stderr).toContain(`error: option '--prefetch ' argument missing`); - expect(stdout).toBeFalsy(); expect(exitCode).toBe(1); }); }); diff --git a/test/progress/progress-flag.test.js b/test/progress/progress-flag.test.js index 7aebd90ab12..b0488451c4c 100644 --- a/test/progress/progress-flag.test.js +++ b/test/progress/progress-flag.test.js @@ -4,7 +4,7 @@ const { run, isWebpack5 } = require('../utils/test-utils'); describe('progress flag', () => { it('should show progress', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--progress']); + const { stdout, stderr, exitCode } = run(__dirname, ['--progress']); expect(exitCode).toBe(0); expect(stderr).not.toMatch(/\[webpack\.Progress] \d+ ms setup/); @@ -13,7 +13,7 @@ describe('progress flag', () => { }); it('should support the "profile" value', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--progress=profile']); + const { stdout, stderr, exitCode } = run(__dirname, ['--progress=profile']); expect(exitCode).toBe(0); if (isWebpack5) { @@ -32,7 +32,7 @@ describe('progress flag', () => { }); it('should not add duplicate plugins', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', 'webpack.progress.config.js', '--progress']); + const { stdout, stderr, exitCode } = run(__dirname, ['-c', 'webpack.progress.config.js', '--progress']); expect(exitCode).toEqual(0); expect(stdout.match(/ProgressPlugin/g)).toHaveLength(1); diff --git a/test/serve/basic/serve-basic.test.js b/test/serve/basic/serve-basic.test.js index 2ad37284524..4b1a8b728f5 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -28,46 +28,40 @@ describe('basic serve usage', () => { } it('should respect the --no-color flag', async () => { - const { stdout, stderr } = await runServe(['--help', '--no-color'], __dirname); + const { stdout } = await runServe(['--help', '--no-color'], __dirname); options.enabled = true; expect(stdout).not.toContain(yellow(usageText)); expect(stdout).toContain(descriptionText); - expect(stderr).toHaveLength(0); }); it('should not invoke info subcommand', async () => { - const { stdout, stderr } = await runServe(['--client-log-level', 'info'], testPath); + const { stdout } = await runServe(['--client-log-level', 'info'], testPath); expect(stdout).toContain('main.js'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); it('compiles without flags', async () => { - const { stdout, stderr } = await runServe(['--port', port], testPath); + const { stdout } = await runServe(['--port', port], testPath); expect(stdout).toContain('main.js'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); it('uses hot flag to alter bundle', async () => { - const { stdout, stderr } = await runServe(['--port', port, '--hot'], testPath); + const { stdout } = await runServe(['--port', port, '--hot'], testPath); expect(stdout).toContain('main.js'); expect(stdout).toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); it('uses hot-only flag to alter bundle', async () => { - const { stdout, stderr } = await runServe(['--port', port, isDevServer4 ? '--hot only' : '--hot-only'], testPath); + const { stdout } = await runServe(['--port', port, isDevServer4 ? '--hot only' : '--hot-only'], testPath); expect(stdout).toContain('main.js'); expect(stdout).toContain('HotModuleReplacementPlugin'); - expect(stderr).toBeFalsy(); }); it('uses no-hot flag', async () => { - const { stdout, stderr } = await runServe(['--port', port, '--no-hot'], testPath); + const { stdout } = await runServe(['--port', port, '--no-hot'], testPath); expect(stdout).toContain('main.js'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); it('uses hot flag and progress flag', async () => { diff --git a/test/serve/serve-variable/serve-basic.test.js b/test/serve/serve-variable/serve-basic.test.js index d8e6bc12c77..45433e6ef3c 100644 --- a/test/serve/serve-variable/serve-basic.test.js +++ b/test/serve/serve-variable/serve-basic.test.js @@ -24,10 +24,10 @@ describe('serve variable', () => { } it('compiles without flags and export variable', async () => { - const { stdout, stderr } = await runServe(['--port', port], testPath); + const { stdout } = await runServe(['--port', port], testPath); expect(stdout).toContain('main.js'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); + expect(stdout).toContain('PASS'); }); }); diff --git a/test/serve/with-custom-port/serve-custom-config.test.js b/test/serve/with-custom-port/serve-custom-config.test.js index e0e0b55e8fb..65915556f24 100644 --- a/test/serve/with-custom-port/serve-custom-config.test.js +++ b/test/serve/with-custom-port/serve-custom-config.test.js @@ -24,44 +24,40 @@ describe('serve with devServer in config', () => { } it('Should pick up the host and port from config', async () => { - const { stdout, stderr } = await runServe([], testPath); + const { stdout } = await runServe([], testPath); // Should output the correct bundle file expect(stdout).toContain('main.js'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); // Runs at correct host and port expect(stdout).toContain('http://0.0.0.0:1234'); - expect(stderr).toBeFalsy(); }); it('Port flag should override the config port', async () => { - const { stdout, stderr } = await runServe(['--port', port], testPath); + const { stdout } = await runServe(['--port', port], testPath); // Should output the correct bundle file expect(stdout).toContain('main.js'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); // Runs at correct host and port expect(stdout).toContain(`http://0.0.0.0:${port}`); - expect(stderr).toBeFalsy(); }); it('Passing hot flag works alongside other server config', async () => { - const { stdout, stderr } = await runServe(['--port', port, '--hot'], testPath); + const { stdout } = await runServe(['--port', port, '--hot'], testPath); // Should output the correct bundle file expect(stdout).toContain('main.js'); // HMR is being used expect(stdout).toContain('HotModuleReplacementPlugin'); // Runs at correct host and port expect(stdout).toContain(`http://0.0.0.0:${port}`); - expect(stderr).toBeFalsy(); }); it('works fine when no-hot flag is passed alongside other server config', async () => { - const { stdout, stderr } = await runServe(['--port', port, '--no-hot'], testPath); + const { stdout } = await runServe(['--port', port, '--no-hot'], testPath); // Should output the correct bundle file expect(stdout).toContain('main.js'); // HMR is not being used expect(stdout).not.toContain('HotModuleReplacementPlugin'); // Runs at correct host and port expect(stdout).toContain(`http://0.0.0.0:${port}`); - expect(stderr).toBeFalsy(); }); }); diff --git a/test/stats/cli-flags/stats.test.js b/test/stats/cli-flags/stats.test.js index ed461160782..f03359402a2 100644 --- a/test/stats/cli-flags/stats.test.js +++ b/test/stats/cli-flags/stats.test.js @@ -12,10 +12,10 @@ if (isWebpack5) { describe('stats flag', () => { for (const preset of presets) { it(`should accept --stats "${preset}"`, () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats', `${preset}`]); + const { stdout, exitCode } = run(__dirname, ['--stats', `${preset}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (isWebpack5) { expect(stdout).toContain(`stats: { preset: '${preset}' }`); } else { @@ -25,10 +25,10 @@ describe('stats flag', () => { } it('should accept stats as boolean', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats']); + const { stdout, exitCode } = run(__dirname, ['--stats']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (isWebpack5) { expect(stdout).toContain(`stats: { preset: 'normal' }`); } else { diff --git a/test/stats/config/stats.test.js b/test/stats/config/stats.test.js index 84c77b6e3ca..bfc8a5a26df 100644 --- a/test/stats/config/stats.test.js +++ b/test/stats/config/stats.test.js @@ -6,10 +6,10 @@ const { version } = require('webpack'); describe('stats flag with config', () => { it('should compile without stats flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, []); + const { stdout, exitCode } = run(__dirname, []); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'normal' }`); } else { @@ -17,10 +17,10 @@ describe('stats flag with config', () => { } }); it('should compile with stats flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats', 'errors-warnings']); + const { stdout, exitCode } = run(__dirname, ['--stats', 'errors-warnings']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'errors-warnings' }`); } else { diff --git a/test/target/flag-test/target-flag.test.js b/test/target/flag-test/target-flag.test.js index 23b01983600..6b0dcabc45f 100644 --- a/test/target/flag-test/target-flag.test.js +++ b/test/target/flag-test/target-flag.test.js @@ -8,10 +8,10 @@ const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', ' describe('--target flag', () => { targetValues.forEach((val) => { it(`should accept ${val} with --target flag`, (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['--target', `${val}`]); + const { stdout, exitCode } = run(__dirname, ['--target', `${val}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (isWebpack5) { expect(stdout).toContain(`target: [ '${val}' ]`); } else { @@ -26,10 +26,10 @@ describe('--target flag', () => { }); it(`should accept ${val} with -t alias`, (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-t', `${val}`]); + const { stdout, exitCode } = run(__dirname, ['-t', `${val}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + if (isWebpack5) { expect(stdout).toContain(`target: [ '${val}' ]`); } else { @@ -57,10 +57,10 @@ describe('--target flag', () => { if (isWebpack5) { it('should allow multiple targets', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--target', 'node', '--target', 'async-node']); + const { stdout, exitCode } = run(__dirname, ['--target', 'node', '--target', 'async-node']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stdout).toContain(`target: [ 'node', 'async-node' ]`); }); } diff --git a/test/target/node/node-test.test.js b/test/target/node/node-test.test.js index f6719d9629e..c26936bb020 100644 --- a/test/target/node/node-test.test.js +++ b/test/target/node/node-test.test.js @@ -5,8 +5,8 @@ const { run } = require('../../utils/test-utils'); describe('Node target', () => { it('should emit the correct code', (done) => { - const { stderr } = run(__dirname, ['-c', './webpack.config.js']); - expect(stderr).toBeFalsy(); + run(__dirname, ['-c', './webpack.config.js']); + stat(resolve(__dirname, 'bin/main.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/unknown/unknown.test.js b/test/unknown/unknown.test.js index 903122b2495..8dbec4fee71 100644 --- a/test/unknown/unknown.test.js +++ b/test/unknown/unknown.test.js @@ -8,7 +8,7 @@ describe('unknown behaviour', () => { expect(exitCode).toBe(2); }); it('suggests the closest match to an unknown flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entyr', './a.js']); + const { stdout, stderr, exitCode } = run(__dirname, ['--entyr', './a.js']); expect(stderr).toContain('Unknown argument: --entyr'); expect(stdout).toContain('Did you mean --entry?'); expect(exitCode).toBe(2); diff --git a/test/utils/cli-plugin-test/plugin.test.js b/test/utils/cli-plugin-test/plugin.test.js index 14e4810a3fa..3eb69626b5e 100644 --- a/test/utils/cli-plugin-test/plugin.test.js +++ b/test/utils/cli-plugin-test/plugin.test.js @@ -4,8 +4,8 @@ const { run } = require('../test-utils'); describe('webpack-cli-test-plugin Test', () => { it('should log the webpack configuration', () => { - const { stderr, stdout } = run(__dirname); - expect(stderr).toBeFalsy(); + const { stdout } = run(__dirname); + expect(stdout).toContain(`target: 'node'`); if (typeof cli !== 'undefined') { expect(stdout).toContain(`alias: { alias: [ 'alias1', 'alias2' ] }`); diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js index 5f24458ad91..ee5124a36df 100644 --- a/test/utils/test-utils.js +++ b/test/utils/test-utils.js @@ -9,6 +9,7 @@ const concat = require('concat-stream'); const { version } = require('webpack'); const { version: devServerVersion } = require('webpack-dev-server/package.json'); const { hyphenToUpperCase } = require('../../packages/webpack-cli/lib/utils/arg-utils'); +const stripAnsi = require('strip-ansi'); const WEBPACK_PATH = path.resolve(__dirname, '../../packages/webpack-cli/bin/cli.js'); const ENABLE_LOG_COMPILATION = process.env.ENABLE_PIPE || false; @@ -16,6 +17,12 @@ const isWebpack5 = version.startsWith('5'); const isDevServer4 = devServerVersion.startsWith('4'); const isWindows = process.platform === 'win32'; +const cliLogs = [ + ' [webpack-cli] compilation starting...', + ` [webpack-cli] webpack ${version} compiled`, + ' [webpack-cli] watching files for updates...', +]; + /** * Run the webpack CLI for a test case. * @@ -57,7 +64,25 @@ const runWatch = (testCase, args = [], setOutput = true, outputKillStr = 'watchi proc.stdout.pipe( new Writable({ write(chunk, encoding, callback) { - const output = chunk.toString('utf8'); + const output = stripAnsi(chunk.toString('utf8')); + + if (output.includes(outputKillStr)) { + if (isWindows) { + exec('taskkill /pid ' + proc.pid + ' /T /F'); + } else { + proc.kill(); + } + } + + callback(); + }, + }), + ); + + proc.stderr.pipe( + new Writable({ + write(chunk, encoding, callback) { + const output = stripAnsi(chunk.toString('utf8')); if (output.includes(outputKillStr)) { if (isWindows) { @@ -127,6 +152,7 @@ const runPromptWithAnswers = (location, args, answers, waitForOutput = true) => new Writable({ write(chunk, encoding, callback) { const output = chunk.toString('utf8'); + if (output) { if (outputTimeout) { clearTimeout(outputTimeout); @@ -252,4 +278,5 @@ module.exports = { isWebpack5, isDevServer4, isWindows, + cliLogs, }; diff --git a/test/utils/test-utils.test.js b/test/utils/test-utils.test.js index a7e19b7b970..2ca9c566b17 100644 --- a/test/utils/test-utils.test.js +++ b/test/utils/test-utils.test.js @@ -34,18 +34,16 @@ describe('appendFile', () => { describe('run function', () => { it('should work correctly by default', () => { - const { command, stdout, stderr } = run(__dirname); + const { command } = run(__dirname); // Executes the correct command expect(command).toContain('cli.js'); // Should use apply a default output dir expect(command).toContain('--output-path'); expect(command).toContain('bin'); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); }); it('executes cli with passed commands and params', () => { - const { stdout, stderr, command } = run(__dirname, ['info', '--output', 'markdown'], false); + const { stdout, command } = run(__dirname, ['info', '--output', 'markdown'], false); // execution command contains info command expect(command).toContain('info'); expect(command).toContain('--output markdown'); @@ -55,32 +53,27 @@ describe('run function', () => { expect(stdout).toContain('Node'); expect(stdout).toContain('npm'); expect(stdout).toContain('Yarn'); - expect(stderr).toBeFalsy(); }); it('uses default output when output param is false', () => { - const { stdout, stderr, command } = run(__dirname, [], false); + const { command } = run(__dirname, [], false); // execution command contains info command expect(command).not.toContain('--output-path'); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); }); }); describe('runAndGetWatchProc function', () => { it('should work correctly by default', async () => { - const { command, stdout, stderr } = await runAndGetWatchProc(__dirname); + const { command } = await runAndGetWatchProc(__dirname); // Executes the correct command expect(command).toContain('cli.js'); // Should use apply a default output dir expect(command).toContain('--output-path'); expect(command).toContain('bin'); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); }); it('executes cli with passed commands and params', async () => { - const { stdout, stderr, command } = await runAndGetWatchProc(__dirname, ['info', '--output', 'markdown'], false); + const { stdout, command } = await runAndGetWatchProc(__dirname, ['info', '--output', 'markdown'], false); // execution command contains info command expect(command).toContain('info'); expect(command).toContain('--output markdown'); @@ -90,15 +83,12 @@ describe('runAndGetWatchProc function', () => { expect(stdout).toContain('Node'); expect(stdout).toContain('npm'); expect(stdout).toContain('Yarn'); - expect(stderr).toBeFalsy(); }); it('uses default output when output param is false', async () => { - const { stdout, stderr, command } = await runAndGetWatchProc(__dirname, [], false); + const { command } = await runAndGetWatchProc(__dirname, [], false); // execution command contains info command expect(command).not.toContain('--output-path'); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); }); it('writes to stdin', async () => { diff --git a/test/version/version-external-packages.test.js b/test/version/version-external-packages.test.js index 7dfd06b5084..a81ae7b04d9 100644 --- a/test/version/version-external-packages.test.js +++ b/test/version/version-external-packages.test.js @@ -11,66 +11,59 @@ const cliPkgJSON = require('../../packages/webpack-cli/package.json'); describe('version flag with external packages', () => { it('outputs version with init', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['init', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['init', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(initPkgJSON.version); expect(stdout).toContain(cliPkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs version with the alias c for init', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['c', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['c', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(initPkgJSON.version); expect(stdout).toContain(cliPkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs version with info', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['info', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['info', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(infoPkgJSON.version); expect(stdout).toContain(cliPkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs version with serve', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['serve', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['serve', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(servePkgJSON.version); expect(stdout).toContain(cliPkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs version with migrate', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['migrate', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['migrate', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(migratePkgJSON.version); expect(stdout).toContain(cliPkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs version with plugin', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['plugin', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['plugin', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pluginPkgJSON.version); expect(stdout).toContain(cliPkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs version with loader', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['loader', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['loader', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(loaderPkgJSON.version); expect(stdout).toContain(cliPkgJSON.version); - expect(stderr).toHaveLength(0); }); it(' should throw error for multiple commands', () => { @@ -81,7 +74,7 @@ describe('version flag with external packages', () => { }); it(' should throw error if invalid argument is present with --version flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['init', 'abc', '--version'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['init', 'abc', '--version'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`Error: Invalid command 'abc'`); @@ -89,7 +82,7 @@ describe('version flag with external packages', () => { }); it(' should throw error if invalid argument is present with version command', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['init', 'abc', 'version'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['init', 'abc', 'version'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`Error: Invalid command 'abc'`); @@ -97,7 +90,7 @@ describe('version flag with external packages', () => { }); it(' should throw error if invalid argument is present with -v alias', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['init', 'abc', '-v'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['init', 'abc', '-v'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`Error: Invalid command 'abc'`); diff --git a/test/version/version-multi-args.test.js b/test/version/version-multi-args.test.js index 585bb59b792..d1f32cda11f 100644 --- a/test/version/version-multi-args.test.js +++ b/test/version/version-multi-args.test.js @@ -5,25 +5,23 @@ const pkgJSON = require('../../packages/webpack-cli/package.json'); describe('version flag with multiple arguments', () => { it('does not output version with help command', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['version', 'help'], false); + const { stdout, exitCode } = run(__dirname, ['version', 'help'], false); expect(stdout).not.toContain(pkgJSON.version); expect(exitCode).toBe(0); const uniqueIdentifier = 'The build tool for modern web applications'; expect(stdout).toContain(uniqueIdentifier); - expect(stderr).toHaveLength(0); }); it('does not output version with help dashed', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['version', '--help'], false); + const { stdout, exitCode } = run(__dirname, ['version', '--help'], false); expect(stdout).not.toContain(pkgJSON.version); expect(exitCode).toBe(0); const uniqueIdentifier = 'The build tool for modern web applications'; expect(stdout).toContain(uniqueIdentifier); - expect(stderr).toHaveLength(0); }); it('throws error if invalid command is passed with version command', () => { diff --git a/test/version/version-single-arg.test.js b/test/version/version-single-arg.test.js index 72a6114b8a3..b4a3a4a4bef 100644 --- a/test/version/version-single-arg.test.js +++ b/test/version/version-single-arg.test.js @@ -5,26 +5,23 @@ const pkgJSON = require('../../packages/webpack-cli/package.json'); describe('single version flag', () => { it('outputs versions with command syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['version'], false); + const { stdout, exitCode } = run(__dirname, ['version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs versions with dashed syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--version'], false); + const { stdout, exitCode } = run(__dirname, ['--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pkgJSON.version); - expect(stderr).toHaveLength(0); }); it('outputs versions with alias syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-v'], false); + const { stdout, exitCode } = run(__dirname, ['-v'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pkgJSON.version); - expect(stderr).toHaveLength(0); }); }); diff --git a/test/watch/watch-flag.test.js b/test/watch/watch-flag.test.js index e326fed48d8..6d769cab134 100644 --- a/test/watch/watch-flag.test.js +++ b/test/watch/watch-flag.test.js @@ -1,7 +1,7 @@ 'use strict'; const stripAnsi = require('strip-ansi'); -const { runAndGetWatchProc, isWebpack5 } = require('../utils/test-utils'); +const { runAndGetWatchProc, isWebpack5, cliLogs } = require('../utils/test-utils'); const { writeFileSync } = require('fs'); const { resolve } = require('path'); @@ -12,17 +12,9 @@ describe('--watch flag', () => { it('should recompile upon file change', (done) => { const proc = runAndGetWatchProc(__dirname, ['--watch'], false, '', true); let semaphore = 0; + proc.stdout.on('data', (chunk) => { const data = stripAnsi(chunk.toString()); - - if (semaphore === 0 && data.includes('watching files for updates')) { - process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');`); - - semaphore++; - }); - } - if (semaphore === 1 && data.includes('index.js')) { if (isWebpack5) { for (const word of wordsInStatsv5) { @@ -36,8 +28,20 @@ describe('--watch flag', () => { semaphore++; } + }); + + proc.stderr.on('data', (chunk) => { + const data = stripAnsi(chunk.toString()); + + if (semaphore === 0 && data.includes(cliLogs[2])) { + process.nextTick(() => { + writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');`); + + semaphore++; + }); + } - if (semaphore === 2 && data.includes('watching files for updates')) { + if (semaphore === 2 && data.includes(cliLogs[2])) { proc.kill(); done(); } @@ -47,17 +51,9 @@ describe('--watch flag', () => { it('should print compilation lifecycle', (done) => { const proc = runAndGetWatchProc(__dirname, ['--watch'], false, '', true); let semaphore = 0; + proc.stdout.on('data', (chunk) => { const data = stripAnsi(chunk.toString()); - - if (semaphore === 0 && data.includes('Compilation starting')) { - semaphore++; - } - - if (semaphore === 1 && data.includes('Compilation finished')) { - semaphore++; - } - if (semaphore === 2 && data.includes('index.js')) { if (isWebpack5) { for (const word of wordsInStatsv5) { @@ -71,8 +67,20 @@ describe('--watch flag', () => { semaphore++; } + }); + + proc.stderr.on('data', (chunk) => { + const data = stripAnsi(chunk.toString()); + + if (semaphore === 0 && data.includes(cliLogs[0])) { + semaphore++; + } + + if (semaphore === 1 && data.includes(cliLogs[1])) { + semaphore++; + } - if (semaphore === 3 && data.includes('watching files for updates...')) { + if (semaphore === 3 && data.includes(cliLogs[2])) { semaphore++; proc.kill(); diff --git a/test/zero-config/entry-absent/zero-config.test.js b/test/zero-config/entry-absent/zero-config.test.js index b67e707fba1..8a94f039473 100644 --- a/test/zero-config/entry-absent/zero-config.test.js +++ b/test/zero-config/entry-absent/zero-config.test.js @@ -2,10 +2,9 @@ const { run } = require('../../utils/test-utils'); describe('Zero Config tests', () => { it('runs when config and entry are both absent', () => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + const { stdout, exitCode } = run(__dirname, [], false); // Entry file is absent, should log the Error from the compiler expect(stdout).toContain("Error: Can't resolve './src'"); expect(exitCode).toBe(1); - expect(stderr).toBeFalsy(); }); }); diff --git a/test/zero-config/entry-present/zero-config.test.js b/test/zero-config/entry-present/zero-config.test.js index dc551da4bcf..1b9eeac7ed3 100644 --- a/test/zero-config/entry-present/zero-config.test.js +++ b/test/zero-config/entry-present/zero-config.test.js @@ -4,14 +4,14 @@ const { run } = require('../../utils/test-utils'); describe('Zero Config tests', () => { it('runs when no config is supplied but entry is present', () => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + const { stdout, exitCode } = run(__dirname, [], false); // Should be able to find the entry file expect(stdout).toContain('./src/index.js'); // Should output at the default output dir and filename expect(stdout).toContain('main.js'); // check that the output file exists expect(fs.existsSync(path.join(__dirname, '/dist/main.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); }); });