From e3bf375869c952f0ead6cdf7f4239f904bb403d0 Mon Sep 17 00:00:00 2001 From: Damian Pieczynski Date: Fri, 6 Nov 2020 12:08:52 +0100 Subject: [PATCH] refactor: revert logger --- packages/webpack-cli/__tests__/info.test.js | 12 ++--- packages/webpack-cli/lib/utils/logger.js | 26 +++------ test/core-flags/bail-flag.test.js | 2 +- test/core-flags/cache-flags.test.js | 4 +- test/help/help-commands.test.js | 23 ++++---- test/help/help-flags.test.js | 22 ++++---- test/help/help-multi-args.test.js | 12 ++--- test/help/help-single-arg.test.js | 14 ++--- test/info/info-help.test.js | 16 +++--- test/info/info-output.test.js | 20 +++---- test/init/coreFlags/init-flags.test.js | 4 +- test/serve/basic/serve-basic.test.js | 4 +- test/unknown/unknown.test.js | 4 +- test/utils/test-utils.test.js | 20 +++---- .../version/version-external-packages.test.js | 54 +++++++++---------- test/version/version-multi-args.test.js | 20 +++---- test/version/version-single-arg.test.js | 12 ++--- 17 files changed, 127 insertions(+), 142 deletions(-) diff --git a/packages/webpack-cli/__tests__/info.test.js b/packages/webpack-cli/__tests__/info.test.js index 5518e4b18c9..44a6f1fc2d2 100644 --- a/packages/webpack-cli/__tests__/info.test.js +++ b/packages/webpack-cli/__tests__/info.test.js @@ -3,23 +3,23 @@ const path = require('path'); describe('Info', () => { it('should run with cli', () => { - const { 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(stderr).toContain('System'); - expect(stderr).toContain('Binaries'); - expect(stderr).toContain('OS'); + expect(stdout).toContain('System'); + expect(stdout).toContain('Binaries'); + expect(stdout).toContain('OS'); }); it('should work with flags', () => { - const { 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, }); const testJSON = () => { - const output = JSON.parse(stderr); + const output = JSON.parse(stdout); expect(output['System']).toBeTruthy(); expect(output['System']['OS']).toBeTruthy(); }; diff --git a/packages/webpack-cli/lib/utils/logger.js b/packages/webpack-cli/lib/utils/logger.js index df84ba1c219..3afafc1ad44 100644 --- a/packages/webpack-cli/lib/utils/logger.js +++ b/packages/webpack-cli/lib/utils/logger.js @@ -1,25 +1,11 @@ const util = require('util'); const { red, cyan, yellow, green } = require('colorette'); -const write = (prefix = '[webpack-cli] ', color = (val) => val) => { - return (...args) => { - const str = prefix + color(util.format(...args)); - process.stderr.write(str + '\n'); - }; -}; - module.exports = { - error: write(undefined, red), - warn: write(undefined, yellow), - info: write(undefined, cyan), - log: write(), - - /** - * @deprecated use info - */ - success: write(undefined, green), - /** - * @deprecated use info - */ - raw: write(''), + error: (val) => console.error(`[webpack-cli] ${red(util.format(val))}`), + warn: (val) => console.warn(`[webpack-cli] ${yellow(val)}`), + info: (val) => console.info(`[webpack-cli] ${cyan(val)}`), + success: (val) => console.log(`[webpack-cli] ${green(val)}`), + log: (val) => console.log(`[webpack-cli] ${val}`), + raw: (val) => console.log(val), }; diff --git a/test/core-flags/bail-flag.test.js b/test/core-flags/bail-flag.test.js index dd2576642c1..e5bd7f71a7e 100644 --- a/test/core-flags/bail-flag.test.js +++ b/test/core-flags/bail-flag.test.js @@ -2,7 +2,7 @@ const { run } = require('../utils/test-utils'); -describe.skip('--bail flag', () => { +describe('--bail flag', () => { it('should set bail to true', () => { const { stdout, exitCode } = run(__dirname, ['--bail']); diff --git a/test/core-flags/cache-flags.test.js b/test/core-flags/cache-flags.test.js index 26f985b14ef..cbc15da1220 100644 --- a/test/core-flags/cache-flags.test.js +++ b/test/core-flags/cache-flags.test.js @@ -122,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'"); diff --git a/test/help/help-commands.test.js b/test/help/help-commands.test.js index 292c19f49ab..198d17422de 100644 --- a/test/help/help-commands.test.js +++ b/test/help/help-commands.test.js @@ -5,41 +5,40 @@ const helpHeader = 'The build tool for modern web applications'; describe('commands help', () => { it('shows help for subcommands', () => { - const { stderr, exitCode } = run(__dirname, ['serve', 'help'], false); + const { stdout, exitCode } = run(__dirname, ['serve', 'help'], false); expect(exitCode).toBe(0); - - expect(stderr).toContain('webpack s | serve'); + expect(stdout).toContain('webpack s | serve'); }); it('shows help information with subcommands as an arg', () => { - const { stderr, exitCode } = run(__dirname, ['help', 'serve'], false); + const { stdout, exitCode } = run(__dirname, ['help', 'serve'], false); expect(exitCode).toBe(0); - expect(stderr).toContain('webpack s | serve'); + expect(stdout).toContain('webpack s | serve'); }); it('shows warning for invalid command with --help flag', () => { - const { stderr, 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'`); - expect(stderr).toContain(helpHeader); + expect(stdout).toContain(helpHeader); }); it('shows warning for invalid command with help command', () => { - const { stderr, 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'`); - expect(stderr).toContain(helpHeader); + expect(stdout).toContain(helpHeader); }); it('gives precedence to earlier command in case of multiple commands', () => { - const { stderr, exitCode } = run(__dirname, ['--help', 'init', 'info'], false); + const { stdout, exitCode } = run(__dirname, ['--help', 'init', 'info'], false); expect(exitCode).toBe(0); - expect(stderr).not.toContain(helpHeader); - expect(stderr).toContain('webpack c | init [scaffold]'); + expect(stdout).not.toContain(helpHeader); + expect(stdout).toContain('webpack c | init [scaffold]'); }); }); diff --git a/test/help/help-flags.test.js b/test/help/help-flags.test.js index 4f2938e4bc2..621cdc02370 100644 --- a/test/help/help-flags.test.js +++ b/test/help/help-flags.test.js @@ -5,43 +5,43 @@ const helpHeader = 'The build tool for modern web applications'; describe('commands help', () => { it('log warning for invalid flag with --help flag', () => { - const { stderr, 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'`); - expect(stderr).toContain(helpHeader); + expect(stdout).toContain(helpHeader); }); it('log warning for invalid flag with help command', () => { - const { stderr, 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'`); - expect(stderr).toContain(helpHeader); + expect(stdout).toContain(helpHeader); }); it('shows flag help with valid flag', () => { const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--merge'], false); expect(exitCode).toBe(0); - expect(stdout).not.toContain(helpHeader); - expect(stderr).toContain('webpack -m, --merge'); + expect(stderr).not.toContain(helpHeader); + expect(stdout).toContain('webpack -m, --merge'); }); 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).toContain('webpack --mode '); - expect(stderr).toContain('Defines the mode to pass to webpack'); + expect(stderr).not.toContain(helpHeader); + expect(stdout).toContain('webpack --mode '); + expect(stdout).toContain('Defines the mode to pass to webpack'); }); 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).toContain('webpack --entry '); + expect(stderr).not.toContain(helpHeader); + expect(stdout).toContain('webpack --entry '); }); }); diff --git a/test/help/help-multi-args.test.js b/test/help/help-multi-args.test.js index 8cd7c019a4a..34944ad129b 100644 --- a/test/help/help-multi-args.test.js +++ b/test/help/help-multi-args.test.js @@ -7,21 +7,21 @@ const helpHeader = 'The build tool for modern web applications'; describe('help cmd with multiple arguments', () => { commands.forEach((cmd) => { it(`shows cmd help with ${cmd.name}`, () => { - const { stderr, exitCode } = run(__dirname, ['--help', `${cmd.name}`], false); + const { stdout, stderr, exitCode } = run(__dirname, ['--help', `${cmd.name}`], false); expect(exitCode).toBe(0); expect(stderr).not.toContain(helpHeader); - expect(stderr).toContain(`${cmd.name}`); - expect(stderr).toContain(`${cmd.usage}`); - expect(stderr).toContain(`${cmd.description}`); + expect(stdout).toContain(`${cmd.name}`); + expect(stdout).toContain(`${cmd.usage}`); + expect(stdout).toContain(`${cmd.description}`); }); }); it('should output help for --version by taking precedence', () => { - const { stderr, exitCode } = run(__dirname, ['--help', '--version'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--version'], false); expect(exitCode).toBe(0); expect(stderr).not.toContain(helpHeader); - expect(stderr).toContain('webpack -v, --version'); + expect(stdout).toContain('webpack -v, --version'); }); }); diff --git a/test/help/help-single-arg.test.js b/test/help/help-single-arg.test.js index b236b0644a7..532e8178a47 100644 --- a/test/help/help-single-arg.test.js +++ b/test/help/help-single-arg.test.js @@ -6,7 +6,7 @@ const helpHeader = 'The build tool for modern web applications'; describe('single help flag', () => { it('respects --no-color flag', () => { - const { stderr, exitCode } = run(__dirname, ['--help', '--no-color'], false); + const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--no-color'], false); const usage = 'webpack [...options] | '; const example = 'webpack help --flag | '; options.enabled = true; @@ -14,22 +14,22 @@ describe('single help flag', () => { expect(exitCode).toBe(0); expect(stderr).not.toContain(yellow(usage)); expect(stderr).not.toContain(yellow(example)); - expect(stderr).toContain(usage); - expect(stderr).toContain(example); + expect(stdout).toContain(usage); + expect(stdout).toContain(example); }); it('outputs help info with command syntax', () => { - const { stderr, exitCode } = run(__dirname, ['help'], false); + const { stdout, exitCode } = run(__dirname, ['help'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(helpHeader); + expect(stdout).toContain(helpHeader); }); it('outputs help info with dashed syntax', () => { - const { stderr, exitCode } = run(__dirname, ['--help'], false); + const { stdout, exitCode } = run(__dirname, ['--help'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(helpHeader); + expect(stdout).toContain(helpHeader); }); it('creates a readable snapshot', () => { diff --git a/test/info/info-help.test.js b/test/info/info-help.test.js index 3d7a039e01f..b82b95de4ba 100644 --- a/test/info/info-help.test.js +++ b/test/info/info-help.test.js @@ -11,26 +11,26 @@ 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 { stderr, exitCode } = runInfo(['--help'], __dirname); + const { stdout, exitCode } = runInfo(['--help'], __dirname); expect(exitCode).toBe(0); - expect(stderr).toContain(usageText); - expect(stderr).toContain(descriptionText); + expect(stdout).toContain(usageText); + expect(stdout).toContain(descriptionText); }); it('should respect the --no-color flag', () => { - const { stderr, exitCode } = runInfo(['--help', '--no-color'], __dirname); + const { stdout, exitCode } = runInfo(['--help', '--no-color'], __dirname); options.enabled = true; expect(exitCode).toBe(0); - expect(stderr).not.toContain(yellow(usageText)); - expect(stderr).toContain(descriptionText); + expect(stdout).not.toContain(yellow(usageText)); + expect(stdout).toContain(descriptionText); }); it('should output all cli flags', () => { - const { stderr, exitCode } = runInfo(['--help'], __dirname); + const { stdout, exitCode } = runInfo(['--help'], __dirname); - infoFlags.forEach((flag) => expect(stderr).toContain(`--${flag.name}`)); + infoFlags.forEach((flag) => expect(stdout).toContain(`--${flag.name}`)); expect(exitCode).toBe(0); }); diff --git a/test/info/info-output.test.js b/test/info/info-output.test.js index 31020f91fa3..8878212caad 100644 --- a/test/info/info-output.test.js +++ b/test/info/info-output.test.js @@ -5,19 +5,19 @@ const { runInfo } = require('../utils/test-utils'); describe('basic info usage', () => { it('gets info without flags', () => { - const { stderr } = runInfo([], __dirname); - expect(stderr).toContain('System:'); - expect(stderr).toContain('Node'); - expect(stderr).toContain('npm'); - expect(stderr).toContain('Yarn'); + const { stdout } = runInfo([], __dirname); + expect(stdout).toContain('System:'); + expect(stdout).toContain('Node'); + expect(stdout).toContain('npm'); + expect(stdout).toContain('Yarn'); }); it('gets info as json', () => { - const { stderr } = runInfo(['--output="json"'], __dirname); - expect(stderr).toContain('"System":'); + const { stdout } = runInfo(['--output="json"'], __dirname); + expect(stdout).toContain('"System":'); const parse = () => { - const output = JSON.parse(stderr); + const output = JSON.parse(stdout); expect(output['System']).toBeTruthy(); expect(output['Binaries']).toBeTruthy(); expect(output['System']['OS']).toBeTruthy(); @@ -28,8 +28,8 @@ describe('basic info usage', () => { }); it('gets info as markdown', () => { - const { stderr } = runInfo(['--output="markdown"'], __dirname); - expect(stderr).toContain('## System:'); + const { stdout } = runInfo(['--output="markdown"'], __dirname); + expect(stdout).toContain('## System:'); }); it('shows a warning if an invalid value is supplied', () => { diff --git a/test/init/coreFlags/init-flags.test.js b/test/init/coreFlags/init-flags.test.js index 8c600960108..3885b0a8c0d 100644 --- a/test/init/coreFlags/init-flags.test.js +++ b/test/init/coreFlags/init-flags.test.js @@ -6,10 +6,10 @@ 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); + const { stdout } = run(__dirname, ['init', '--help'], false); expect(stdout).not.toContain(firstPrompt); - expect(stderr).toContain('Initialize a new webpack configuration'); + expect(stdout).toContain('Initialize a new webpack configuration'); }); it('should throw error with invalid scaffolder package', () => { const { stderr } = run(__dirname, ['init', 'webpack-rocks'], false); diff --git a/test/serve/basic/serve-basic.test.js b/test/serve/basic/serve-basic.test.js index e661c21a0eb..17cfcb6f5b9 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -28,10 +28,10 @@ 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(stderr).toContain(descriptionText); + expect(stdout).toContain(descriptionText); }); it('should not invoke info subcommand', async () => { diff --git a/test/unknown/unknown.test.js b/test/unknown/unknown.test.js index 81a66c5029d..8dbec4fee71 100644 --- a/test/unknown/unknown.test.js +++ b/test/unknown/unknown.test.js @@ -8,9 +8,9 @@ describe('unknown behaviour', () => { expect(exitCode).toBe(2); }); it('suggests the closest match to an unknown flag', () => { - const { stderr, exitCode } = run(__dirname, ['--entyr', './a.js']); + const { stdout, stderr, exitCode } = run(__dirname, ['--entyr', './a.js']); expect(stderr).toContain('Unknown argument: --entyr'); - expect(stderr).toContain('Did you mean --entry?'); + expect(stdout).toContain('Did you mean --entry?'); expect(exitCode).toBe(2); }); }); diff --git a/test/utils/test-utils.test.js b/test/utils/test-utils.test.js index 7a3e04de09c..2ca9c566b17 100644 --- a/test/utils/test-utils.test.js +++ b/test/utils/test-utils.test.js @@ -43,16 +43,16 @@ describe('run function', () => { }); it('executes cli with passed commands and params', () => { - const { 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'); // Contains info command output - expect(stderr).toContain('System:'); - expect(stderr).toContain('Node'); - expect(stderr).toContain('npm'); - expect(stderr).toContain('Yarn'); + expect(stdout).toContain('System:'); + expect(stdout).toContain('Node'); + expect(stdout).toContain('npm'); + expect(stdout).toContain('Yarn'); }); it('uses default output when output param is false', () => { @@ -73,16 +73,16 @@ describe('runAndGetWatchProc function', () => { }); it('executes cli with passed commands and params', async () => { - const { 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'); // Contains info command output - expect(stderr).toContain('System:'); - expect(stderr).toContain('Node'); - expect(stderr).toContain('npm'); - expect(stderr).toContain('Yarn'); + expect(stdout).toContain('System:'); + expect(stdout).toContain('Node'); + expect(stdout).toContain('npm'); + expect(stdout).toContain('Yarn'); }); it('uses default output when output param is false', async () => { diff --git a/test/version/version-external-packages.test.js b/test/version/version-external-packages.test.js index a2d1b734605..a81ae7b04d9 100644 --- a/test/version/version-external-packages.test.js +++ b/test/version/version-external-packages.test.js @@ -11,59 +11,59 @@ const cliPkgJSON = require('../../packages/webpack-cli/package.json'); describe('version flag with external packages', () => { it('outputs version with init', () => { - const { stderr, exitCode } = run(__dirname, ['init', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['init', '--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(initPkgJSON.version); - expect(stderr).toContain(cliPkgJSON.version); + expect(stdout).toContain(initPkgJSON.version); + expect(stdout).toContain(cliPkgJSON.version); }); it('outputs version with the alias c for init', () => { - const { stderr, exitCode } = run(__dirname, ['c', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['c', '--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(initPkgJSON.version); - expect(stderr).toContain(cliPkgJSON.version); + expect(stdout).toContain(initPkgJSON.version); + expect(stdout).toContain(cliPkgJSON.version); }); it('outputs version with info', () => { - const { stderr, exitCode } = run(__dirname, ['info', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['info', '--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(infoPkgJSON.version); - expect(stderr).toContain(cliPkgJSON.version); + expect(stdout).toContain(infoPkgJSON.version); + expect(stdout).toContain(cliPkgJSON.version); }); it('outputs version with serve', () => { - const { stderr, exitCode } = run(__dirname, ['serve', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['serve', '--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(servePkgJSON.version); - expect(stderr).toContain(cliPkgJSON.version); + expect(stdout).toContain(servePkgJSON.version); + expect(stdout).toContain(cliPkgJSON.version); }); it('outputs version with migrate', () => { - const { stderr, exitCode } = run(__dirname, ['migrate', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['migrate', '--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(migratePkgJSON.version); - expect(stderr).toContain(cliPkgJSON.version); + expect(stdout).toContain(migratePkgJSON.version); + expect(stdout).toContain(cliPkgJSON.version); }); it('outputs version with plugin', () => { - const { stderr, exitCode } = run(__dirname, ['plugin', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['plugin', '--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(pluginPkgJSON.version); - expect(stderr).toContain(cliPkgJSON.version); + expect(stdout).toContain(pluginPkgJSON.version); + expect(stdout).toContain(cliPkgJSON.version); }); it('outputs version with loader', () => { - const { stderr, exitCode } = run(__dirname, ['loader', '--version'], false); + const { stdout, exitCode } = run(__dirname, ['loader', '--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(loaderPkgJSON.version); - expect(stderr).toContain(cliPkgJSON.version); + expect(stdout).toContain(loaderPkgJSON.version); + expect(stdout).toContain(cliPkgJSON.version); }); it(' should throw error for multiple commands', () => { @@ -74,26 +74,26 @@ describe('version flag with external packages', () => { }); it(' should throw error if invalid argument is present with --version flag', () => { - const { stderr, 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'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); it(' should throw error if invalid argument is present with version command', () => { - const { stderr, 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'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); it(' should throw error if invalid argument is present with -v alias', () => { - const { stderr, 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'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); }); diff --git a/test/version/version-multi-args.test.js b/test/version/version-multi-args.test.js index 38ccf992df7..d1f32cda11f 100644 --- a/test/version/version-multi-args.test.js +++ b/test/version/version-multi-args.test.js @@ -5,23 +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(stderr).toContain(uniqueIdentifier); + expect(stdout).toContain(uniqueIdentifier); }); 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(stderr).toContain(uniqueIdentifier); + expect(stdout).toContain(uniqueIdentifier); }); it('throws error if invalid command is passed with version command', () => { @@ -30,7 +30,7 @@ describe('version flag with multiple arguments', () => { expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); expect(stderr).toContain(`Error: Invalid command 'abc'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); it('throws error if invalid option is passed with version command', () => { @@ -39,7 +39,7 @@ describe('version flag with multiple arguments', () => { expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); expect(stderr).toContain(`Error: Invalid option '--abc'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); it('throws error if invalid command is passed with --version flag', () => { @@ -48,7 +48,7 @@ describe('version flag with multiple arguments', () => { expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); expect(stderr).toContain(`Error: Invalid command 'abc'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); it('throws error if invalid option is passed with --version flag', () => { @@ -57,7 +57,7 @@ describe('version flag with multiple arguments', () => { expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); expect(stderr).toContain(`Error: Invalid option '--abc'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); it('throws error if invalid command is passed with -v alias', () => { @@ -66,7 +66,7 @@ describe('version flag with multiple arguments', () => { expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); expect(stderr).toContain(`Error: Invalid command 'abc'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); it('throws error if invalid option is passed with -v alias', () => { @@ -75,6 +75,6 @@ describe('version flag with multiple arguments', () => { expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); expect(stderr).toContain(`Error: Invalid option '--abc'`); - expect(stderr).toContain('Run webpack --help to see available commands and arguments'); + expect(stdout).toContain('Run webpack --help to see available commands and arguments'); }); }); diff --git a/test/version/version-single-arg.test.js b/test/version/version-single-arg.test.js index d7956fb8b6a..b4a3a4a4bef 100644 --- a/test/version/version-single-arg.test.js +++ b/test/version/version-single-arg.test.js @@ -5,23 +5,23 @@ const pkgJSON = require('../../packages/webpack-cli/package.json'); describe('single version flag', () => { it('outputs versions with command syntax', () => { - const { stderr, exitCode } = run(__dirname, ['version'], false); + const { stdout, exitCode } = run(__dirname, ['version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(pkgJSON.version); + expect(stdout).toContain(pkgJSON.version); }); it('outputs versions with dashed syntax', () => { - const { stderr, exitCode } = run(__dirname, ['--version'], false); + const { stdout, exitCode } = run(__dirname, ['--version'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(pkgJSON.version); + expect(stdout).toContain(pkgJSON.version); }); it('outputs versions with alias syntax', () => { - const { stderr, exitCode } = run(__dirname, ['-v'], false); + const { stdout, exitCode } = run(__dirname, ['-v'], false); expect(exitCode).toBe(0); - expect(stderr).toContain(pkgJSON.version); + expect(stdout).toContain(pkgJSON.version); }); });