From 7daccc786a0eb4eeae4c5b3632fc28240a696170 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Tue, 1 Dec 2020 17:49:49 +0300 Subject: [PATCH] feat: respect the `infrastructureLogging.level` option (potential breaking change, logger uses `stderr`) (#2144) --- .../webpack-cli/__tests__/serve/serve.test.js | 12 ++- packages/webpack-cli/lib/plugins/CLIPlugin.js | 21 ++-- packages/webpack-cli/lib/webpack-cli.js | 5 + test/analyze/analyze-flag.test.js | 3 +- test/bail/bail.test.js | 33 +++++- test/build-errors/errors.test.js | 18 ++-- test/build-warnings/warnings.test.js | 19 ++-- test/cache/cache.test.js | 9 ++ test/colors/colors.test.js | 75 +++++++------ test/config-format/coffee/coffee.test.js | 18 ++-- test/config-format/commonjs/commonjs.test.js | 10 +- .../typescript/typescript.test.js | 2 +- .../custom-name/custom-name.test.js | 11 +- .../dotfolder-array/dotfolder-array.test.js | 24 ++--- .../dotfolder-single/dotfolder-single.test.js | 18 +--- .../relative/basic-config.test.js | 21 ++-- test/config-name/config-name.test.js | 33 ++++-- test/config/absent/config-absent.test.js | 14 +-- test/config/basic/basic-config.test.js | 10 +- .../basic-config/default-js-config.test.js | 12 ++- .../cjs-config/default-cjs-config.test.js | 11 +- .../multiple-location-config.test.js | 9 +- .../dev-none-config.test.js | 9 +- .../with-mode/multiple-config.test.js | 9 +- test/config/empty-array/empty-array.test.js | 8 +- .../empty-function/empty-function.test.js | 8 +- .../empty-promise/empty-promise.test.js | 8 +- test/config/empty/empty.test.js | 8 +- test/config/error/config-error.test.js | 10 +- .../config/function/functional-config.test.js | 39 +++---- .../invalid-export/invalid-export.test.js | 1 + test/config/invalid-path/invalid-path.test.js | 3 +- .../multiple-with-one-compilation.test.js | 10 +- test/config/multiple/multiple-config.test.js | 17 ++- .../no-config-array/no-config-array.test.js | 2 +- .../no-config-object/no-config-object.test.js | 6 +- .../function-with-argv.test.js | 27 +++-- .../webpack.config.js | 2 + .../array-function-with-env.test.js | 27 +++-- .../array-function-with-env/webpack.config.js | 2 + .../array-functions/array-functions.test.js | 8 +- .../type/array-functions/webpack.config.js | 2 + .../array-promises/array-promises.test.js | 9 +- .../type/array-promises/webpack.config.js | 2 + test/config/type/array/array.test.js | 8 +- .../function-array/function-array.test.js | 8 +- .../type/function-array/webpack.config.js | 2 + .../function-async/function-async.test.js | 6 +- .../function-promise/function-promise.test.js | 6 +- .../function-with-argv.test.js | 20 ++-- .../function-with-env.test.js | 82 +++++++++----- test/config/type/function/function.test.js | 8 +- .../type/promise-array/promise-array.test.js | 7 +- .../promise-function/promise-function.test.js | 8 +- test/config/type/promise/promise.test.js | 8 +- test/core-flags/amd-flag.test.js | 5 +- test/core-flags/bail-flag.test.js | 10 +- test/core-flags/cache-flags.test.js | 102 +++++++++++------- test/core-flags/context-flag.test.js | 11 +- test/core-flags/dependencies-flag.test.js | 10 +- test/core-flags/devtool-flag.test.js | 8 +- test/core-flags/entry-reset-flag.test.js | 11 +- test/core-flags/experiments-flag.test.js | 10 +- test/core-flags/externals-flags.test.js | 30 +++--- .../core-flags/infrastructure-logging.test.js | 15 +-- test/core-flags/invalid-flag.test.js | 2 +- test/core-flags/module-flags.test.js | 37 ++++--- test/core-flags/node-flags.test.js | 15 +-- test/core-flags/optimization-flags.test.js | 43 +++++--- test/core-flags/output-flags.test.js | 75 ++++++++----- test/core-flags/parallelism-flag.test.js | 11 +- test/core-flags/performance-flags.test.js | 15 +-- test/core-flags/profile-flag.test.js | 10 +- test/core-flags/records-flag.test.js | 15 +-- test/core-flags/resolve-flags.test.js | 25 +++-- test/core-flags/snapshot-flags.test.js | 11 +- test/core-flags/stats-flags.test.js | 40 ++++--- test/core-flags/watch-flags.test.js | 22 ++-- test/defaults/output-defaults.test.js | 18 +++- test/devtool/array/source-map-array.test.js | 18 ++-- test/devtool/object/source-map-object.test.js | 28 +++-- .../entry-with-command.test.js | 15 +-- .../entry-with-config.test.js | 15 +-- .../entry-with-config.test.js | 14 +-- .../defaults-empty/entry-single-arg.test.js | 5 +- .../defaults-index/entry-multi-args.test.js | 30 ++---- test/entry/flag-entry/entry-with-flag.test.js | 51 ++++----- .../multiple-entries/multi-entries.test.js | 10 +- test/entry/scss/scss.test.js | 2 + test/env/array/array-env.test.js | 5 +- test/env/object/object-env.test.js | 5 +- test/error/error.test.js | 6 +- test/help/help-commands.test.js | 10 +- test/help/help-flags.test.js | 10 +- test/help/help-multi-args.test.js | 8 +- test/help/help-single-arg.test.js | 15 +-- test/hot/hot-flag.test.js | 9 +- test/info/info-help.test.js | 6 +- test/info/info-output.test.js | 2 +- test/info/info-unknown.test.js | 2 +- test/invalid-schema/invalid-schema.test.js | 4 + .../config-absent/merge-config-absent.test.js | 10 +- test/merge/config/merge-config.test.js | 30 +++--- .../mode-single-arg/mode-single-arg.test.js | 31 ++++-- .../mode-with-config/mode-with-config.test.js | 44 +++++--- test/name/name.test.js | 5 +- test/no-hot/no-hot.test.js | 15 +-- test/no-stats/with-config/main.js | 3 - .../with-config/no-stats-with-config.test.js | 14 ++- test/no-stats/with-flags/main.js | 3 - test/no-stats/with-flags/no-stats.test.js | 19 +++- test/node/node.test.js | 27 ++--- test/optimization/optimization.test.js | 27 +++-- .../output-named-bundles.test.js | 54 +++++----- test/prefetch/prefetch.test.js | 21 ++-- test/progress/progress-flag.test.js | 20 +++- test/serve/basic/serve-basic.test.js | 39 ++++--- test/serve/serve-variable/serve-basic.test.js | 4 +- .../serve-custom-config.test.js | 16 ++- test/stats/cli-flags/stats.test.js | 18 ++-- test/stats/config/stats.test.js | 12 ++- test/stats/watch/stats-and-watch.test.js | 37 ++++--- test/target/flag-test/target-flag.test.js | 48 ++++----- test/target/node/node-test.test.js | 18 ++-- test/unknown/unknown.test.js | 13 ++- test/utils/cli-plugin-test/plugin.test.js | 9 +- test/utils/test-utils.js | 6 +- test/utils/test-utils.test.js | 24 +++-- .../version/version-external-packages.test.js | 23 ++-- test/version/version-multi-args.test.js | 16 +-- test/version/version-single-arg.test.js | 6 +- test/watch/watch-flag.test.js | 45 ++++---- .../entry-absent/zero-config.test.js | 8 +- .../entry-present/zero-config.test.js | 12 +-- 134 files changed, 1338 insertions(+), 928 deletions(-) diff --git a/packages/webpack-cli/__tests__/serve/serve.test.js b/packages/webpack-cli/__tests__/serve/serve.test.js index edebe9bd2a5..77df7668eb2 100644 --- a/packages/webpack-cli/__tests__/serve/serve.test.js +++ b/packages/webpack-cli/__tests__/serve/serve.test.js @@ -12,16 +12,20 @@ describe('Serve', () => { } it('should run with cli', async () => { - const { stdout, stderr } = await runServe([], __dirname); + const { stderr, stdout } = await runServe([], __dirname); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { stderr, stdout } = await runServe(['--hot'], __dirname); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain('main.js'); expect(stdout).toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); }); diff --git a/packages/webpack-cli/lib/plugins/CLIPlugin.js b/packages/webpack-cli/lib/plugins/CLIPlugin.js index ec267adced0..a57a1d17846 100644 --- a/packages/webpack-cli/lib/plugins/CLIPlugin.js +++ b/packages/webpack-cli/lib/plugins/CLIPlugin.js @@ -1,6 +1,5 @@ const packageExists = require('../utils/package-exists'); const webpack = packageExists('webpack') ? require('webpack') : undefined; -const logger = require('../utils/logger'); class CLIPlugin { constructor(options) { @@ -37,11 +36,6 @@ class CLIPlugin { const progressPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin)); if (!progressPlugin) { - 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); - } - new ProgressPlugin({ profile: this.options.progress === 'profile' }).apply(compiler); } } @@ -51,37 +45,40 @@ class CLIPlugin { const getCompilationName = (compilation) => (compilation.name ? ` '${compilation.name}'` : ''); compiler.hooks.run.tap(pluginName, (compiler) => { - logger.success(`Compilation${getCompilationName(compiler)} starting...`); + this.logger.info(`Compilation${getCompilationName(compiler)} starting...`); }); compiler.hooks.watchRun.tap(pluginName, (compiler) => { const { bail, watch } = compiler.options; if (bail && watch) { - logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.'); + this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.'); } - logger.success(`Compilation${getCompilationName(compiler)} starting...`); + this.logger.info(`Compilation${getCompilationName(compiler)} starting...`); }); compiler.hooks.invalid.tap(pluginName, (filename, changeTime) => { const date = new Date(changeTime * 1000); - logger.log(`File '${filename}' was modified, changed time is ${date} (timestamp is ${changeTime})`); + this.logger.info(`File '${filename}' was modified`); + this.logger.log(`Changed time is ${date} (timestamp is ${changeTime})`); }); (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, (stats) => { - logger.success(`Compilation${getCompilationName(stats.compilation)} finished`); + this.logger.info(`Compilation${getCompilationName(stats.compilation)} finished`); process.nextTick(() => { if (compiler.watchMode) { - logger.success(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`); + this.logger.info(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`); } }); }); } apply(compiler) { + this.logger = compiler.getInfrastructureLogger('webpack-cli'); + if (this.options.progress && this.options.helpfulOutput) { this.setupProgressPlugin(compiler); } diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index b76b4016d0e..5830df34c34 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -219,6 +219,11 @@ class WebpackCLI { } } + if (typeof args.progress === 'string' && args.progress !== 'profile') { + logger.error(`'${args.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`); + process.exit(2); + } + if (Object.keys(args).length === 0 && !process.env.NODE_ENV) { return config; } diff --git a/test/analyze/analyze-flag.test.js b/test/analyze/analyze-flag.test.js index 972a00223eb..15274c16c6e 100644 --- a/test/analyze/analyze-flag.test.js +++ b/test/analyze/analyze-flag.test.js @@ -22,7 +22,8 @@ describe('--analyze flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['-c', './analyze.config.js', '--analyze']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain('Webpack Bundle Analyzer saved report to'); expect(stdout.match(/Webpack Bundle Analyzer saved report to/g)).toHaveLength(1); }); diff --git a/test/bail/bail.test.js b/test/bail/bail.test.js index c848403eb09..bddea2f0136 100644 --- a/test/bail/bail.test.js +++ b/test/bail/bail.test.js @@ -4,17 +4,21 @@ const { run, runWatch } = require('../utils/test-utils'); 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 { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'bail-webpack.config.js']); expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); 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 { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'no-bail-webpack.config.js']); expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); @@ -22,6 +26,8 @@ describe('bail and watch warning', () => { 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']); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); @@ -29,6 +35,8 @@ describe('bail and watch warning', () => { it('should not log warning without the "bail" option', async () => { const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); @@ -36,6 +44,8 @@ describe('bail and watch warning', () => { it('should not log warning without the "bail" option', async () => { const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); @@ -43,6 +53,8 @@ describe('bail and watch warning', () => { it('should log warning in watch mode', async () => { const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-webpack.config.js', '--watch']); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); @@ -50,13 +62,26 @@ describe('bail and watch warning', () => { it('should log warning in watch mode', async () => { const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-and-watch-webpack.config.js']); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); it('should log warning in case of multiple compilers', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'multi-webpack.config.js']); - + const { stderr, stdout } = await runWatch( + __dirname, + ['-c', 'multi-webpack.config.js'], + true, + "Compiler 'second' is watching files for updates...", + ); + + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compiler 'first' is watching files for updates..."); + expect(stderr).toContain("Compilation 'second' starting..."); + expect(stderr).toContain("Compilation 'second' finished"); + expect(stderr).toContain("Compiler 'second' is watching files for updates..."); expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); expect(stdout).toBeTruthy(); }); diff --git a/test/build-errors/errors.test.js b/test/build-errors/errors.test.js index 5ff6bbc617b..36d4cf0924e 100644 --- a/test/build-errors/errors.test.js +++ b/test/build-errors/errors.test.js @@ -5,18 +5,22 @@ const { resolve } = require('path'); describe('errors', () => { it('should output by default', () => { - const { stdout, exitCode } = run(__dirname); + const { exitCode, stderr, stdout } = run(__dirname); + expect(exitCode).toBe(1); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toMatch(/ERROR/); expect(stdout).toMatch(/Error: Can't resolve/); - expect(exitCode).toBe(1); }); it('should output JSON with the "json" flag', () => { - const { stdout, exitCode } = run(__dirname, ['--json']); + const { exitCode, stderr, stdout } = run(__dirname, ['--json']); - expect(() => JSON.parse(stdout)).not.toThrow(); expect(exitCode).toBe(1); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); + expect(() => JSON.parse(stdout)).not.toThrow(); const json = JSON.parse(stdout); @@ -27,10 +31,12 @@ describe('errors', () => { }); it('should store json to a file', (done) => { - const { stdout, exitCode } = run(__dirname, ['--json', 'stats.json']); + const { exitCode, stderr, stdout } = run(__dirname, ['--json', 'stats.json']); - expect(stdout).toContain('stats are successfully stored as json to stats.json'); expect(exitCode).toBe(1); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); + expect(stdout).toContain('stats are successfully stored as json to stats.json'); stat(resolve(__dirname, './stats.json'), (err, stats) => { expect(err).toBe(null); diff --git a/test/build-warnings/warnings.test.js b/test/build-warnings/warnings.test.js index 576f59a4848..6bf7c918513 100644 --- a/test/build-warnings/warnings.test.js +++ b/test/build-warnings/warnings.test.js @@ -5,18 +5,23 @@ const { resolve } = require('path'); describe('warnings', () => { it('should output by default', () => { - const { stdout, exitCode } = run(__dirname); + const { exitCode, stderr, stdout } = run(__dirname); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toMatch(/WARNING/); expect(stdout).toMatch(/Error: Can't resolve/); - expect(exitCode).toBe(0); }); it('should output JSON with the "json" flag', () => { - const { stdout, exitCode } = run(__dirname, ['--json']); + const { exitCode, stderr, stdout } = run(__dirname, ['--json']); - expect(() => JSON.parse(stdout)).not.toThrow(); expect(exitCode).toBe(0); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); + + expect(() => JSON.parse(stdout)).not.toThrow(); const json = JSON.parse(stdout); @@ -27,10 +32,12 @@ describe('warnings', () => { }); it('should store json to a file', (done) => { - const { stdout, exitCode } = run(__dirname, ['--json', 'stats.json']); + const { exitCode, stderr, stdout } = run(__dirname, ['--json', 'stats.json']); - expect(stdout).toContain('stats are successfully stored as json to stats.json'); expect(exitCode).toBe(0); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); + expect(stdout).toContain('stats are successfully stored as json to stats.json'); stat(resolve(__dirname, './stats.json'), (err, stats) => { expect(err).toBe(null); diff --git a/test/cache/cache.test.js b/test/cache/cache.test.js index c9a84017b08..7a31586a97d 100644 --- a/test/cache/cache.test.js +++ b/test/cache/cache.test.js @@ -17,6 +17,8 @@ describe('cache', () => { let { exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.config.js', '--cache-name', 'test'], false); if (isWebpack5) { + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain('No pack exists at'); expect(stderr).toContain('Stored pack'); expect(stdout).toBeTruthy(); @@ -28,6 +30,8 @@ describe('cache', () => { if (isWebpack5) { expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain('restore cache container'); expect(stderr).toContain('restore cache content metadata'); expect(stderr).toContain('restore cache content'); @@ -41,6 +45,9 @@ describe('cache', () => { let { exitCode, stderr, stdout } = run(__dirname, ['--cache-name', 'test-1'], false); if (isWebpack5) { + expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain('No pack exists at'); expect(stderr).toContain('Stored pack'); expect(stdout).toBeTruthy(); @@ -52,6 +59,8 @@ describe('cache', () => { if (isWebpack5) { expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain('restore cache container'); expect(stderr).toContain('restore cache content metadata'); expect(stderr).toContain('restore cache content'); diff --git a/test/colors/colors.test.js b/test/colors/colors.test.js index 58bd36a6dfc..2add37e2178 100644 --- a/test/colors/colors.test.js +++ b/test/colors/colors.test.js @@ -5,25 +5,27 @@ const { options: coloretteOptions } = require('colorette'); describe('colors related tests', () => { it('should output by default', () => { - const { stderr, stdout, exitCode } = run(__dirname, [], true, [], { FORCE_COLOR: true }); + const { exitCode, stderr, stdout } = run(__dirname, [], true, [], { FORCE_COLOR: true }); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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'], true, [], { FORCE_COLOR: true }); + const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose'], true, [], { FORCE_COLOR: true }); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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( + const { exitCode, stderr, stdout } = run( __dirname, ['--stats=verbose', `--config=${resolve(__dirname, './no-stats.webpack.config.js')}`], true, @@ -31,27 +33,30 @@ describe('colors related tests', () => { { FORCE_COLOR: true }, ); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'test' starting..."); + expect(stderr).toContain("Compilation 'test' finished"); 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'], true, [], { + const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--config=stats-string.webpack.config.js'], true, [], { FORCE_COLOR: true, }); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 disable colored output with --no-color', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--no-color']); + const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--no-color']); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(stdout).toContain(output); @@ -59,87 +64,95 @@ describe('colors related tests', () => { }); it('should work with the "stats" option and --color flags', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--color']); + const { exitCode, stderr, stdout } = run(__dirname, ['--stats=verbose', '--color']); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); const output = isWebpack5 ? 'successfully' : 'main.js'; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); 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'], true, [], { FORCE_COLOR: true }); + const { exitCode, stderr, stdout } = run(__dirname, ['--config=stats-string.webpack.config.js'], true, [], { FORCE_COLOR: true }); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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'], true, [], { FORCE_COLOR: true }); + const { exitCode, stderr, stdout } = run(__dirname, ['--config=stats-boolean.webpack.config.js'], true, [], { FORCE_COLOR: true }); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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'], true, [], { FORCE_COLOR: true }); + const { exitCode, stderr, stdout } = run(__dirname, ['--config=no-stats.webpack.config.js'], true, [], { FORCE_COLOR: true }); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'test' starting..."); + expect(stderr).toContain("Compilation 'test' finished"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--config=colors-true.webpack.config.js']); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { exitCode, stderr, stdout } = run(__dirname, ['--config=colors-false.webpack.config.js']); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); const output = isWebpack5 ? 'successfully' : 'main.js'; - expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(stdout).toContain(output); expect(exitCode).toBe(0); }); it('should prioritize --color over colors in config', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-false.webpack.config.js', '--color']); + const { exitCode, stderr, stdout } = run(__dirname, ['--config=colors-false.webpack.config.js', '--color']); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); const output = isWebpack5 ? 'successfully' : 'main.js'; - expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(exitCode).toBe(0); }); it('should prioratize --no-color over colors in config', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-true.webpack.config.js', '--no-color']); + const { exitCode, stderr, stdout } = run(__dirname, ['--config=colors-true.webpack.config.js', '--no-color']); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); const output = isWebpack5 ? 'successfully' : 'main.js'; - expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(stdout).toContain(output); expect(exitCode).toBe(0); }); it('should work in multicompiler mode', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config=multiple-configs.js', '--color']); + const { exitCode, stderr, stdout } = run(__dirname, ['--config=multiple-configs.js', '--color']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'first-config' starting..."); + expect(stderr).toContain("Compilation 'first-config' finished"); + expect(stderr).toContain("Compilation 'second-config' starting..."); + expect(stderr).toContain("Compilation 'second-config' finished"); if (isWebpack5) { expect(stdout).toContain(`\u001b[1mfirst-config`); diff --git a/test/config-format/coffee/coffee.test.js b/test/config-format/coffee/coffee.test.js index ccb8b46cd16..e0ab6310dfc 100644 --- a/test/config-format/coffee/coffee.test.js +++ b/test/config-format/coffee/coffee.test.js @@ -1,24 +1,22 @@ // eslint-disable-next-line node/no-unpublished-require const { run } = require('../../utils/test-utils'); -const { existsSync } = require('fs'); -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, stderr, stdout } = 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(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); it('should load coffeescript file by default', () => { - const { stderr, stdout, exitCode } = run(__dirname, [], false); + const { exitCode, stderr, stdout } = run(__dirname, [], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); - expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config-format/commonjs/commonjs.test.js b/test/config-format/commonjs/commonjs.test.js index 0a60b8ffd02..73a9232f94a 100644 --- a/test/config-format/commonjs/commonjs.test.js +++ b/test/config-format/commonjs/commonjs.test.js @@ -1,14 +1,12 @@ const { run } = require('../../utils/test-utils'); -const { existsSync } = require('fs'); -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, stderr, stdout } = 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(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config-format/typescript/typescript.test.js b/test/config-format/typescript/typescript.test.js index e7f7bcfd696..61e3945d134 100644 --- a/test/config-format/typescript/typescript.test.js +++ b/test/config-format/typescript/typescript.test.js @@ -8,7 +8,7 @@ describe('webpack cli', () => { 'should support typescript file', async () => { await runInstall(__dirname); - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.config.ts']); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.config.ts']); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); diff --git a/test/config-lookup/custom-name/custom-name.test.js b/test/config-lookup/custom-name/custom-name.test.js index 66ecfe8a93a..06e57a4bdf7 100644 --- a/test/config-lookup/custom-name/custom-name.test.js +++ b/test/config-lookup/custom-name/custom-name.test.js @@ -1,14 +1,15 @@ 'use strict'; -const { existsSync } = require('fs'); + const { resolve } = require('path'); 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, stderr, stdout } = run(__dirname, ['--config', resolve(__dirname, 'config.webpack.js')], false); + expect(exitCode).toBe(0); - expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config-lookup/dotfolder-array/dotfolder-array.test.js b/test/config-lookup/dotfolder-array/dotfolder-array.test.js index e2c305e9b4d..face65c4450 100644 --- a/test/config-lookup/dotfolder-array/dotfolder-array.test.js +++ b/test/config-lookup/dotfolder-array/dotfolder-array.test.js @@ -1,24 +1,16 @@ 'use strict'; -const { stat } = require('fs'); -const { resolve } = require('path'); + const { run } = require('../../utils/test-utils'); describe('dotfolder array config lookup', () => { - it('should find a webpack array configuration in a dotfolder', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + it('should find a webpack array configuration in a dotfolder', () => { + const { exitCode, stderr, stdout } = run(__dirname, [], false); - expect(stderr).not.toBeUndefined(); - expect(stdout).not.toBeUndefined(); expect(exitCode).toBe(0); - - stat(resolve(__dirname, './dist/dist-commonjs.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - }); - stat(resolve(__dirname, './dist/dist-amd.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stderr).toContain("Compilation 'commonjs' starting..."); + expect(stderr).toContain("Compilation 'commonjs' finished"); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config-lookup/dotfolder-single/dotfolder-single.test.js b/test/config-lookup/dotfolder-single/dotfolder-single.test.js index ee09ec2899f..ae62b1dd94f 100644 --- a/test/config-lookup/dotfolder-single/dotfolder-single.test.js +++ b/test/config-lookup/dotfolder-single/dotfolder-single.test.js @@ -1,23 +1,15 @@ 'use strict'; -const { stat } = require('fs'); -const { resolve } = require('path'); - const { run } = require('../../utils/test-utils'); describe('dotfolder single config lookup', () => { - it('should find a webpack configuration in a dotfolder', (done) => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + it('should find a webpack configuration in a dotfolder', () => { + const { exitCode, stderr, stdout } = run(__dirname, [], false); - expect(stderr).not.toBeUndefined(); - expect(stdout).not.toBeUndefined(); expect(exitCode).toBe(0); - + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).not.toContain('Module not found'); - stat(resolve(__dirname, './dist/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config-lookup/relative/basic-config.test.js b/test/config-lookup/relative/basic-config.test.js index ad568ba330d..723a904373f 100644 --- a/test/config-lookup/relative/basic-config.test.js +++ b/test/config-lookup/relative/basic-config.test.js @@ -1,22 +1,23 @@ 'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); + 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, stderr, stdout } = 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(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).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, stderr, stdout } = 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(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config-name/config-name.test.js b/test/config-name/config-name.test.js index 7f800ffdfd8..fa0cd7a554c 100644 --- a/test/config-name/config-name.test.js +++ b/test/config-name/config-name.test.js @@ -7,7 +7,8 @@ describe('--config-name flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--config-name', 'first'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); expect(stdout).toContain('first'); expect(stdout).not.toContain('second'); expect(stdout).not.toContain('third'); @@ -17,21 +18,27 @@ describe('--config-name flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--config-name', 'first', '--config-name', 'third'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'third' starting..."); + expect(stderr).toContain("Compilation 'third' finished"); expect(stdout).toContain('first'); expect(stdout).not.toContain('second'); expect(stdout).toContain('third'); }); it('should work with multiple values for --config-name and multiple configurations', () => { - const { stderr, stdout, exitCode } = run( + const { exitCode, stderr, stdout } = run( __dirname, ['-c', './function-config.js', '-c', './single-other-config.js', '--config-name', 'first', '--config-name', 'four'], false, ); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'four' starting..."); + expect(stderr).toContain("Compilation 'four' finished"); expect(stdout).toContain('first'); expect(stdout).not.toContain('second'); expect(stdout).not.toContain('third'); @@ -42,6 +49,8 @@ describe('--config-name flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--config-name', 'test'], false); expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('Configuration with the "test" name was not found.'); expect(stdout).toBeFalsy(); }); @@ -50,6 +59,8 @@ describe('--config-name flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--config-name', 'test', '-c', 'single-config.js'], false); expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('Configuration with the "test" name was not found.'); expect(stdout).toBeFalsy(); }); @@ -62,6 +73,8 @@ describe('--config-name flag', () => { ); expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('Configuration with the "test" name was not found.'); expect(stderr).toContain('Configuration with the "bar" name was not found.'); expect(stdout).toBeFalsy(); @@ -75,6 +88,8 @@ describe('--config-name flag', () => { ); expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).not.toContain('Configuration with the "first" name was not found.'); expect(stderr).toContain('Configuration with the "bar" name was not found.'); expect(stdout).toBeFalsy(); @@ -84,7 +99,8 @@ describe('--config-name flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--config', 'function-config.js', '--config-name', 'first'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); expect(stdout).toContain('first'); expect(stdout).not.toContain('second'); expect(stdout).not.toContain('third'); @@ -98,7 +114,10 @@ describe('--config-name flag', () => { ); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'third' starting..."); + expect(stderr).toContain("Compilation 'third' finished"); expect(stdout).toContain('first'); expect(stdout).not.toContain('second'); expect(stdout).toContain('third'); @@ -108,6 +127,8 @@ describe('--config-name flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--config', 'function-config.js', '--config-name', 'test'], false); expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('Configuration with the "test" name was not found.'); expect(stdout).toBeFalsy(); }); diff --git a/test/config/absent/config-absent.test.js b/test/config/absent/config-absent.test.js index 6990cdd1c04..7cfbe24a490 100644 --- a/test/config/absent/config-absent.test.js +++ b/test/config/absent/config-absent.test.js @@ -1,18 +1,18 @@ 'use strict'; -const { existsSync } = require('fs'); + const { resolve } = require('path'); const { run } = require('../../utils/test-utils'); describe('Config:', () => { it('supplied config file is absent', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + // should throw with correct exit code expect(exitCode).toBe(2); - expect(stdout).toBeFalsy(); - const configPath = resolve(__dirname, 'webpack.config.js'); // Should contain the correct error message - expect(stderr).toContain(`The specified config file doesn't exist in '${configPath}'`); - // Should not bundle - expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeFalsy(); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); + expect(stderr).toContain(`The specified config file doesn't exist in '${resolve(__dirname, 'webpack.config.js')}'`); + expect(stdout).toBeFalsy(); }); }); diff --git a/test/config/basic/basic-config.test.js b/test/config/basic/basic-config.test.js index 6372c65afa9..fa061bbdbb3 100644 --- a/test/config/basic/basic-config.test.js +++ b/test/config/basic/basic-config.test.js @@ -1,18 +1,18 @@ 'use strict'; -const { existsSync } = require('fs'); + const { resolve } = require('path'); 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( + const { exitCode, stderr, stdout } = run( __dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false, ); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); - expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); 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..95e875c044b 100644 --- a/test/config/defaults/basic-config/default-js-config.test.js +++ b/test/config/defaults/basic-config/default-js-config.test.js @@ -4,21 +4,25 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [], false); + + expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + // default entry should be used expect(stdout).toContain('./src/index.js'); // should pick up the output path from config expect(stdout).toContain('test-output'); + if (!isWebpack5) { expect(stdout).toContain('Hash'); expect(stdout).toContain('Version'); expect(stdout).toContain('Built at'); expect(stdout).toContain('Time'); } - // Should return the correct exit code - 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..6e52b89d3ab 100644 --- a/test/config/defaults/cjs-config/default-cjs-config.test.js +++ b/test/config/defaults/cjs-config/default-cjs-config.test.js @@ -4,21 +4,24 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [], false); + + expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // default entry should be used expect(stdout).toContain('./src/index.js'); // should pick up the output path from config expect(stdout).toContain('test-output'); + if (!isWebpack5) { expect(stdout).toContain('Hash'); expect(stdout).toContain('Version'); expect(stdout).toContain('Built at'); expect(stdout).toContain('Time'); } - // Should return the correct exit code - 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/dot-webpack-directory-webpackfile/multiple-location-config.test.js b/test/config/defaults/dot-webpack-directory-webpackfile/multiple-location-config.test.js index a366a0165a9..5b08b1a5b42 100644 --- a/test/config/defaults/dot-webpack-directory-webpackfile/multiple-location-config.test.js +++ b/test/config/defaults/dot-webpack-directory-webpackfile/multiple-location-config.test.js @@ -5,10 +5,13 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [], false); + expect(exitCode).toEqual(0); - expect(stdout).not.toBe(undefined); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './binary/dev.folder.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/config/defaults/dot-webpack-directory/dev-none-config.test.js b/test/config/defaults/dot-webpack-directory/dev-none-config.test.js index 6c2a8778bbd..33537daffb7 100644 --- a/test/config/defaults/dot-webpack-directory/dev-none-config.test.js +++ b/test/config/defaults/dot-webpack-directory/dev-none-config.test.js @@ -5,10 +5,13 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [], false); + expect(exitCode).toEqual(0); - expect(stdout).not.toBe(undefined); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './binary/dev.bundle.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/config/defaults/with-mode/multiple-config.test.js b/test/config/defaults/with-mode/multiple-config.test.js index 75c1ce693a7..43ebe7e0cb4 100644 --- a/test/config/defaults/with-mode/multiple-config.test.js +++ b/test/config/defaults/with-mode/multiple-config.test.js @@ -5,10 +5,13 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'development'], false); + expect(exitCode).toEqual(0); - expect(stdout).not.toBe(undefined); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './binary/dev.bundle.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/config/empty-array/empty-array.test.js b/test/config/empty-array/empty-array.test.js index 0c34474487d..a466a1c108b 100644 --- a/test/config/empty-array/empty-array.test.js +++ b/test/config/empty-array/empty-array.test.js @@ -4,9 +4,11 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config/empty-function/empty-function.test.js b/test/config/empty-function/empty-function.test.js index 0c34474487d..a466a1c108b 100644 --- a/test/config/empty-function/empty-function.test.js +++ b/test/config/empty-function/empty-function.test.js @@ -4,9 +4,11 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config/empty-promise/empty-promise.test.js b/test/config/empty-promise/empty-promise.test.js index 0c34474487d..a466a1c108b 100644 --- a/test/config/empty-promise/empty-promise.test.js +++ b/test/config/empty-promise/empty-promise.test.js @@ -4,9 +4,11 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config/empty/empty.test.js b/test/config/empty/empty.test.js index 0c34474487d..a466a1c108b 100644 --- a/test/config/empty/empty.test.js +++ b/test/config/empty/empty.test.js @@ -4,9 +4,11 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config/error/config-error.test.js b/test/config/error/config-error.test.js index d11e29e29a7..e0adeeb31d9 100644 --- a/test/config/error/config-error.test.js +++ b/test/config/error/config-error.test.js @@ -4,17 +4,19 @@ const { run } = require('../../utils/test-utils'); describe('config error', () => { it('should throw error with invalid configuration', () => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(2); expect(stderr).toContain('Invalid configuration object'); expect(stderr).toContain(`"development" | "production" | "none"`); - expect(exitCode).toBe(2); + expect(stdout).toBeFalsy(); }); it('should throw syntax error and exit with non-zero exit code', () => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'syntax-error.js')]); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'syntax-error.js')]); - expect(stderr).toContain('SyntaxError: Unexpected token'); expect(exitCode).toBe(2); + expect(stderr).toContain('SyntaxError: Unexpected token'); + expect(stdout).toBeFalsy(); }); }); diff --git a/test/config/function/functional-config.test.js b/test/config/function/functional-config.test.js index ccc79d6aec1..19b55870c1a 100644 --- a/test/config/function/functional-config.test.js +++ b/test/config/function/functional-config.test.js @@ -1,40 +1,27 @@ 'use strict'; + const { resolve } = require('path'); -const { stat } = require('fs'); 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')]); + it('should work as expected in case of single config', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--config', resolve(__dirname, 'single-webpack.config.js')]); - expect(stderr).toBeFalsy(); - expect(stdout).toContain('./src/index.js'); expect(exitCode).toBe(0); - - stat(resolve(__dirname, './bin/dist-single.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); + expect(stderr).toContain("Compilation 'single' starting..."); + expect(stderr).toContain("Compilation 'single' finished"); + expect(stdout).toContain('./src/index.js'); }); - it('should work as expected in case of multiple config', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'multi-webpack.config.js')]); + it('should work as expected in case of multiple config', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--config', resolve(__dirname, 'multi-webpack.config.js')]); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'second' starting..."); + expect(stderr).toContain("Compilation 'second' finished"); expect(stdout).toContain('first'); expect(stdout).toContain('second'); - expect(exitCode).toBe(0); - - stat(resolve(__dirname, './bin/dist-first.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); - stat(resolve(__dirname, './bin/dist-second.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); }); }); diff --git a/test/config/invalid-export/invalid-export.test.js b/test/config/invalid-export/invalid-export.test.js index e4dc82b1c18..7d081411006 100644 --- a/test/config/invalid-export/invalid-export.test.js +++ b/test/config/invalid-export/invalid-export.test.js @@ -5,6 +5,7 @@ const { run } = require('../../utils/test-utils'); describe('invalid export', () => { it('should throw error with no configuration or index file', () => { const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + expect(exitCode).toBe(2); expect(stderr).toContain(`Invalid configuration in '${resolve(__dirname, 'webpack.config.js')}'`); expect(stdout).toBeFalsy(); diff --git a/test/config/invalid-path/invalid-path.test.js b/test/config/invalid-path/invalid-path.test.js index 6600899ef06..b571740a71f 100644 --- a/test/config/invalid-path/invalid-path.test.js +++ b/test/config/invalid-path/invalid-path.test.js @@ -4,7 +4,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, 'invalid-webpack.config.js')], false); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'invalid-webpack.config.js')], false); + expect(exitCode).toBe(2); expect(stderr).toContain(`The specified config file doesn't exist in '${resolve(__dirname, 'invalid-webpack.config.js')}'`); expect(stdout).toBeFalsy(); diff --git a/test/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js b/test/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js index 6372c65afa9..fa061bbdbb3 100644 --- a/test/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js +++ b/test/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js @@ -1,18 +1,18 @@ 'use strict'; -const { existsSync } = require('fs'); + const { resolve } = require('path'); 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( + const { exitCode, stderr, stdout } = run( __dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false, ); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); - expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/config/multiple/multiple-config.test.js b/test/config/multiple/multiple-config.test.js index f29651bf8ef..097a99d9b48 100644 --- a/test/config/multiple/multiple-config.test.js +++ b/test/config/multiple/multiple-config.test.js @@ -1,20 +1,19 @@ -const { existsSync } = require('fs'); -const { resolve } = require('path'); 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 { exitCode, stderr, stdout } = run(__dirname, ['-c', 'webpack1.config.js', '-c', 'webpack2.config.js'], false); + // Should contain the correct exit code expect(exitCode).toEqual(0); + + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stderr).toContain("Compilation 'commonjs' starting..."); + expect(stderr).toContain("Compilation 'commonjs' finished"); + // Should spawn multiple compilers expect(stdout).toContain('amd:'); expect(stdout).toContain('commonjs:'); - - expect(stderr).toBeFalsy(); - - // should generate the correct output files - expect(existsSync(resolve(__dirname, './dist/dist-commonjs.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/dist-amd.js'))).toBeTruthy(); }); }); diff --git a/test/config/no-config-array/no-config-array.test.js b/test/config/no-config-array/no-config-array.test.js index ee5b81b9627..79fad1ae71e 100644 --- a/test/config/no-config-array/no-config-array.test.js +++ b/test/config/no-config-array/no-config-array.test.js @@ -5,7 +5,7 @@ const { run } = require('../../utils/test-utils'); describe('no configs in array', () => { it('is able to understand and parse a very basic configuration file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/config/no-config-object/no-config-object.test.js b/test/config/no-config-object/no-config-object.test.js index dad17223896..ba6cdfd4ab3 100644 --- a/test/config/no-config-object/no-config-object.test.js +++ b/test/config/no-config-object/no-config-object.test.js @@ -5,13 +5,15 @@ const { run } = require('../../utils/test-utils'); describe('empty config', () => { it('should work', () => { - const { stdout, stderr, exitCode } = run( + const { exitCode, stderr, stdout } = run( __dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--mode', 'development'], false, ); + expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).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..82077a230a5 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 @@ -1,15 +1,28 @@ 'use strict'; -const { existsSync } = require('fs'); +const { stat } = require('fs'); const { resolve } = require('path'); 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(); + it('is able to understand a configuration file as a function', (done) => { + const { exitCode, stderr, stdout } = 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(); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'second' starting..."); + expect(stderr).toContain("Compilation 'second' finished"); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './dist/a-dev.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + }); + + stat(resolve(__dirname, './dist/b-dev.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); }); }); diff --git a/test/config/type/array-function-with-argv/webpack.config.js b/test/config/type/array-function-with-argv/webpack.config.js index 2ced6f132a5..8c3b60bfde5 100644 --- a/test/config/type/array-function-with-argv/webpack.config.js +++ b/test/config/type/array-function-with-argv/webpack.config.js @@ -4,6 +4,7 @@ module.exports = [ const { mode } = argv; return { entry: './a.js', + name: 'first', output: { filename: mode === 'production' ? 'a-prod.js' : 'a-dev.js', }, @@ -14,6 +15,7 @@ module.exports = [ const { mode } = argv; return { entry: './b.js', + name: 'second', output: { filename: mode === 'production' ? 'b-prod.js' : 'b-dev.js', }, 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..5f1621b9c98 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 @@ -1,17 +1,28 @@ 'use strict'; -const { existsSync } = require('fs'); +const { stat } = require('fs'); const { resolve } = require('path'); 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(); + it('is able to understand a configuration file as a function', (done) => { + const { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'development'], false); + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'second' starting..."); + expect(stderr).toContain("Compilation 'second' finished"); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './dist/a-dev.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + }); - // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/a-dev.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/b-dev.js'))).toBeTruthy(); + stat(resolve(__dirname, './dist/b-dev.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); }); }); diff --git a/test/config/type/array-function-with-env/webpack.config.js b/test/config/type/array-function-with-env/webpack.config.js index 2ced6f132a5..8c3b60bfde5 100644 --- a/test/config/type/array-function-with-env/webpack.config.js +++ b/test/config/type/array-function-with-env/webpack.config.js @@ -4,6 +4,7 @@ module.exports = [ const { mode } = argv; return { entry: './a.js', + name: 'first', output: { filename: mode === 'production' ? 'a-prod.js' : 'a-dev.js', }, @@ -14,6 +15,7 @@ module.exports = [ const { mode } = argv; return { entry: './b.js', + name: 'second', output: { filename: mode === 'production' ? 'b-prod.js' : 'b-dev.js', }, diff --git a/test/config/type/array-functions/array-functions.test.js b/test/config/type/array-functions/array-functions.test.js index 920852f4aa0..fd584ec597f 100644 --- a/test/config/type/array-functions/array-functions.test.js +++ b/test/config/type/array-functions/array-functions.test.js @@ -5,10 +5,14 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'second' starting..."); + expect(stderr).toContain("Compilation 'second' finished"); + expect(stdout).toBeTruthy(); stat(resolve(__dirname, './binary/a-functor.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config/type/array-functions/webpack.config.js b/test/config/type/array-functions/webpack.config.js index a10065bb402..2d60cddbafb 100644 --- a/test/config/type/array-functions/webpack.config.js +++ b/test/config/type/array-functions/webpack.config.js @@ -2,6 +2,7 @@ module.exports = [ () => { return { entry: './a', + name: 'first', output: { path: __dirname + '/binary', filename: 'a-functor.js', @@ -11,6 +12,7 @@ module.exports = [ () => { return { entry: './b', + name: 'second', output: { path: __dirname + '/binary', filename: 'b-functor.js', diff --git a/test/config/type/array-promises/array-promises.test.js b/test/config/type/array-promises/array-promises.test.js index b9527b1f2e2..798086428b4 100644 --- a/test/config/type/array-promises/array-promises.test.js +++ b/test/config/type/array-promises/array-promises.test.js @@ -5,11 +5,14 @@ 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, stderr, stdout } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'second' starting..."); + expect(stderr).toContain("Compilation 'second' finished"); + expect(stdout).toBeTruthy(); stat(resolve(__dirname, './binary/a-promise.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config/type/array-promises/webpack.config.js b/test/config/type/array-promises/webpack.config.js index 8d7498a200f..9456d7a6bbd 100644 --- a/test/config/type/array-promises/webpack.config.js +++ b/test/config/type/array-promises/webpack.config.js @@ -3,6 +3,7 @@ module.exports = [ setTimeout(() => { resolve({ entry: './a', + name: 'first', output: { path: __dirname + '/binary', filename: 'a-promise.js', @@ -14,6 +15,7 @@ module.exports = [ setTimeout(() => { resolve({ entry: './b', + name: 'second', output: { path: __dirname + '/binary', filename: 'b-promise.js', diff --git a/test/config/type/array/array.test.js b/test/config/type/array/array.test.js index 6fa581f100d..6d7392493f2 100644 --- a/test/config/type/array/array.test.js +++ b/test/config/type/array/array.test.js @@ -5,11 +5,15 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stderr).toContain("Compilation 'commonjs' starting..."); + expect(stderr).toContain("Compilation 'commonjs' finished"); 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..22ab749ceb7 100644 --- a/test/config/type/function-array/function-array.test.js +++ b/test/config/type/function-array/function-array.test.js @@ -5,10 +5,14 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'first' starting..."); + expect(stderr).toContain("Compilation 'first' finished"); + expect(stderr).toContain("Compilation 'second' starting..."); + expect(stderr).toContain("Compilation 'second' finished"); + expect(stdout).toBeTruthy(); stat(resolve(__dirname, './binary/a-functor.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config/type/function-array/webpack.config.js b/test/config/type/function-array/webpack.config.js index 5bd0287a4bb..8e46701080a 100644 --- a/test/config/type/function-array/webpack.config.js +++ b/test/config/type/function-array/webpack.config.js @@ -1,6 +1,7 @@ module.exports = () => [ { entry: './a', + name: 'first', output: { path: __dirname + '/binary', filename: 'a-functor.js', @@ -8,6 +9,7 @@ module.exports = () => [ }, { entry: './b', + name: 'second', output: { path: __dirname + '/binary', filename: 'b-functor.js', diff --git a/test/config/type/function-async/function-async.test.js b/test/config/type/function-async/function-async.test.js index 3b8fa277d98..af7e99bf71d 100644 --- a/test/config/type/function-async/function-async.test.js +++ b/test/config/type/function-async/function-async.test.js @@ -5,10 +5,12 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); stat(resolve(__dirname, './binary/functor.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config/type/function-promise/function-promise.test.js b/test/config/type/function-promise/function-promise.test.js index ba42b3c57e5..bbd4887a9f9 100644 --- a/test/config/type/function-promise/function-promise.test.js +++ b/test/config/type/function-promise/function-promise.test.js @@ -5,10 +5,12 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); stat(resolve(__dirname, './binary/functor.js'), (err, stats) => { expect(err).toBe(null); 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 efbb0e2b33c..35b6c34527c 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 @@ -1,16 +1,22 @@ 'use strict'; -const { existsSync } = require('fs'); +const { stat } = require('fs'); const { resolve } = require('path'); 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(); + it('is able to understand a configuration file as a function', (done) => { + const { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'development'], false); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); expect(stdout).toContain("argv: { mode: 'development' }"); - // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/dev.js'))).toBeTruthy(); + + stat(resolve(__dirname, './dist/dev.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); }); }); 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..1fb719b1b05 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 @@ -5,30 +5,38 @@ const { run } = require('../../../utils/test-utils'); describe('function configuration', () => { it('should throw when env is not supplied', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--env'], false); - expect(stdout).toBeFalsy(); - expect(stderr).toBeTruthy(); + const { exitCode, stderr, stdout } = run(__dirname, ['--env'], false); + + // TODO Bug, need to fix + expect(exitCode).toBe(1); expect(stderr).toContain(`option '--env ' argument missing`); - expect(exitCode).toEqual(1); + expect(stdout).toBeFalsy(); }); + 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, stderr, stdout } = run(__dirname, ['--env', 'isProd']); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // 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, stderr, stdout } = run(__dirname, ['--env', 'isDev']); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // 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, [ + const { exitCode, stderr, stdout } = run(__dirname, [ '--env', 'environment=production', '--env', @@ -36,14 +44,17 @@ describe('function configuration', () => { '-c', 'webpack.env.config.js', ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // 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, stderr, stdout } = run(__dirname, [ '--env', 'file.name.is.this=Atsumu', '--env', @@ -51,14 +62,17 @@ describe('function configuration', () => { '-c', 'webpack.env.config.js', ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // 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, stderr, stdout } = run(__dirname, [ '--env', 'file=name=is=Eren', '--env', @@ -66,14 +80,17 @@ describe('function configuration', () => { '-c', 'webpack.env.config.js', ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // 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, [ + const { exitCode, stderr, stdout } = run(__dirname, [ '--env', 'name.=Hisoka', '--env', @@ -81,27 +98,36 @@ describe('function configuration', () => { '-c', 'webpack.env.config.js', ]); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // 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, stderr, stdout } = run(__dirname, ['--env', 'name.', '--env', 'environment=dot', '-c', 'webpack.env.config.js']); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // 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 { exitCode, stderr, stdout } = run(__dirname, ['--env', 'isDev', '--env', 'verboseStats', '--env', 'envMessage']); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); // check that the verbose env is respected expect(stdout).toContain('LOG from webpack'); + // check if the values from DefinePlugin make it to the compiled code readFile(resolve(__dirname, './bin/dev.js'), 'utf-8', (err, data) => { expect(err).toBe(null); diff --git a/test/config/type/function/function.test.js b/test/config/type/function/function.test.js index 8c782889fbf..44908c8882c 100644 --- a/test/config/type/function/function.test.js +++ b/test/config/type/function/function.test.js @@ -5,11 +5,13 @@ 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, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './binary/functor.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/config/type/promise-array/promise-array.test.js b/test/config/type/promise-array/promise-array.test.js index e83d7875038..25f76a66e52 100644 --- a/test/config/type/promise-array/promise-array.test.js +++ b/test/config/type/promise-array/promise-array.test.js @@ -5,11 +5,12 @@ 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, stderr, stdout } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stdout).toBeTruthy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); stat(resolve(__dirname, './binary/a-promise.js'), (err, stats) => { expect(err).toBe(null); diff --git a/test/config/type/promise-function/promise-function.test.js b/test/config/type/promise-function/promise-function.test.js index 2fea09bce8e..e53c9e2b0ad 100644 --- a/test/config/type/promise-function/promise-function.test.js +++ b/test/config/type/promise-function/promise-function.test.js @@ -5,11 +5,13 @@ 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, stderr, stdout } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './binary/promise.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/config/type/promise/promise.test.js b/test/config/type/promise/promise.test.js index 20a766f279b..019106ea3ec 100644 --- a/test/config/type/promise/promise.test.js +++ b/test/config/type/promise/promise.test.js @@ -5,11 +5,13 @@ 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, stderr, stdout } = run(__dirname, ['-c', './webpack.config.js'], false); - expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, './binary/promise.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/core-flags/amd-flag.test.js b/test/core-flags/amd-flag.test.js index 67c3df8ce37..2cac616a060 100644 --- a/test/core-flags/amd-flag.test.js +++ b/test/core-flags/amd-flag.test.js @@ -4,10 +4,11 @@ const { run } = require('../utils/test-utils'); describe('--no-amd flag', () => { it('should accept --no-amd', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-amd']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-amd']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('amd: false'); }); }); diff --git a/test/core-flags/bail-flag.test.js b/test/core-flags/bail-flag.test.js index 300f2841edb..27a38f18a3d 100644 --- a/test/core-flags/bail-flag.test.js +++ b/test/core-flags/bail-flag.test.js @@ -4,18 +4,20 @@ const { run } = require('../utils/test-utils'); describe('--bail flag', () => { it('should set bail to true', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--bail']); + const { exitCode, stderr, stdout } = run(__dirname, ['--bail']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('bail: true'); }); it('should set bail to false', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-bail']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-bail']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('bail: false'); }); }); diff --git a/test/core-flags/cache-flags.test.js b/test/core-flags/cache-flags.test.js index 562b0c51f5d..dbe2193f7b1 100644 --- a/test/core-flags/cache-flags.test.js +++ b/test/core-flags/cache-flags.test.js @@ -14,40 +14,44 @@ describe('cache related flags from core', () => { }); it('should be successful with --cache ', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache']); + const { exitCode, stderr, stdout } = run(__dirname, ['--cache']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`type: 'memory'`); }); it('should be successful with --no-cache ', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-cache']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-cache']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('cache: false'); }); it('should set cache.type', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem']); + const { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-directory', './test-cache-path']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); expect(stdout).toContain('test-cache-path'); }); it('should set cache.cacheLocation with --cache-cache-locations', () => { - const { stderr, stdout, exitCode } = run(__dirname, [ + const { exitCode, stderr, stdout } = run(__dirname, [ '--cache-type', 'filesystem', '--cache-cache-location', @@ -55,44 +59,49 @@ describe('cache related flags from core', () => { ]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-hash-algorithm', 'sha256']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-name', 'cli-test']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-store', 'pack']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-version', '1.1.3']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); expect(stdout).toContain(`version: '1.1.3'`); }); @@ -101,7 +110,8 @@ describe('cache related flags from core', () => { let { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); expect(stdout).toContain('buildDependencies'); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.config.js')}'`); @@ -111,32 +121,36 @@ describe('cache related flags from core', () => { ({ exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.config.js'])); expect(exitCode).toEqual(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('[cached]'); }); it('should assign cache build dependencies correctly when cache type is filesystem in config', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js']); + let { exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.cache.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler-cache' starting..."); + expect(stderr).toContain("Compilation 'compiler-cache' finished"); expect(stdout).toContain("type: 'filesystem'"); expect(stdout).toContain('buildDependencies'); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.cache.config.js')}'`); // Run again to check for cache - const newRun = run(__dirname, ['-c', './webpack.cache.config.js']); + ({ exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.cache.config.js'])); - expect(newRun.exitCode).toBe(0); - expect(newRun.stderr).toBeFalsy(); - expect(newRun.stdout).toContain('[cached]'); + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler-cache' starting..."); + expect(stderr).toContain("Compilation 'compiler-cache' finished"); + expect(stdout).toContain('[cached]'); }); it('should assign cache build dependencies with multiple configs', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js']); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); expect(stdout).toContain('buildDependencies'); // expect(stdout).toContain(`'${resolve(__dirname, 'webpack.cache.config.js')}'`); @@ -144,20 +158,22 @@ describe('cache related flags from core', () => { }); it('should assign cache build dependencies with default config', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--cache-type', 'filesystem']); + const { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('buildDependencies'); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.config.js')}'`); expect(stdout).toContain("type: 'filesystem'"); }); it('should assign cache build dependencies with merged configs', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js', '--merge']); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js', '--merge']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("type: 'filesystem'"); expect(stdout).toContain('buildDependencies'); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.cache.config.js')}'`); @@ -168,27 +184,31 @@ describe('cache related flags from core', () => { // Creating a temporary webpack config writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "development"}'); - const { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); + let { exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).not.toContain('[cached]'); // Running again should use the cache - const newRun = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); + ({ exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js'])); - expect(newRun.exitCode).toBe(0); - expect(newRun.stderr).toBeFalsy(); - expect(newRun.stdout).toContain('[cached]'); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toContain('[cached]'); // Change config to invalidate cache writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "production"}'); - const newRun2 = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); + ({ exitCode, stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js'])); unlinkSync(resolve(__dirname, './webpack.test.config.js')); - expect(newRun2.exitCode).toBe(0); - expect(newRun2).not.toContain('[cached]'); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).not.toContain('[cached]'); }); }); diff --git a/test/core-flags/context-flag.test.js b/test/core-flags/context-flag.test.js index f725b129d00..804bc6cd3d7 100644 --- a/test/core-flags/context-flag.test.js +++ b/test/core-flags/context-flag.test.js @@ -5,10 +5,12 @@ const { run, isWindows } = require('../utils/test-utils'); describe('--context flag', () => { it('should allow to set context', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--context', './']); + const { exitCode, stderr, stdout } = run(__dirname, ['--context', './']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); + if (isWindows) { const windowsPath = resolve(__dirname, './').replace(/\\/g, '\\\\'); expect(stdout).toContain(`context: '${windowsPath}'`); @@ -18,10 +20,11 @@ describe('--context flag', () => { }); it('should throw module not found error for invalid context', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--context', '/invalid-context-path']); + const { exitCode, stderr, stdout } = run(__dirname, ['--context', '/invalid-context-path']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(1); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); 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..1cc0ff6536b 100644 --- a/test/core-flags/dependencies-flag.test.js +++ b/test/core-flags/dependencies-flag.test.js @@ -4,18 +4,20 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--dependencies', 'lodash']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`dependencies: [ 'lodash' ]`); }); it('should reset dependencies option', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--dependencies-reset']); + const { exitCode, stderr, stdout } = run(__dirname, ['--dependencies-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('dependencies: []'); }); }); diff --git a/test/core-flags/devtool-flag.test.js b/test/core-flags/devtool-flag.test.js index fa37bc37b43..269396b21a2 100644 --- a/test/core-flags/devtool-flag.test.js +++ b/test/core-flags/devtool-flag.test.js @@ -7,7 +7,8 @@ describe('--devtool flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--devtool', 'source-map']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`devtool: 'source-map'`); }); @@ -15,7 +16,8 @@ describe('--devtool flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--no-devtool']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`devtool: false`); }); @@ -23,6 +25,8 @@ describe('--devtool flag', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--devtool', 'invalid']); expect(exitCode).toBe(2); + expect(stderr).not.toContain("Compilation 'compiler' starting..."); + expect(stderr).not.toContain("Compilation 'compiler' finished"); expect(stderr).toContain('Invalid configuration object'); expect(stdout).toBeFalsy(); }); diff --git a/test/core-flags/entry-reset-flag.test.js b/test/core-flags/entry-reset-flag.test.js index 545d57e6ba6..660c40bf39e 100644 --- a/test/core-flags/entry-reset-flag.test.js +++ b/test/core-flags/entry-reset-flag.test.js @@ -4,19 +4,22 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--entry-reset', '--entry', './src/entry.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('src/entry.js'); expect(stdout).not.toContain('src/main.js'); }); it('should throw error if entry is an empty array', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entry-reset']); + const { exitCode, stderr, stdout } = run(__dirname, ['--entry-reset']); - expect(stderr).toContain('Invalid configuration object'); expect(exitCode).toBe(2); + expect(stderr).not.toContain("Compilation 'compiler' starting..."); + expect(stderr).not.toContain("Compilation 'compiler' finished"); + expect(stderr).toContain('Invalid configuration object'); expect(stdout).toBeFalsy(); }); }); diff --git a/test/core-flags/experiments-flag.test.js b/test/core-flags/experiments-flag.test.js index 96b32734256..741463cfedb 100644 --- a/test/core-flags/experiments-flag.test.js +++ b/test/core-flags/experiments-flag.test.js @@ -12,18 +12,20 @@ describe('experiments option related flag', () => { const propName = hyphenToUpperCase(property); it(`should config ${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: true`); }); it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: false`); }); }); diff --git a/test/core-flags/externals-flags.test.js b/test/core-flags/externals-flags.test.js index 295ca4525aa..dd0afaaf86a 100644 --- a/test/core-flags/externals-flags.test.js +++ b/test/core-flags/externals-flags.test.js @@ -7,34 +7,38 @@ const externalsPresetsFlags = flags.filter(({ name }) => name.startsWith('extern describe('externals related flag', () => { it('should set externals properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals', './main.js']); + const { exitCode, stderr, stdout } = run(__dirname, ['--externals', './main.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`externals: [ './main.js' ]`); }); it('should set externalsType properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals', 'var']); + const { exitCode, stderr, stdout } = run(__dirname, ['--externals', 'var']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`externalsType: 'var'`); }); it('should accept --external-type values', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals-type', 'var']); + const { exitCode, stderr, stdout } = run(__dirname, ['--externals-type', 'var']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`externalsType: 'var'`); }); it('should reset externals', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--externals-reset']); + const { exitCode, stderr, stdout } = run(__dirname, ['--externals-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`externals: []`); }); @@ -44,18 +48,20 @@ describe('externals related flag', () => { const propName = hyphenToUpperCase(property); it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: true`); }); it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: false`); }); }); diff --git a/test/core-flags/infrastructure-logging.test.js b/test/core-flags/infrastructure-logging.test.js index 8bebd29d056..f04966f215b 100644 --- a/test/core-flags/infrastructure-logging.test.js +++ b/test/core-flags/infrastructure-logging.test.js @@ -4,26 +4,29 @@ const { run } = require('../utils/test-utils'); describe('infrastructure logging related flag', () => { it('should set infrastructureLogging.debug properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--infrastructure-logging-debug', 'myPlugin']); + const { exitCode, stderr, stdout } = run(__dirname, ['--infrastructure-logging-debug', 'myPlugin']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`debug: [ 'myPlugin' ]`); }); it('should reset infrastructureLogging.debug to []', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--infrastructure-logging-debug-reset']); + const { exitCode, stderr, stdout } = run(__dirname, ['--infrastructure-logging-debug-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`debug: []`); }); it('should set infrastructureLogging.level properly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--infrastructure-logging-level', 'log']); + const { exitCode, stderr, stdout } = run(__dirname, ['--infrastructure-logging-level', 'log']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`level: 'log'`); }); }); diff --git a/test/core-flags/invalid-flag.test.js b/test/core-flags/invalid-flag.test.js index da7462a851b..451a3ef6176 100644 --- a/test/core-flags/invalid-flag.test.js +++ b/test/core-flags/invalid-flag.test.js @@ -4,7 +4,7 @@ const { run } = require('../utils/test-utils'); describe('--parallelism flag', () => { it('should set parallelism to the value passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--output-script-type', 'unknown']); + const { exitCode, stderr, stdout } = run(__dirname, ['--output-script-type', 'unknown']); expect(exitCode).toBe(2); expect(stderr).toContain("Found the 'invalid-value' problem with the '--output-script-type' argument by path 'output.scriptType'"); diff --git a/test/core-flags/module-flags.test.js b/test/core-flags/module-flags.test.js index d2e813cd92b..b02f3aade81 100644 --- a/test/core-flags/module-flags.test.js +++ b/test/core-flags/module-flags.test.js @@ -9,41 +9,47 @@ describe('module config related flag', () => { moduleFlags.forEach((flag) => { // extract property name from flag name let property = flag.name.split('module-')[1]; + if (property.includes('rules-') && property !== 'rules-reset') { property = flag.name.split('rules-')[1]; } + const propName = hyphenToUpperCase(property); if (flag.type === Boolean && !flag.name.includes('module-no-parse')) { it(`should config --${flag.name} correctly`, () => { if (flag.name.includes('-reset')) { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { stderr, stdout } = run(__dirname, [`--${flag.name}`]); const option = propName.split('Reset')[0]; - expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${option}: []`); } else if (flag.name.includes('rules-')) { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain("sideEffects: 'flag'"); } else { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: true`); } }); if (!flag.name.endsWith('-reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); + if (flag.name.includes('rules-')) { expect(stdout).toContain('sideEffects: false'); } else { @@ -58,16 +64,19 @@ describe('module config related flag', () => { let { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'value']); if (flag.name === 'module-no-parse') { - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('value'); } else if (flag.name.includes('reg-exp')) { ({ stdout, stderr, exitCode } = run(__dirname, [`--${flag.name}`, '/ab?c*/'])); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: /ab?c*/`); } else if (flag.name.includes('module-rules-')) { - ({ stdout, stderr, exitCode } = run(__dirname, [`--${flag.name}`, 'javascript/auto'])); + ({ stdout } = run(__dirname, [`--${flag.name}`, 'javascript/auto'])); if (propName === 'use' || propName === 'type') { expect(stdout).toContain(`${propName}: 'javascript/auto'`); @@ -82,8 +91,10 @@ describe('module config related flag', () => { expect(stdout).toContain('rules-value'); } } else { - expect(stdout).toContain(`${propName}: 'value'`); expect(exitCode).toBe(0); + expect(stdout).toContain(`${propName}: 'value'`); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); } }); } diff --git a/test/core-flags/node-flags.test.js b/test/core-flags/node-flags.test.js index ac7f060322f..437f0c1d778 100644 --- a/test/core-flags/node-flags.test.js +++ b/test/core-flags/node-flags.test.js @@ -4,26 +4,29 @@ const { run } = require('../utils/test-utils'); describe('node option related flags', () => { it('should config node option to false', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-node']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-node']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('node: false'); }); it('should set node.filename correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--node-filename', 'mock']); + const { exitCode, stderr, stdout } = run(__dirname, ['--node-filename', 'mock']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`__filename: 'mock'`); }); it('should set node.filename correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--node-dirname', 'mock']); + const { exitCode, stderr, stdout } = run(__dirname, ['--node-dirname', 'mock']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`__dirname: 'mock'`); }); }); diff --git a/test/core-flags/optimization-flags.test.js b/test/core-flags/optimization-flags.test.js index 2af3c4b8a57..6e579f40129 100644 --- a/test/core-flags/optimization-flags.test.js +++ b/test/core-flags/optimization-flags.test.js @@ -9,11 +9,13 @@ describe('optimization config related flag', () => { optimizationFlags.forEach((flag) => { // extract property name from flag name let property = flag.name.split('optimization-')[1]; + if (flag.name.includes('split-chunks')) { property = flag.name.split('optimization-split-chunks-')[1]; } let propName = hyphenToUpperCase(property); + if (flag.name.includes('-reset')) { propName = propName.split('Reset')[0]; } @@ -24,29 +26,34 @@ describe('optimization config related flag', () => { const { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`splitChunks: false`); } else if (flag.name.includes('reset')) { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: []`); } else { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: true`); } }); if (!flag.name.includes('reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); + if (flag.name === 'optimization-split-chunks') { expect(stdout).toContain('splitChunks: false'); } else { @@ -64,37 +71,43 @@ describe('optimization config related flag', () => { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'initial']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`chunks: 'initial'`); } else if (flag.name === 'optimization-mangle-exports') { const { exitCode, stderr, stdout } = run(__dirname, ['--optimization-mangle-exports', 'size']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`mangleExports: 'size'`); } else if (flag.name === 'optimization-used-exports') { const { exitCode, stderr, stdout } = run(__dirname, ['--optimization-used-exports', 'global']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`usedExports: 'global'`); } else if (flag.name === 'optimization-split-chunks-default-size-types') { const { exitCode, stderr, stdout } = run(__dirname, ['--optimization-split-chunks-default-size-types', 'global']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`defaultSizeTypes: [Array]`); } else if (flag.name === 'optimization-side-effects') { const { exitCode, stderr, stdout } = run(__dirname, ['--optimization-side-effects', 'flag']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'flag'`); } else { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'named']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'named']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'named'`); } }); @@ -102,10 +115,12 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); + 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 88b75211943..a186374f048 100644 --- a/test/core-flags/output-flags.test.js +++ b/test/core-flags/output-flags.test.js @@ -9,9 +9,11 @@ describe('output config related flag', () => { outputFlags.forEach((flag) => { // extract property name from flag name let property = flag.name.split('output-')[1]; + if (property.includes('environment-')) { property = property.split('environment-')[1]; } + const propName = hyphenToUpperCase(property); if (flag.type === Boolean && !flag.name.includes('output-library')) { @@ -20,26 +22,34 @@ describe('output config related flag', () => { if (flag.name === 'output-module') { //'output.module: true' is only allowed when 'experiments.outputModule' is enabled - ({ stdout, exitCode } = run(__dirname, [`--${flag.name}`, '--experiments-output-module'])); + ({ exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, '--experiments-output-module'])); + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('module: true'); } else if (flag.name.includes('-reset')) { const option = propName.split('Reset')[0]; - expect(stderr).toBeFalsy(); + + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${option}: []`); } else { - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: true`); } }); if (!flag.name.endsWith('-reset')) { it(`should config --no-${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: false`); }); } @@ -47,10 +57,11 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 10`); }); } @@ -61,73 +72,85 @@ describe('output config related flag', () => { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'anonymous']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'anonymous'`); } else if (flag.name === 'output-chunk-format') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'commonjs']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'commonjs'`); } else if (flag.name === 'output-chunk-loading') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'jsonp']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'jsonp'`); } else if (flag.name === 'output-enabled-chunk-loading-types' || flag.name === 'output-enabled-wasm-loading-types') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'async-node']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: [ 'async-node' ]`); } else if (flag.name === 'output-enabled-library-type') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'amd']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'amd'`); } else if (flag.name === 'output-hash-function') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'sha256']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`hashFunction: 'sha256'`); } else if (flag.name === 'output-script-type') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'module']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'module'`); } else if (flag.name === 'output-enabled-library-types') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'var']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: [ 'var' ]`); } else if (flag.name === 'output-path') { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'test']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'test']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('test'); } else if (flag.name === 'output-worker-chunk-loading') { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'async-node']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'async-node'`); } else if (flag.name.includes('wasm')) { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'async-node']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'async-node'`); } else { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'test']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'test']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 'test'`); } }); @@ -135,7 +158,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 { exitCode, stderr, stdout } = run(__dirname, [ '--output-library-name', 'myLibrary', '--output-library-type', @@ -147,8 +170,9 @@ describe('output config related flag', () => { '--output-library-umd-named-define', ]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('myLibrary'); expect(stdout).toContain(`type: 'var'`); expect(stdout).toContain('export: [Array]'); @@ -157,10 +181,11 @@ describe('output config related flag', () => { }); it('should be succesful with --output-library-reset correctly', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--output-library-reset']); + const { exitCode, stderr, stdout } = run(__dirname, ['--output-library-reset']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('name: []'); }); } diff --git a/test/core-flags/parallelism-flag.test.js b/test/core-flags/parallelism-flag.test.js index 7f2a8bcce38..1bf2f1462db 100644 --- a/test/core-flags/parallelism-flag.test.js +++ b/test/core-flags/parallelism-flag.test.js @@ -4,18 +4,21 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--parallelism', '50']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('parallelism: 50'); }); it('should throw error for invalid parallelism value', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--parallelism', '0']); + const { exitCode, stderr, stdout } = run(__dirname, ['--parallelism', '0']); - expect(stderr).toContain('configuration.parallelism should be >= 1'); expect(exitCode).toBe(2); + expect(stderr).not.toContain("Compilation 'compiler' starting..."); + expect(stderr).not.toContain("Compilation 'compiler' finished"); + expect(stderr).toContain('configuration.parallelism should be >= 1'); expect(stdout).toBeFalsy(); }); }); diff --git a/test/core-flags/performance-flags.test.js b/test/core-flags/performance-flags.test.js index 35a3be6799c..bfaf42b2c4d 100644 --- a/test/core-flags/performance-flags.test.js +++ b/test/core-flags/performance-flags.test.js @@ -7,10 +7,11 @@ const performanceFlags = flags.filter(({ name }) => name.startsWith('performance describe('module config related flag', () => { it(`should config --performance option correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--no-performance`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--no-performance`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('performance: false'); }); @@ -21,20 +22,22 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`${propName}: 10`); }); } if (flag.type === String) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'warning']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'warning']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); 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..5c702ae77d9 100644 --- a/test/core-flags/profile-flag.test.js +++ b/test/core-flags/profile-flag.test.js @@ -4,18 +4,20 @@ const { run } = require('../utils/test-utils'); describe('--profile flag', () => { it('should set profile to true', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--profile']); + const { exitCode, stderr, stdout } = run(__dirname, ['--profile']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('profile: true'); }); it('should set profile to false', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-profile']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-profile']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); 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..831c0d97142 100644 --- a/test/core-flags/records-flag.test.js +++ b/test/core-flags/records-flag.test.js @@ -4,26 +4,29 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--records-path', './bin/records.json']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--records-input-path', './bin/records.json']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); 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 { exitCode, stderr, stdout } = run(__dirname, ['--records-output-path', './bin/records.json']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('records.json'); }); }); diff --git a/test/core-flags/resolve-flags.test.js b/test/core-flags/resolve-flags.test.js index 71e4337c5ce..719a94e9dbe 100644 --- a/test/core-flags/resolve-flags.test.js +++ b/test/core-flags/resolve-flags.test.js @@ -9,16 +9,21 @@ describe('resolve config related flags', () => { resolveFlags.forEach((flag) => { // extract property name from flag name let property = flag.name.split('resolve-')[1]; + if (flag.name.startsWith('resolve-loader')) { property = flag.name.split('resolve-loader-')[1]; } + const propName = hyphenToUpperCase(property); 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}`]); - expect(stderr).toBeFalsy(); + // expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); + if (flag.name.includes('reset')) { const option = propName.split('Reset')[0]; expect(stdout).toContain(`${option}: []`); @@ -30,21 +35,23 @@ 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 { stderr, stdout } = run(__dirname, [`--${flag.name}`, 'browser']); + + // expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); - expect(stderr).toBeFalsy(); if (propName === 'restrictions') { expect(stdout).toContain('browser'); } else { expect(stdout).toContain(`${propName}: [ 'browser' ]`); - expect(exitCode).toBe(0); } }); } if (flag.name.includes('alias-') || flag.name.includes('fallback-')) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [ + const { exitCode, stderr, stdout } = run(__dirname, [ `--resolve-alias-alias`, 'alias', '--resolve-alias-name', @@ -67,8 +74,9 @@ describe('resolve config related flags', () => { 'loader-fall-name', ]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`alias: [ { alias: 'alias', name: 'name' } ]`); expect(stdout).toContain(`aliasFields: [ 'aliasField' ]`); expect(stdout).toContain(`alias: [ { alias: 'loaderAlias', name: 'loaderName' } ]`); @@ -81,7 +89,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 { exitCode, stderr, stdout } = run(__dirname, [ '--resolve-alias-reset', '--resolve-fallback-reset', '--resolve-alias-fields-reset', @@ -90,8 +98,9 @@ describe('resolve config related flags', () => { '--resolve-loader-fallback-reset', ]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`alias: []`); expect(stdout).toContain(`aliasFields: []`); expect(stdout).toContain(`fallback: []`); diff --git a/test/core-flags/snapshot-flags.test.js b/test/core-flags/snapshot-flags.test.js index fea4e059d41..15005dd57b8 100644 --- a/test/core-flags/snapshot-flags.test.js +++ b/test/core-flags/snapshot-flags.test.js @@ -13,10 +13,12 @@ describe('snapshot config related flags', () => { if (flag.type === Boolean) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); + if (flag.name.includes('reset')) { const option = propName.split('Reset')[0]; expect(stdout).toContain(`${option}: []`); @@ -30,10 +32,11 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'test-snap-path']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); 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 ebdaeddfa71..39f57c7faf8 100644 --- a/test/core-flags/stats-flags.test.js +++ b/test/core-flags/stats-flags.test.js @@ -13,10 +13,11 @@ describe('stats config related flag', () => { if (flag.type === Boolean) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); if (flag.name.includes('reset')) { const option = propName.split('Reset')[0]; @@ -28,10 +29,11 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`stats: { ${propName}: false }`); }); } @@ -39,10 +41,11 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`stats: { ${propName}: 10 }`); }); } @@ -52,35 +55,40 @@ describe('stats config related flag', () => { it(`should config --${flag.name} correctly`, () => { if (flag.name.includes('stats-colors')) { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'u001b[32m']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'u001b[32m']); const option = flag.name.split('stats-colors-')[1]; - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`stats: { colors: { ${option}: 'u001b[32m' } }`); } else if (acceptsSingleValue.includes(propName)) { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'log']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'log']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`stats: { ${propName}: 'log' }`); } else if (flag.name === 'stats-context') { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'log']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'log']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain('log'); } else if (flag.name === 'stats-entrypoints') { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'auto']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'auto']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`stats: { ${propName}: 'auto' }`); } else { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`, 'log']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'log']); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`stats: { ${propName}: [ 'log' ] }`); } }); diff --git a/test/core-flags/watch-flags.test.js b/test/core-flags/watch-flags.test.js index 0981dd9ee3d..e1263020b8c 100644 --- a/test/core-flags/watch-flags.test.js +++ b/test/core-flags/watch-flags.test.js @@ -13,10 +13,11 @@ describe('watch config related flag', () => { if (flag.type === Boolean && flag.name !== 'watch') { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout, exitCode } = run(__dirname, [`--${flag.name}`]); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); if (flag.name.includes('reset')) { expect(stdout).toContain(`watchOptions: { ignored: [] }`); @@ -27,10 +28,11 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`watchOptions: { ${propName}: false }`); }); } @@ -38,9 +40,11 @@ describe('watch config related flag', () => { if (flag.type === Number) { it(`should config --${flag.name} correctly`, () => { - const { stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']); + const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`watchOptions: { ${propName}: 10 }`); }); } @@ -51,13 +55,15 @@ describe('watch config related flag', () => { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, '200']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`watchOptions: { ${propName}: 200 }`); } else { const { exitCode, stderr, stdout } = run(__dirname, [`--${flag.name}`, 'ignore.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain("Compilation 'compiler' starting..."); + expect(stderr).toContain("Compilation 'compiler' finished"); expect(stdout).toContain(`watchOptions: { ${propName}: [ 'ignore.js' ] }`); } }); diff --git a/test/defaults/output-defaults.test.js b/test/defaults/output-defaults.test.js index d96c9dd4c1d..88f70420a6c 100644 --- a/test/defaults/output-defaults.test.js +++ b/test/defaults/output-defaults.test.js @@ -5,12 +5,14 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--entry', './a.js', '--output-path', './binary'], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // Should print warning about config fallback expect(stdout).toContain('option has not been set, webpack will fallback to'); + stat(resolve(__dirname, './binary/main.js'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); @@ -19,7 +21,12 @@ describe('output flag defaults', () => { }); it('set default output directory on no output flag', (done) => { - run(__dirname, ['--entry', './a.js'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--entry', './a.js'], false); + + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); stat(resolve(__dirname, './dist/main.js'), (err, stats) => { expect(err).toBe(null); @@ -29,7 +36,10 @@ describe('output flag defaults', () => { }); it('throw error on empty output flag', () => { - const { stderr } = run(__dirname, ['--entry', './a.js', '--output-path'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--entry', './a.js', '--output-path'], false); + + expect(exitCode).toBe(1); expect(stderr).toContain("error: option '-o, --output-path ' argument missing"); + expect(stdout).toBeFalsy(); }); }); diff --git a/test/devtool/array/source-map-array.test.js b/test/devtool/array/source-map-array.test.js index 765ace54950..ae9bbabfe41 100644 --- a/test/devtool/array/source-map-array.test.js +++ b/test/devtool/array/source-map-array.test.js @@ -5,11 +5,14 @@ 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, stderr, stdout } = run(__dirname, [], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'commonjs' starting..."); + expect(stderr).toContain("Compilation 'commonjs' finished"); + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stdout).toBeTruthy(); readdir(resolve(__dirname, 'dist'), (err, files) => { expect(err).toBe(null); @@ -18,11 +21,14 @@ 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, stderr, stdout } = run(__dirname, ['--devtool', 'source-map', '--output-path', './binary'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'commonjs' starting..."); + expect(stderr).toContain("Compilation 'commonjs' finished"); + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stdout).toBeTruthy(); 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..0e2c379144d 100644 --- a/test/devtool/object/source-map-object.test.js +++ b/test/devtool/object/source-map-object.test.js @@ -5,11 +5,13 @@ 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, stderr, stdout } = run(__dirname, ['-c', './webpack.eval.config.js']); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stdout).toBeTruthy(); + readdir(resolve(__dirname, 'bin'), (err, files) => { expect(files.length).toBeGreaterThanOrEqual(1); expect(err).toBe(null); @@ -18,11 +20,13 @@ 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, stderr, stdout } = run(__dirname, ['-c', './webpack.source.config.js'], false); - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, 'dist/dist-amd.js.map'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); @@ -31,7 +35,17 @@ describe('source-map object', () => { }); it('should override config with source-map', (done) => { - run(__dirname, ['-c', './webpack.eval.config.js', '--devtool', 'source-map', '-o', './binary'], false); + const { exitCode, stderr, stdout } = run( + __dirname, + ['-c', './webpack.eval.config.js', '--devtool', 'source-map', '-o', './binary'], + false, + ); + + expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'amd' starting..."); + expect(stderr).toContain("Compilation 'amd' finished"); + expect(stdout).toBeTruthy(); + stat(resolve(__dirname, 'binary/dist-amd.js.map'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); 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..dba46409a83 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 @@ -1,19 +1,14 @@ 'use strict'; -const { stat } = require('fs'); -const { resolve } = require('path'); + 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); + it('should use command entry if config command existed', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['-c', '../1.js', './index.js'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain('./index.js'); - stat(resolve(__dirname, './binary/main.bundle.js'), (err, stats) => { - expect(err).toBeFalsy(); - expect(stats.isFile()).toBe(true); - done(); - }); }); }); 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..effa0df6daa 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 @@ -1,19 +1,14 @@ 'use strict'; -const { stat } = require('fs'); -const { resolve } = require('path'); + 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); + it('should use config entry if config entry existed', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['-c', '../1.js'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain('./a.js'); - stat(resolve(__dirname, './binary/index.bundle.js'), (err, stats) => { - expect(err).toBeFalsy(); - expect(stats.isFile()).toBe(true); - done(); - }); }); }); 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..18fe3c879fb 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 @@ -1,14 +1,14 @@ 'use strict'; -const { join } = require('path'); -const { existsSync } = require('fs'); + 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 { exitCode, stderr, stdout } = run(__dirname, [], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // Should contain the relevant entry expect(stdout).toContain('./src/app.js'); expect(stdout).toContain('./src/print.js'); @@ -17,11 +17,5 @@ describe('default entry and config entry all exist', () => { expect(stdout).toContain('app.bundle.js'); expect(stdout).toContain('print.bundle.js'); expect(stdout).not.toContain('index.js'); - // Should only generate the files as per the entry in config - expect(existsSync(join(__dirname, '/dist/app.bundle.js'))).toBeTruthy(); - 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..6218698926d 100644 --- a/test/entry/defaults-empty/entry-single-arg.test.js +++ b/test/entry/defaults-empty/entry-single-arg.test.js @@ -4,10 +4,11 @@ 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 { exitCode, stderr, stdout } = run(__dirname); expect(exitCode).toBe(1); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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..c4b64f094aa 100644 --- a/test/entry/defaults-index/entry-multi-args.test.js +++ b/test/entry/defaults-index/entry-multi-args.test.js @@ -1,32 +1,24 @@ 'use strict'; -const { stat } = require('fs'); -const { resolve } = require('path'); - 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); + it('finds default index file and compiles successfully', () => { + const { exitCode, stderr, stdout } = run(__dirname); - expect(stderr).not.toContain('Module not found'); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stderr).not.toContain('Module not found'); expect(stdout).toBeTruthy(); - stat(resolve(__dirname, './bin/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); }); - it('finds default index file, compiles and overrides with flags successfully', (done) => { - const { stderr } = run(__dirname, ['--output-path', 'bin']); - expect(stderr).toBeFalsy(); + it('finds default index file, compiles and overrides with flags successfully', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--output-path', 'bin']); - stat(resolve(__dirname, './bin/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/entry/flag-entry/entry-with-flag.test.js b/test/entry/flag-entry/entry-with-flag.test.js index 63798d5281f..5afc6457249 100644 --- a/test/entry/flag-entry/entry-with-flag.test.js +++ b/test/entry/flag-entry/entry-with-flag.test.js @@ -5,54 +5,37 @@ const { stat, readFile } = require('fs'); 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); + it('should resolve the path to src/index.cjs', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--entry', './src/index.cjs', '-o', './dist/'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); - - stat(resolve(__dirname, './dist/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); - readFile(resolve(__dirname, './dist/main.js'), 'utf-8', (err, data) => { - expect(err).toBe(null); - expect(data).toContain('Kazuya Miyuki'); - done(); - }); }); - it('should load ./src/a.js as entry', (done) => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entry', './src/a.js']); + it('should load ./src/a.js as entry', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--entry', './src/a.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); - - stat(resolve(__dirname, './bin/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); - readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { - expect(err).toBe(null); - expect(data).toContain('Hello from a.js'); - done(); - }); }); 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 { exitCode, stderr, stdout } = run(__dirname, ['--entry', '/src/a.js']); if (!isWebpack5) { expect(exitCode).toBe(1); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`Module not found: Error: Can't resolve`); done(); } else { expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { @@ -69,9 +52,11 @@ describe('entry flag', () => { }); it('should throw error for invalid entry file', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--entry', './src/test.js']); - expect(stdout).toContain("Module not found: Error: Can't resolve"); + const { exitCode, stderr, stdout } = run(__dirname, ['--entry', './src/test.js']); + expect(exitCode).toEqual(1); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toContain("Module not found: Error: Can't resolve"); }); }); diff --git a/test/entry/multiple-entries/multi-entries.test.js b/test/entry/multiple-entries/multi-entries.test.js index c0f1bc24d41..c7ed5aa2c13 100644 --- a/test/entry/multiple-entries/multi-entries.test.js +++ b/test/entry/multiple-entries/multi-entries.test.js @@ -6,10 +6,11 @@ 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, stderr, stdout } = run(__dirname, ['./src/a.js', './src/b.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { @@ -26,10 +27,11 @@ 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, stderr, stdout } = run(__dirname, ['--entry', './src/a.js', '--entry', './src/b.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { diff --git a/test/entry/scss/scss.test.js b/test/entry/scss/scss.test.js index 565fb273c10..21ffd3703d5 100644 --- a/test/entry/scss/scss.test.js +++ b/test/entry/scss/scss.test.js @@ -4,7 +4,9 @@ const { run, runInstall } = require('../../utils/test-utils'); 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 90c3707162d..caf8f7054b9 100644 --- a/test/env/array/array-env.test.js +++ b/test/env/array/array-env.test.js @@ -11,10 +11,11 @@ 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, stderr, stdout } = run(__dirname); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); if (isWebpack5) { diff --git a/test/env/object/object-env.test.js b/test/env/object/object-env.test.js index 2365e4c3ea8..91b889f461e 100644 --- a/test/env/object/object-env.test.js +++ b/test/env/object/object-env.test.js @@ -8,10 +8,11 @@ const { run, isWebpack5 } = require('../../utils/test-utils'); describe('env object', () => { it('is able to set env for an object', () => { - const { stderr, stdout, exitCode } = run(__dirname); + const { exitCode, stderr, stdout } = run(__dirname); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); if (isWebpack5) { diff --git a/test/error/error.test.js b/test/error/error.test.js index de30128d161..de227ce0ec6 100644 --- a/test/error/error.test.js +++ b/test/error/error.test.js @@ -4,11 +4,13 @@ const { run } = require('../utils/test-utils'); describe('error', () => { it('should log error with stacktrace', async () => { - const { stderr, stdout, exitCode } = await run(__dirname); + const { exitCode, stderr, stdout } = await run(__dirname); + expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('Error: test'); expect(stderr).toMatch(/at .+ (.+)/); expect(stdout).toBeFalsy(); - expect(exitCode).toBe(2); }); }); diff --git a/test/help/help-commands.test.js b/test/help/help-commands.test.js index 54510f68c60..89beb0bd0b4 100644 --- a/test/help/help-commands.test.js +++ b/test/help/help-commands.test.js @@ -4,7 +4,7 @@ const { run } = require('../utils/test-utils'); describe('commands help', () => { it('log help for subcommands', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['serve', 'help'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['serve', 'help'], false); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -12,7 +12,7 @@ describe('commands help', () => { }); it('log help information with subcommands as an arg', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['help', 'serve'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['help', 'serve'], false); expect(exitCode).toBe(0); expect(stdout).toContain('webpack s | serve'); @@ -20,7 +20,7 @@ describe('commands help', () => { }); it('log error for invalid command with --help flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--help', 'myCommand'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', 'myCommand'], false); expect(exitCode).toBe(2); expect(stderr).toContain("Invalid command 'myCommand'."); @@ -29,7 +29,7 @@ describe('commands help', () => { }); it('log error for invalid command with help command', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['help', 'myCommand'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['help', 'myCommand'], false); expect(exitCode).toBe(2); expect(stderr).toContain("Invalid command 'myCommand'."); @@ -38,7 +38,7 @@ describe('commands help', () => { }); it('log error for multiple commands', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help', 'init', 'info'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', 'init', 'info'], false); expect(exitCode).toBe(2); expect(stderr).toContain("You provided multiple commands or arguments - command 'init' (alias 'c'), command 'info' (alias 'i')."); diff --git a/test/help/help-flags.test.js b/test/help/help-flags.test.js index 5b463133dfd..9be66b51dda 100644 --- a/test/help/help-flags.test.js +++ b/test/help/help-flags.test.js @@ -4,7 +4,7 @@ const { run } = require('../utils/test-utils'); describe('commands help', () => { it('log error for invalid flag with --help flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--help', '--my-flag'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', '--my-flag'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`Invalid option '--my-flag'`); @@ -13,7 +13,7 @@ describe('commands help', () => { }); it('log error for invalid flag with help command', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['help', '--my-flag'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['help', '--my-flag'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`Invalid option '--my-flag'.`); @@ -22,7 +22,7 @@ describe('commands help', () => { }); it('log flag help with valid flag', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--merge'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', '--merge'], false); expect(exitCode).toBe(0); expect(stdout).not.toContain('The build tool for modern web applications'); @@ -31,7 +31,7 @@ describe('commands help', () => { }); it('log show help for --mode', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--mode', '--help'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--mode', '--help'], false); expect(exitCode).toBe(0); expect(stdout).not.toContain('The build tool for modern web applications'); @@ -41,7 +41,7 @@ describe('commands help', () => { }); it('log error for multiple flags', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--entry', '--merge'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', '--entry', '--merge'], false); expect(exitCode).toBe(2); expect(stderr).toContain( diff --git a/test/help/help-multi-args.test.js b/test/help/help-multi-args.test.js index bddba916b41..07fa8d1b744 100644 --- a/test/help/help-multi-args.test.js +++ b/test/help/help-multi-args.test.js @@ -7,23 +7,23 @@ 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 { stdout, stderr, exitCode } = run(__dirname, ['--help', `${cmd.name}`], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', `${cmd.name}`], false); expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); expect(stdout).not.toContain(helpHeader); expect(stdout).toContain(`${cmd.name}`); expect(stdout).toContain(`${cmd.usage}`); expect(stdout).toContain(`${cmd.description}`); - expect(stderr).toHaveLength(0); }); }); it('should output help for --version by taking precedence', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', '--version'], false); expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); expect(stdout).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..5ca743f87fd 100644 --- a/test/help/help-single-arg.test.js +++ b/test/help/help-single-arg.test.js @@ -6,41 +6,42 @@ const helpHeader = 'The build tool for modern web applications'; describe('single help flag', () => { it('respects --no-color flag', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help', '--no-color'], false); const usage = 'webpack [...options] | '; const example = 'webpack help --flag | '; options.enabled = true; expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); expect(stdout).not.toContain(yellow(usage)); expect(stdout).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 { exitCode, stderr, stdout } = run(__dirname, ['help'], false); expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); expect(stdout).toContain(helpHeader); - expect(stderr).toHaveLength(0); }); it('outputs help info with dashed syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--help'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--help'], false); expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); expect(stdout).toContain(helpHeader); - expect(stderr).toHaveLength(0); }); it('creates a readable snapshot', () => { const { stderr } = run(__dirname, ['--help'], false); const serializer = require('jest-serializer-ansi'); + expect.addSnapshotSerializer(serializer); - expect(stderr).toHaveLength(0); + expect(stderr).toBeFalsy(); }); }); diff --git a/test/hot/hot-flag.test.js b/test/hot/hot-flag.test.js index f888c8558dd..9ee1764d6fb 100644 --- a/test/hot/hot-flag.test.js +++ b/test/hot/hot-flag.test.js @@ -5,18 +5,21 @@ const { resolve } = require('path'); describe('--hot flag', () => { it('should be successful when --hot is passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--hot']); + const { exitCode, stderr, stdout } = run(__dirname, ['--hot']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); expect(readFileSync(resolve(__dirname, './bin/main.js')).toString()).toContain('webpackHotUpdate'); }); it('should warn when --hot and --no-hot both are passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--no-hot', '--hot']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-hot', '--hot']); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain( 'You provided both --hot and --no-hot. We will use only the last of these flags that you provided in your CLI arguments', ); diff --git a/test/info/info-help.test.js b/test/info/info-help.test.js index 46b914de71c..5511133bb4a 100644 --- a/test/info/info-help.test.js +++ b/test/info/info-help.test.js @@ -11,7 +11,7 @@ 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 { exitCode, stderr, stdout } = runInfo(['--help'], __dirname); expect(exitCode).toBe(0); expect(stdout).toContain(usageText); @@ -20,7 +20,7 @@ describe('should print help for info command', () => { }); it.skip('should work and respect the --no-color flag', () => { - const { stdout, stderr, exitCode } = runInfo(['--help', '--no-color'], __dirname); + const { exitCode, stderr, stdout } = runInfo(['--help', '--no-color'], __dirname); expect(exitCode).toBe(0); expect(stdout).not.toContain(green(usageText)); @@ -29,7 +29,7 @@ describe('should print help for info command', () => { }); it('should output all cli flags', () => { - const { stdout, stderr, exitCode } = runInfo(['--help'], __dirname); + const { exitCode, stderr, stdout } = runInfo(['--help'], __dirname); infoFlags.forEach((flag) => expect(stdout).toContain(`--${flag.name}`)); expect(stderr).toHaveLength(0); diff --git a/test/info/info-output.test.js b/test/info/info-output.test.js index 8742416eae6..715ae9528b3 100644 --- a/test/info/info-output.test.js +++ b/test/info/info-output.test.js @@ -39,7 +39,7 @@ describe('basic info usage', () => { }); it('shows a warning if an invalid value is supplied', () => { - const { stdout, stderr, exitCode } = runInfo(['--output=unknown'], __dirname); + const { exitCode, stderr, stdout } = runInfo(['--output=unknown'], __dirname); expect(exitCode).toBe(2); expect(stderr).toContain(`[webpack-cli] ${red(`'unknown' is not a valid value for output`)}`); diff --git a/test/info/info-unknown.test.js b/test/info/info-unknown.test.js index 2cd8f8c7593..2451331bf30 100644 --- a/test/info/info-unknown.test.js +++ b/test/info/info-unknown.test.js @@ -3,7 +3,7 @@ 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 { exitCode, stderr, stdout } = runInfo(['--unknown'], __dirname); expect(exitCode).toBe(2); expect(stderr).toContain(`[webpack-cli] ${red('Unknown argument: --unknown')}`); diff --git a/test/invalid-schema/invalid-schema.test.js b/test/invalid-schema/invalid-schema.test.js index 52cd44bebde..e5e42f06b77 100644 --- a/test/invalid-schema/invalid-schema.test.js +++ b/test/invalid-schema/invalid-schema.test.js @@ -6,6 +6,8 @@ describe('invalid schema', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--config', './webpack.config.mock.js']); expect(exitCode).toEqual(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('Invalid configuration object'); expect(stdout).toBeFalsy(); }); @@ -14,6 +16,8 @@ describe('invalid schema', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'Yukihira']); expect(exitCode).toEqual(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); if (isWebpack5) { expect(stderr).toContain("Found the 'invalid-value' problem with the '--mode' argument by path 'mode'"); diff --git a/test/merge/config-absent/merge-config-absent.test.js b/test/merge/config-absent/merge-config-absent.test.js index c595fb7e34c..454d5856747 100644 --- a/test/merge/config-absent/merge-config-absent.test.js +++ b/test/merge/config-absent/merge-config-absent.test.js @@ -1,22 +1,16 @@ 'use strict'; -const fs = require('fs'); -const { join } = require('path'); - const { run } = require('../../utils/test-utils'); describe('merge flag configuration', () => { it('Show warning message when the merge config is absent', () => { // 2.js doesn't exist, let's try merging with it - const { stdout, stderr } = run(__dirname, ['--config', './1.js', '--merge', './2.js'], false); + const { exitCode, stdout, stderr } = run(__dirname, ['--config', './1.js', '--merge', './2.js'], false); + expect(exitCode).toBe(2); // Since the process will exit, nothing on stdout expect(stdout).toBeFalsy(); // Confirm that the user is notified expect(stderr).toContain('At least two configurations are required for merge.'); - // Default config would be used - expect(fs.existsSync(join(__dirname, './dist/merged.js'))).toBeFalsy(); - // Since the process will exit so no compilation will be done - expect(fs.existsSync(join(__dirname, './dist/main.js'))).toBeFalsy(); }); }); diff --git a/test/merge/config/merge-config.test.js b/test/merge/config/merge-config.test.js index cf9afc5f647..55ee4d7a132 100644 --- a/test/merge/config/merge-config.test.js +++ b/test/merge/config/merge-config.test.js @@ -1,29 +1,33 @@ 'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); - 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); - expect(stdout).toContain('option has not been set, webpack will fallback to'); - expect(existsSync(resolve(__dirname, './dist/merged.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); + const { exitCode, stderr, stdout } = run(__dirname, ['--config', './1.js', '-c', './2.js', '--merge'], false); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toContain('option has not been set, webpack will fallback to'); }); + it('merges two configurations together with flag alias', () => { - const { stdout, stderr, 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(); + const { exitCode, stderr, stdout } = run(__dirname, ['--config', './1.js', '--config', './2.js', '-m'], false); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toContain('merged.js'); }); + it('fails when there are less than 2 configurations to merge', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--config', './1.js', '-m'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--config', './1.js', '-m'], false); + + expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('At least two configurations are required for merge.'); expect(stdout).toBeFalsy(); - expect(exitCode).toBe(2); }); }); 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 061595d506b..90e4abb7e02 100644 --- a/test/mode/mode-single-arg/mode-single-arg.test.js +++ b/test/mode/mode-single-arg/mode-single-arg.test.js @@ -1,49 +1,56 @@ 'use strict'; + const { run, isWebpack5 } = require('../../utils/test-utils'); describe('mode flags', () => { it('should not set mode=production by default', () => { - const { stderr, stdout, exitCode } = run(__dirname); + const { exitCode, stderr, stdout } = run(__dirname); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).not.toContain(`mode: 'production'`); expect(stdout).toContain(`The 'mode' option has not been set, webpack will fallback to 'production' for this value.`); }); it('should load a development config when --mode=development is passed', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'development']); + const { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'development']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'production']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'none']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`mode: 'none'`); }); it('should pick mode form NODE_ENV', () => { - const { stderr, stdout, exitCode } = run(__dirname, [], false, [], { NODE_ENV: 'development' }); + const { exitCode, stderr, stdout } = run(__dirname, [], false, [], { NODE_ENV: 'development' }); + expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`mode: 'development'`); }); it('should throw error when --mode=abcd is passed', () => { - const { stderr, exitCode } = run(__dirname, ['--mode', 'abcd']); + const { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'abcd']); expect(exitCode).toBe(2); @@ -53,5 +60,7 @@ describe('mode flags', () => { expect(stderr).toContain('configuration.mode should be one of these'); expect(stderr).toContain(`"development" | "production" | "none"`); } + + expect(stdout).toBeFalsy(); }); }); 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 45363bd6e92..0ff605a4386 100644 --- a/test/mode/mode-with-config/mode-with-config.test.js +++ b/test/mode/mode-with-config/mode-with-config.test.js @@ -6,10 +6,11 @@ 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, stderr, stdout } = run(__dirname, ['--mode', 'production', '--config', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); // Should generate the appropriate files @@ -37,10 +38,11 @@ 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, stderr, stdout } = run(__dirname, ['--mode', 'development', '--config', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); // Should generate the appropriate files @@ -68,10 +70,11 @@ 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, stderr, stdout } = run(__dirname, ['--mode', 'none', '--config', './webpack.config.js']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); // Should generate the appropriate files @@ -99,44 +102,50 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'production', '-c', 'webpack.config2.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'none', '-c', 'webpack.config2.js'], false, [], { NODE_ENV: 'production', }); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { exitCode, stderr, stdout } = run(__dirname, ['-c', 'webpack.config2.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { exitCode, stdout, stderr } = run(__dirname, ['-c', 'webpack.config3.js', '-c', 'webpack.config2.js']); - expect(stderr).toBeFalsy(); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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 { exitCode, stderr, stdout } = run(__dirname, ['--mode', 'none', '-c', './webpack.config3.js', '-c', './webpack.config2.js']); - expect(stderr).toBeFalsy(); expect(exitCode).toEqual(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`mode: 'none'`); expect(stdout.match(new RegExp("mode: 'none'", 'g')).length).toEqual(2); }); @@ -147,7 +156,8 @@ describe('mode flags with config', () => { }); expect(exitCode).toEqual(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`mode: 'production'`); expect(stdout).toContain(`mode: 'development'`); expect(stdout.match(new RegExp("mode: 'production'", 'g')).length).toEqual(1); diff --git a/test/name/name.test.js b/test/name/name.test.js index d615a55ee3f..f05dab56270 100644 --- a/test/name/name.test.js +++ b/test/name/name.test.js @@ -3,10 +3,11 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--name', 'config-name'], false); - expect(stderr).toBeFalsy(); expect(exitCode).toBe(0); + expect(stderr).toContain("Compilation 'config-name' starting..."); + expect(stderr).toContain("Compilation 'config-name' finished"); 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..b3f8665e4ff 100644 --- a/test/no-hot/no-hot.test.js +++ b/test/no-hot/no-hot.test.js @@ -1,15 +1,16 @@ 'use strict'; + const { run } = require('../utils/test-utils'); const { stat, readFile } = require('fs'); const { resolve } = require('path'); -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 { exitCode, stderr, stdout } = run(__dirname, ['--no-hot']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); expect(stdout).not.toContain('webpack/runtime/hot module replacement'); @@ -27,13 +28,13 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['--hot', '--no-hot']); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain( - `[webpack-cli] ${yellow( - 'You provided both --hot and --no-hot. We will use only the last of these flags that you provided in your CLI arguments', - )}`, + '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(); diff --git a/test/no-stats/with-config/main.js b/test/no-stats/with-config/main.js index 1f23f48394d..a0a157ceeef 100644 --- a/test/no-stats/with-config/main.js +++ b/test/no-stats/with-config/main.js @@ -1,4 +1 @@ -require('url'); -require('path'); - console.log('--no-stats with config test'); 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..46a49569c46 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,12 @@ const { version } = require('webpack'); describe('stats flag', () => { it(`should use stats 'detailed' as defined in webpack config`, () => { - const { stderr, stdout } = run(__dirname, []); + const { exitCode, stderr, stdout } = run(__dirname, []); + + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); - expect(stderr).toBeFalsy(); if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'detailed' }`); } else { @@ -16,9 +19,12 @@ describe('stats flag', () => { }); it(`should use --no-stats and override value in config`, () => { - const { stderr, stdout } = run(__dirname, ['--no-stats']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-stats']); + + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); - expect(stderr).toBeFalsy(); if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'none' }`); } else { diff --git a/test/no-stats/with-flags/main.js b/test/no-stats/with-flags/main.js index 0a41cfe5c6e..412593d4ef7 100644 --- a/test/no-stats/with-flags/main.js +++ b/test/no-stats/with-flags/main.js @@ -1,4 +1 @@ -require('url'); -require('path'); - console.log('--no-stats test'); diff --git a/test/no-stats/with-flags/no-stats.test.js b/test/no-stats/with-flags/no-stats.test.js index 34ae453eb69..679461326af 100644 --- a/test/no-stats/with-flags/no-stats.test.js +++ b/test/no-stats/with-flags/no-stats.test.js @@ -5,9 +5,12 @@ const { version } = require('webpack'); describe('stats flag', () => { it('should accept --no-stats as boolean', () => { - const { stderr, stdout } = run(__dirname, ['--no-stats']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-stats']); + + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); - expect(stderr).toBeFalsy(); if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'none' }`); } else { @@ -16,9 +19,13 @@ describe('stats flag', () => { }); it('should warn and use --no-stats when stats and no-stats both are provided', () => { - const { stderr, stdout } = run(__dirname, ['--stats', 'verbose', '--no-stats']); + const { exitCode, stderr, stdout } = run(__dirname, ['--stats', 'verbose', '--no-stats']); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain(`You provided both --stats and --no-stats. We will use only the last of these flags`); + if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'none' }`); } else { @@ -27,9 +34,13 @@ describe('stats flag', () => { }); it('should warn and use --stats when stats and no-stats both are provided', () => { - const { stderr, stdout } = run(__dirname, ['--no-stats', '--stats', 'verbose']); + const { exitCode, stderr, stdout } = run(__dirname, ['--no-stats', '--stats', 'verbose']); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).toContain(`You provided both --stats and --no-stats. We will use only the last of these flags`); + if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'verbose' }`); } else { diff --git a/test/node/node.test.js b/test/node/node.test.js index 077e34044a4..4a05f2432d5 100644 --- a/test/node/node.test.js +++ b/test/node/node.test.js @@ -1,5 +1,5 @@ 'use strict'; -const { stat } = require('fs'); + const { resolve } = require('path'); const { run } = require('../utils/test-utils'); @@ -7,42 +7,45 @@ const { run } = require('../utils/test-utils'); // passing via NODE_OPTIONS= in env in execa // 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, [ + it('is able to pass the options flags to node js', async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ['--output-path', './bin'], false, [ `--require=${resolve(__dirname, 'bootstrap.js')}`, `--require=${resolve(__dirname, 'bootstrap2.js')}`, ]); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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); - done(); - }); }); it('throws an error on supplying unknown flags', async () => { - const { stderr, exitCode } = await run(__dirname, [], false, ['--unknown']); + const { exitCode, stderr, stdout } = await run(__dirname, [], false, ['--unknown']); expect(exitCode).not.toBe(0); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('bad option'); + expect(stdout).toBeFalsy(); }); it('throws an error if no values were supplied with --max-old-space-size', async () => { - const { stderr, stdout, exitCode } = await run(__dirname, [], false, ['--max-old-space-size']); + const { exitCode, stderr, stdout } = await run(__dirname, [], false, ['--max-old-space-size']); expect(exitCode).not.toBe(0); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('value for flag --max-old-space-size'); expect(stdout).toBeFalsy(); }); it('throws an error if an illegal value was supplied with --max-old-space-size', async () => { - const { stderr, stdout, exitCode } = await run(__dirname, [], true, ['--max_old_space_size=1024a']); + const { exitCode, stderr, stdout } = await run(__dirname, [], true, ['--max_old_space_size=1024a']); expect(exitCode).not.toBe(0); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain('Error: illegal value for flag --max_old_space_size=1024a of type size_t'); expect(stdout).toBeFalsy(); }); diff --git a/test/optimization/optimization.test.js b/test/optimization/optimization.test.js index 74e97f03e7f..f30060e850e 100644 --- a/test/optimization/optimization.test.js +++ b/test/optimization/optimization.test.js @@ -1,22 +1,21 @@ -const fs = require('fs'); -const { join } = require('path'); -const { version } = require('webpack'); -const { run } = require('../utils/test-utils'); +const { run, isWebpack5 } = require('../utils/test-utils'); describe('optimization option in config', () => { it('should work with mangleExports disabled', () => { - const { stdout, stderr, exitCode } = run(__dirname, [], false); + const { exitCode, stderr, stdout } = run(__dirname, [], false); + // Should throw when webpack is less than 5 - if (!version.startsWith('5')) { - expect(stderr).toContain("configuration.optimization has an unknown property 'mangleExports'"); - expect(exitCode).toBe(2); - } else { - // Should apply the provided optimization to the compiler - expect(stdout).toContain('mangleExports: false'); - // check that the output file exists - expect(fs.existsSync(join(__dirname, '/dist/main.js'))).toBeTruthy(); - expect(stderr).toBeFalsy(); + if (isWebpack5) { expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toContain('mangleExports: false'); + } else { + expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); + expect(stderr).toContain("configuration.optimization has an unknown property 'mangleExports'"); + expect(stdout).toBeFalsy(); } }); }); diff --git a/test/output/named-bundles/output-named-bundles.test.js b/test/output/named-bundles/output-named-bundles.test.js index 0743bb84f67..ecb694c74a3 100644 --- a/test/output/named-bundles/output-named-bundles.test.js +++ b/test/output/named-bundles/output-named-bundles.test.js @@ -1,62 +1,62 @@ 'use strict'; -const { statSync } = require('fs'); + const { resolve } = require('path'); 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, stderr, stdout } = 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); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); 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, stderr, stdout } = 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); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); it('should create multiple bundles with an overriding flag', () => { - const { stderr, exitCode } = run( + const { exitCode, stderr, stdout } = 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); - stats = statSync(resolve(__dirname, './bin/c.bundle.js')); - expect(stats.isFile()).toBe(true); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); it('should successfully compile multiple entries', () => { - const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.multiple.config.js')], false); + const { exitCode, stderr, stdout } = 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); - stats = statSync(resolve(__dirname, './bin/c.bundle.js')); - expect(stats.isFile()).toBe(true); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); it('should output file in bin directory using default webpack config with warning for empty output value', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--output-path'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--output-path'], false); - expect(stderr).toEqual("error: option '-o, --output-path ' argument missing"); expect(exitCode).toEqual(1); + expect(stderr).toEqual("error: option '-o, --output-path ' argument missing"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/prefetch/prefetch.test.js b/test/prefetch/prefetch.test.js index dbeaf4f7138..30def73ad77 100644 --- a/test/prefetch/prefetch.test.js +++ b/test/prefetch/prefetch.test.js @@ -12,7 +12,8 @@ describe('prefetch', () => { const { exitCode, stderr, stdout } = run(__dirname, ['--prefetch', './src/p.js', '--mode', 'development'], false); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); const content = fs.readFileSync(join(__dirname, '/dist/main.js'), 'utf-8'); @@ -21,20 +22,22 @@ describe('prefetch', () => { }); it('should log error when the prefetched file is absent', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--prefetch', './src/somefile.js'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--prefetch', './src/somefile.js'], false); + + expect(exitCode).toBe(1); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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 log error when flag value is not supplied', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--prefetch'], false); - // Should contain the error message + const { exitCode, stderr, stdout } = run(__dirname, ['--prefetch'], false); + + expect(exitCode).toBe(1); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); 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..6a5a8d1dd39 100644 --- a/test/progress/progress-flag.test.js +++ b/test/progress/progress-flag.test.js @@ -4,40 +4,50 @@ const { run, isWebpack5 } = require('../utils/test-utils'); describe('progress flag', () => { it('should show progress', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--progress']); + const { exitCode, stderr, stdout } = run(__dirname, ['--progress']); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).not.toMatch(/\[webpack\.Progress] \d+ ms setup/); expect(stderr).toContain('[webpack.Progress] 100%'); expect(stdout).toContain('main.js'); }); it('should support the "profile" value', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--progress=profile']); + const { exitCode, stderr, stdout } = run(__dirname, ['--progress=profile']); expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + if (isWebpack5) { expect(stderr).toMatch(/\[webpack\.Progress] \d+ ms setup/); } + expect(stderr).toContain('[webpack.Progress] 100%'); expect(stdout).toContain('main.js'); }); it('should not support invalid value', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--progress=unknown']); + const { exitCode, stderr, stdout } = run(__dirname, ['--progress=unknown']); expect(exitCode).toBe(2); + expect(stderr).not.toContain('Compilation starting...'); + expect(stderr).not.toContain('Compilation finished'); expect(stderr).toContain(`'unknown' is an invalid value for the --progress option. Only 'profile' is allowed.`); expect(stdout).toBeFalsy(); }); it('should not add duplicate plugins', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['-c', 'webpack.progress.config.js', '--progress']); + const { exitCode, stderr, stdout } = run(__dirname, ['-c', 'webpack.progress.config.js', '--progress']); expect(exitCode).toEqual(0); - expect(stdout.match(/ProgressPlugin/g)).toHaveLength(1); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stderr).not.toMatch(/\[webpack\.Progress] \d+ ms setup/); expect(stderr).toContain('[webpack.Progress] 100%'); expect(stdout).toContain('main.js'); + 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..64c112648f4 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -1,6 +1,5 @@ 'use strict'; -const { yellow, options } = require('colorette'); const path = require('path'); const getPort = require('get-port'); const { runServe, isDevServer4 } = require('../../utils/test-utils'); @@ -29,58 +28,72 @@ describe('basic serve usage', () => { it('should respect the --no-color flag', async () => { const { stdout, stderr } = await runServe(['--help', '--no-color'], __dirname); - options.enabled = true; - expect(stdout).not.toContain(yellow(usageText)); + + expect(stderr).toBeFalsy(); + expect(stdout).toContain(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); + + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compilation starting...'); 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); + + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compilation starting...'); 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); + + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compilation starting...'); 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); + + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compilation starting...'); 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); + expect(stdout).toContain('main.js'); + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compilation starting...'); expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stderr).toHaveLength(0); }); it('uses hot flag and progress flag', async () => { const { stdout, stderr } = await runServe(['--port', port, '--hot', '--progress'], testPath); + + expect(stderr).toContain('webpack.Progress'); + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compilation starting...'); expect(stdout).toContain('main.js'); expect(stdout).toContain('HotModuleReplacementPlugin'); - // progress flag makes use of stderr - expect(stderr).not.toHaveLength(0); }); it('throws error on unknown flag', async () => { - const { stdout, stderr } = await runServe(['--port', port, '--unknown-flag'], testPath); - expect(stdout).toHaveLength(0); + const { exitCode, stdout, stderr } = await runServe(['--port', port, '--unknown-flag'], testPath); + + expect(exitCode).toBe(2); expect(stderr).toContain('Unknown argument: --unknown-flag'); + expect(stdout).toBeFalsy(); }); }); diff --git a/test/serve/serve-variable/serve-basic.test.js b/test/serve/serve-variable/serve-basic.test.js index d8e6bc12c77..7bab5984b4d 100644 --- a/test/serve/serve-variable/serve-basic.test.js +++ b/test/serve/serve-variable/serve-basic.test.js @@ -25,9 +25,11 @@ describe('serve variable', () => { it('compiles without flags and export variable', async () => { const { stdout, stderr } = await runServe(['--port', port], testPath); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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..bac94e4accf 100644 --- a/test/serve/with-custom-port/serve-custom-config.test.js +++ b/test/serve/with-custom-port/serve-custom-config.test.js @@ -25,43 +25,51 @@ describe('serve with devServer in config', () => { it('Should pick up the host and port from config', async () => { const { stdout, stderr } = await runServe([], testPath); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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 ee612408123..21e5a4566ff 100644 --- a/test/stats/cli-flags/stats.test.js +++ b/test/stats/cli-flags/stats.test.js @@ -12,10 +12,11 @@ if (isWebpack5) { describe('stats flag', () => { for (const preset of presets) { it(`should accept --stats "${preset}"`, () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats', `${preset}`]); + const { exitCode, stderr, stdout } = run(__dirname, ['--stats', `${preset}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); if (isWebpack5) { expect(stdout).toContain(`stats: { preset: '${preset}' }`); @@ -26,10 +27,12 @@ describe('stats flag', () => { } it('should accept stats as boolean', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats']); + const { exitCode, stderr, stdout } = run(__dirname, ['--stats']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + if (isWebpack5) { expect(stdout).toContain(`stats: { preset: 'normal' }`); } else { @@ -37,11 +40,10 @@ describe('stats flag', () => { } }); - it('should warn when an unknown flag stats value is passed', () => { - const { exitCode, stderr } = run(__dirname, ['--stats', 'foo']); + it('should log error when an unknown flag stats value is passed', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--stats', 'foo']); expect(exitCode).toEqual(2); - expect(stderr).toBeTruthy(); if (isWebpack5) { expect(stderr).toContain("Found the 'invalid-value' problem with the '--stats' argument by path 'stats'"); @@ -49,5 +51,7 @@ describe('stats flag', () => { expect(stderr).toContain('* configuration.stats should be one of these:'); expect(stderr).toContain('"none" | "errors-only" | "minimal" | "normal" | "detailed" | "verbose" | "errors-warnings"'); } + + expect(stdout).toBeFalsy(); }); }); diff --git a/test/stats/config/stats.test.js b/test/stats/config/stats.test.js index 84c77b6e3ca..932e57f56ab 100644 --- a/test/stats/config/stats.test.js +++ b/test/stats/config/stats.test.js @@ -6,10 +6,12 @@ const { version } = require('webpack'); describe('stats flag with config', () => { it('should compile without stats flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, []); + const { exitCode, stderr, stdout } = run(__dirname, []); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'normal' }`); } else { @@ -17,10 +19,12 @@ describe('stats flag with config', () => { } }); it('should compile with stats flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--stats', 'errors-warnings']); + const { exitCode, stderr, stdout } = run(__dirname, ['--stats', 'errors-warnings']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + if (version.startsWith('5')) { expect(stdout).toContain(`stats: { preset: 'errors-warnings' }`); } else { diff --git a/test/stats/watch/stats-and-watch.test.js b/test/stats/watch/stats-and-watch.test.js index 4c308975371..86ef24df20e 100644 --- a/test/stats/watch/stats-and-watch.test.js +++ b/test/stats/watch/stats-and-watch.test.js @@ -1,35 +1,34 @@ 'use strict'; -const { runWatch, isWebpack5 } = require('../../utils/test-utils'); +const { runWatch } = require('../../utils/test-utils'); + +// const output = isWebpack5 ? 'successfully' : 'main.js'; describe('stats and watch', () => { it('should not log stats with the "none" value from the configuration', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', './webpack.config.js', '--color']); + const { stderr } = await runWatch(__dirname, ['-c', './webpack.config.js', '--color']); - expect(stdout).toContain('[webpack-cli] Compilation starting...'); - expect(stdout).toContain('[webpack-cli] Compilation finished'); - expect(stdout).toContain('[webpack-cli] Compiler is watching files for updates...'); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compiler is watching files for updates...'); + // expect(stdout).toContain(output); }); it('should not log stats with the "none" value from the configuration and multi compiler mode', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', './multi-webpack.config.js', '--color']); + const { stderr } = await runWatch(__dirname, ['-c', './multi-webpack.config.js', '--color']); - expect(stdout).toContain('[webpack-cli] Compilation starting...'); - expect(stdout).toContain('[webpack-cli] Compilation finished'); - expect(stdout).toContain('[webpack-cli] Compiler is watching files for updates...'); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compiler is watching files for updates...'); + // expect(stdout).toContain(output); }); it('should log stats with the "normal" value in arguments', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', './webpack.config.js', '--stats', 'normal', '--color']); - - const output = isWebpack5 ? 'successfully' : 'main.js'; + const { stderr } = await runWatch(__dirname, ['-c', './webpack.config.js', '--stats', 'normal', '--color']); - expect(stdout).toContain('[webpack-cli] Compilation starting...'); - expect(stdout).toContain('[webpack-cli] Compilation finished'); - expect(stdout).toContain('[webpack-cli] Compiler is watching files for updates...'); - expect(stdout).toContain(output); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stderr).toContain('Compiler is watching files for updates...'); + // expect(stdout).toContain(output); }); }); diff --git a/test/target/flag-test/target-flag.test.js b/test/target/flag-test/target-flag.test.js index cf7b7f6cf37..4df47f8edcf 100644 --- a/test/target/flag-test/target-flag.test.js +++ b/test/target/flag-test/target-flag.test.js @@ -1,79 +1,75 @@ 'use strict'; -const { stat } = require('fs'); -const { resolve } = require('path'); + const { run, isWebpack5 } = require('../../utils/test-utils'); const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload']; describe('--target flag', () => { targetValues.forEach((val) => { - it(`should accept ${val} with --target flag`, (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['--target', `${val}`]); + it(`should accept ${val} with --target flag`, () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--target', `${val}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + if (isWebpack5) { expect(stdout).toContain(`target: [ '${val}' ]`); } else { expect(stdout).toContain(`target: '${val}'`); } - - stat(resolve(__dirname, 'bin/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); }); - it(`should accept ${val} with -t alias`, (done) => { - const { stdout, stderr, exitCode } = run(__dirname, ['-t', `${val}`]); + it(`should accept ${val} with -t alias`, () => { + const { exitCode, stderr, stdout } = run(__dirname, ['-t', `${val}`]); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + if (isWebpack5) { expect(stdout).toContain(`target: [ '${val}' ]`); } else { expect(stdout).toContain(`target: '${val}'`); } - - stat(resolve(__dirname, 'bin/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); }); }); it(`should throw error with invalid value for --target`, () => { - const { stderr, exitCode } = run(__dirname, ['--target', 'invalid']); + const { exitCode, stderr, stdout } = run(__dirname, ['--target', 'invalid']); expect(exitCode).toBe(2); + if (isWebpack5) { expect(stderr).toContain(`Unknown target 'invalid'`); } else { expect(stderr).toContain('Invalid configuration object'); } + + expect(stdout).toBeFalsy(); }); if (isWebpack5) { it('should allow multiple targets', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--target', 'node', '--target', 'async-node']); + const { exitCode, stderr, stdout } = run(__dirname, ['--target', 'node', '--target', 'async-node']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`target: [ 'node', 'async-node' ]`); }); it('should reset target from node to async-node with --target-reset', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--target-reset', '--target', 'async-node']); + const { exitCode, stderr, stdout } = run(__dirname, ['--target-reset', '--target', 'async-node']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`target: [ 'async-node' ]`); }); it('should throw error if target is an empty array', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--target-reset']); + const { exitCode, stderr, stdout } = run(__dirname, ['--target-reset']); expect(exitCode).toBe(2); expect(stderr).toContain('Invalid configuration object'); diff --git a/test/target/node/node-test.test.js b/test/target/node/node-test.test.js index f6719d9629e..0fdd23b8a77 100644 --- a/test/target/node/node-test.test.js +++ b/test/target/node/node-test.test.js @@ -1,16 +1,14 @@ 'use strict'; -const { stat } = require('fs'); -const { resolve } = require('path'); + 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(); - stat(resolve(__dirname, 'bin/main.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); + it('should emit the correct code', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['-c', './webpack.config.js']); + + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + expect(stdout).toBeTruthy(); }); }); diff --git a/test/unknown/unknown.test.js b/test/unknown/unknown.test.js index 9e6ed7bb5e3..dd5a8ea78b3 100644 --- a/test/unknown/unknown.test.js +++ b/test/unknown/unknown.test.js @@ -2,36 +2,39 @@ const { run, isWebpack5 } = require('../utils/test-utils'); describe('unknown behaviour', () => { it('should log error if an unknown flag is passed in', () => { - const { stderr, exitCode } = run(__dirname, ['--unknown']); + const { exitCode, stderr, stdout } = run(__dirname, ['--unknown']); expect(exitCode).toBe(2); expect(stderr).toContain("Unknown argument: '--unknown'"); + expect(stdout).toBeFalsy(); }); it('should log error and respect --color flag', () => { - const { stderr, exitCode } = run(__dirname, ['--unknown', '--color']); + const { exitCode, stderr, stdout } = run(__dirname, ['--unknown', '--color']); expect(exitCode).toBe(2); expect(stderr).toContain(`[webpack-cli] \u001b[31mUnknown argument: '--unknown'`); + expect(stdout).toBeFalsy(); }); it('should log error for unknown flag and respect --no-color', () => { - const { stderr, exitCode } = run(__dirname, ['--unknown', '--no-color']); + const { exitCode, stderr, stdout } = run(__dirname, ['--unknown', '--no-color']); expect(exitCode).toBe(2); expect(stderr).not.toContain(`[webpack-cli] \u001b[31mUnknown argument: '--unknown'`); expect(stderr).toContain("Unknown argument: '--unknown'"); + expect(stdout).toBeFalsy(); }); it('suggests the closest match to an unknown flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--entyr', './a.js']); + const { exitCode, stderr, stdout } = run(__dirname, ['--entyr', './a.js']); expect(exitCode).toBe(2); expect(stderr).toContain("Unknown argument: '--entyr'"); expect(stdout).toContain("Did you mean '--entry'?"); }); it('suggests the closest match to an unknown flag #2', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['--output-fileneme', '[name].js']); + const { exitCode, stderr, stdout } = run(__dirname, ['--output-fileneme', '[name].js']); expect(exitCode).toBe(2); expect(stderr).toContain("Unknown argument: '--output-fileneme'"); diff --git a/test/utils/cli-plugin-test/plugin.test.js b/test/utils/cli-plugin-test/plugin.test.js index 14e4810a3fa..9473f01064f 100644 --- a/test/utils/cli-plugin-test/plugin.test.js +++ b/test/utils/cli-plugin-test/plugin.test.js @@ -4,12 +4,17 @@ 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 { exitCode, stderr, stdout } = run(__dirname); + + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toContain(`target: 'node'`); + if (typeof cli !== 'undefined') { expect(stdout).toContain(`alias: { alias: [ 'alias1', 'alias2' ] }`); } + expect(stdout).toContain(` WebpackCLITestPlugin { opts: [Array], showAll: true }`); }); }); diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js index 4b3a50091af..7b57ff9db22 100644 --- a/test/utils/test-utils.js +++ b/test/utils/test-utils.js @@ -51,7 +51,7 @@ const run = (testCase, args = [], setOutput = true, nodeOptions = [], env) => { return result; }; -const runWatch = (testCase, args = [], setOutput = true, outputKillStr = 'watching files for updates...') => { +const runWatch = (testCase, args = [], setOutput = true, outputKillStr = 'Compiler is watching files for updates...') => { const cwd = path.resolve(testCase); const outputPath = path.resolve(testCase, 'bin'); @@ -64,7 +64,7 @@ const runWatch = (testCase, args = [], setOutput = true, outputKillStr = 'watchi stdio: 'pipe', }); - proc.stdout.pipe( + proc.stderr.pipe( new Writable({ write(chunk, encoding, callback) { const output = chunk.toString('utf8'); @@ -241,7 +241,7 @@ const runInstall = async (cwd) => { }; const runServe = (args, testPath) => { - return runWatch(testPath, ['serve'].concat(args), false, 'main'); + return runWatch(testPath, ['serve'].concat(args), false); }; const runInfo = (args, testPath) => { diff --git a/test/utils/test-utils.test.js b/test/utils/test-utils.test.js index a7e19b7b970..daff27b08e9 100644 --- a/test/utils/test-utils.test.js +++ b/test/utils/test-utils.test.js @@ -17,8 +17,10 @@ describe('appendFile', () => { afterEach(() => { unlinkSync(junkFilePath); }); + it('should append data to file if file exists', () => { appendDataIfFileExists(__dirname, junkFile, junkComment); + const actualData = readFileSync(junkFilePath).toString(); expect(actualData).toBe(initialJunkData + junkComment); @@ -35,21 +37,23 @@ describe('appendFile', () => { describe('run function', () => { it('should work correctly by default', () => { const { command, stdout, stderr } = run(__dirname); + + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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); + // execution command contains info command expect(command).toContain('info'); expect(command).toContain('--output markdown'); - // Contains info command output expect(stdout).toContain('System:'); expect(stdout).toContain('Node'); @@ -60,31 +64,35 @@ describe('run function', () => { it('uses default output when output param is false', () => { const { stdout, stderr, command } = run(__dirname, [], false); + // execution command contains info command expect(command).not.toContain('--output-path'); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); }); }); describe('runAndGetWatchProc function', () => { it('should work correctly by default', async () => { const { command, stdout, stderr } = 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(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); 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); + // execution command contains info command expect(command).toContain('info'); expect(command).toContain('--output markdown'); - // Contains info command output expect(stdout).toContain('System:'); expect(stdout).toContain('Node'); @@ -95,14 +103,17 @@ describe('runAndGetWatchProc function', () => { it('uses default output when output param is false', async () => { const { stdout, stderr, command } = await runAndGetWatchProc(__dirname, [], false); + // execution command contains info command expect(command).not.toContain('--output-path'); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); - expect(stderr).toBeFalsy(); }); it('writes to stdin', async () => { const { stdout } = await runAndGetWatchProc(__dirname, ['init'], false, 'n'); + expect(stdout).toContain('Which will be your application entry point?'); }); }); @@ -110,6 +121,7 @@ describe('runAndGetWatchProc function', () => { describe('hyphenToUpperCase function', () => { it('changes value from hypen to upperCase', () => { const result = hyphenToUpperCase('test-value'); + expect(result).toEqual('testValue'); }); }); diff --git a/test/version/version-external-packages.test.js b/test/version/version-external-packages.test.js index 47c21ab9be7..f149527f1fd 100644 --- a/test/version/version-external-packages.test.js +++ b/test/version/version-external-packages.test.js @@ -11,7 +11,7 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['init', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(initPkgJSON.version); @@ -20,7 +20,7 @@ describe('version flag with external packages', () => { }); it('outputs version with the alias c for init', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['c', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['c', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(initPkgJSON.version); @@ -29,7 +29,7 @@ describe('version flag with external packages', () => { }); it('outputs version with info', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['info', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['info', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(infoPkgJSON.version); @@ -38,7 +38,7 @@ describe('version flag with external packages', () => { }); it('outputs version with serve', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['serve', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['serve', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(servePkgJSON.version); @@ -47,7 +47,7 @@ describe('version flag with external packages', () => { }); it('outputs version with migrate', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['migrate', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['migrate', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(migratePkgJSON.version); @@ -56,7 +56,7 @@ describe('version flag with external packages', () => { }); it('outputs version with plugin', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['plugin', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['plugin', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pluginPkgJSON.version); @@ -65,7 +65,7 @@ describe('version flag with external packages', () => { }); it('outputs version with loader', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['loader', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['loader', '--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(loaderPkgJSON.version); @@ -74,16 +74,17 @@ describe('version flag with external packages', () => { }); it(' should throw error for multiple commands', () => { - const { stderr, exitCode } = run(__dirname, ['init', 'migrate', '--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['init', 'migrate', '--version'], false); expect(exitCode).toBe(2); expect(stderr).toContain( "You provided multiple commands - 'init' (alias 'c'), 'migrate' (alias 'm'). Please use only one command at a time.", ); + expect(stdout).toBeFalsy(); }); it(' should throw error if invalid argument is present with --version flag', () => { - const { stderr, stdout, exitCode } = run(__dirname, ['init', 'abc', '--version', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['init', 'abc', '--version', '--no-color'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`[webpack-cli] Invalid command 'abc'`); @@ -92,7 +93,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', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['init', 'abc', 'version', '--no-color'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`[webpack-cli] Invalid command 'abc'`); @@ -101,7 +102,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', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['init', 'abc', '-v', '--no-color'], false); expect(exitCode).toBe(2); expect(stderr).toContain(`[webpack-cli] Invalid command 'abc'`); diff --git a/test/version/version-multi-args.test.js b/test/version/version-multi-args.test.js index 1051f44ee45..f5de6205cb6 100644 --- a/test/version/version-multi-args.test.js +++ b/test/version/version-multi-args.test.js @@ -5,7 +5,7 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['version', 'help'], false); expect(exitCode).toBe(0); expect(stdout).not.toContain(pkgJSON.version); @@ -14,7 +14,7 @@ describe('version flag with multiple arguments', () => { }); it('does not output version with help dashed', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['version', '--help'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['version', '--help'], false); expect(exitCode).toBe(0); expect(stdout).not.toContain(pkgJSON.version); @@ -23,7 +23,7 @@ describe('version flag with multiple arguments', () => { }); it('throws error if invalid command is passed with version command', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['version', 'abc', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['version', 'abc', '--no-color'], false); expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); @@ -32,7 +32,7 @@ describe('version flag with multiple arguments', () => { }); it('throws error if invalid option is passed with version command', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['version', '--abc', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['version', '--abc', '--no-color'], false); expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); @@ -41,7 +41,7 @@ describe('version flag with multiple arguments', () => { }); it('throws error if invalid command is passed with --version flag', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--version', 'abc', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--version', 'abc', '--no-color'], false); expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); @@ -50,7 +50,7 @@ describe('version flag with multiple arguments', () => { }); it('throws error if invalid option is passed with --version flag', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--version', '--abc', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--version', '--abc', '--no-color'], false); expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); @@ -59,7 +59,7 @@ describe('version flag with multiple arguments', () => { }); it('throws error if invalid command is passed with -v alias', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-v', 'abc', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['-v', 'abc', '--no-color'], false); expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); @@ -68,7 +68,7 @@ describe('version flag with multiple arguments', () => { }); it('throws error if invalid option is passed with -v alias', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-v', '--abc', '--no-color'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['-v', '--abc', '--no-color'], false); expect(exitCode).toBe(2); expect(stdout).not.toContain(pkgJSON.version); diff --git a/test/version/version-single-arg.test.js b/test/version/version-single-arg.test.js index 72a6114b8a3..8516f802bb9 100644 --- a/test/version/version-single-arg.test.js +++ b/test/version/version-single-arg.test.js @@ -5,7 +5,7 @@ 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 { exitCode, stderr, stdout } = run(__dirname, ['version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pkgJSON.version); @@ -13,7 +13,7 @@ describe('single version flag', () => { }); it('outputs versions with dashed syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--version'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['--version'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pkgJSON.version); @@ -21,7 +21,7 @@ describe('single version flag', () => { }); it('outputs versions with alias syntax', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['-v'], false); + const { exitCode, stderr, stdout } = run(__dirname, ['-v'], false); expect(exitCode).toBe(0); expect(stdout).toContain(pkgJSON.version); diff --git a/test/watch/watch-flag.test.js b/test/watch/watch-flag.test.js index f95b54759b7..caa2f970530 100644 --- a/test/watch/watch-flag.test.js +++ b/test/watch/watch-flag.test.js @@ -13,33 +13,20 @@ describe('--watch flag', () => { const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './watch.config.js', '--no-watch']); expect(exitCode).toBe(0); - expect(stderr).toBeFalsy(); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); expect(stdout).toBeTruthy(); }); it('should recompile upon file change', (done) => { const proc = runAndGetWatchProc(__dirname, ['--watch', '--mode', 'development'], false, '', true); - let semaphore = 0; - proc.stdout.on('data', (chunk) => { - const data = stripAnsi(chunk.toString()); - - if (semaphore === 0 && data.includes('Compiler is watching files for updates...')) { - process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');`); - - semaphore++; - }); - } - if (semaphore === 1 && data.includes('was modified')) { - process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');`); + let modified = false; - semaphore++; - }); - } + proc.stdout.on('data', (chunk) => { + const data = stripAnsi(chunk.toString()); - if (semaphore === 2 && data.includes('index.js')) { + if (data.includes('index.js')) { if (isWebpack5) { for (const word of wordsInStatsv5) { expect(data).toContain(word); @@ -49,13 +36,23 @@ describe('--watch flag', () => { expect(data).toContain(word); } } - - semaphore++; } + }); + + proc.stderr.on('data', (chunk) => { + const data = stripAnsi(chunk.toString()); - if (semaphore === 3 && data.includes('Compiler is watching files for updates...')) { - proc.kill(); - done(); + if (data.includes('Compiler is watching files for updates...')) { + if (!modified) { + process.nextTick(() => { + writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');`); + }); + + modified = true; + } else { + proc.kill(); + done(); + } } }); }); diff --git a/test/zero-config/entry-absent/zero-config.test.js b/test/zero-config/entry-absent/zero-config.test.js index b67e707fba1..005e22689e2 100644 --- a/test/zero-config/entry-absent/zero-config.test.js +++ b/test/zero-config/entry-absent/zero-config.test.js @@ -2,10 +2,12 @@ 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 { exitCode, stderr, stdout } = run(__dirname, [], false); + + expect(exitCode).toBe(1); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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..b39db4d1243 100644 --- a/test/zero-config/entry-present/zero-config.test.js +++ b/test/zero-config/entry-present/zero-config.test.js @@ -1,17 +1,15 @@ -const fs = require('fs'); -const path = require('path'); 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 { exitCode, stderr, stdout } = run(__dirname, [], false); + + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); // 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); }); });