From 181295fb1b1973c201c221813562219d85b845ae Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 15 May 2021 20:21:06 +0530 Subject: [PATCH] fix: prettier config (#2719) --- .codecov.yml | 4 +- .eslintrc.js | 42 +- .github/ISSUE_TEMPLATE/Bug_report.md | 2 +- .github/ISSUE_TEMPLATE/Feature_request.md | 2 +- .github/dependabot.yml | 4 +- .github/workflows/nodejs.yml | 4 +- commitlint.config.js | 2 +- jest.config.js | 35 +- lint-staged.config.js | 4 +- open-bot.yml | 124 +-- packages/configtest/src/index.ts | 16 +- packages/generators/README.md | 7 +- .../generators/addon-template/package.json.js | 4 +- .../generators/init-template/default/index.js | 2 +- .../init-template/default/package.json.js | 16 +- .../init-template/default/postcss.config.js | 2 +- packages/generators/src/addon-generator.ts | 48 +- packages/generators/src/handlers.ts | 2 +- packages/generators/src/handlers/default.ts | 159 ++-- packages/generators/src/index.ts | 102 ++- packages/generators/src/init-generator.ts | 66 +- packages/generators/src/loader-generator.ts | 18 +- packages/generators/src/plugin-generator.ts | 20 +- packages/generators/src/types/index.ts | 2 +- packages/generators/src/update-generator.ts | 2 +- packages/generators/src/utils/helpers.ts | 4 +- .../generators/src/utils/scaffold-utils.ts | 31 +- packages/info/src/index.ts | 65 +- packages/serve/src/index.ts | 39 +- packages/serve/src/startDevServer.ts | 41 +- packages/serve/src/types.ts | 14 +- packages/webpack-cli/bin/cli.js | 28 +- packages/webpack-cli/lib/bootstrap.js | 4 +- packages/webpack-cli/lib/index.js | 4 +- packages/webpack-cli/lib/plugins/CLIPlugin.js | 52 +- .../lib/utils/capitalize-first-letter.js | 4 +- .../lib/utils/dynamic-import-loader.js | 2 +- .../lib/utils/get-package-manager.js | 34 +- packages/webpack-cli/lib/utils/index.js | 24 +- packages/webpack-cli/lib/utils/logger.js | 4 +- .../lib/utils/prompt-installation.js | 20 +- packages/webpack-cli/lib/utils/prompt.js | 4 +- packages/webpack-cli/lib/utils/run-command.js | 6 +- .../webpack-cli/lib/utils/to-kebab-case.js | 2 +- packages/webpack-cli/lib/webpack-cli.js | 855 +++++++++++------- prettier.config.js | 5 +- scripts/cleanupTest.js | 26 +- scripts/globalSetup.js | 2 +- scripts/prepareSuite.js | 16 +- scripts/setupBuild.js | 6 +- scripts/snapshotResolver.js | 27 +- scripts/updateDocs.js | 38 +- scripts/utils.js | 8 +- setupTest.js | 2 +- smoketests/helpers.js | 74 +- smoketests/index.js | 16 +- .../configtest.test.js | 18 +- .../generator.test.js | 18 +- .../missing-command-packages/info.test.js | 12 +- .../missing-command-packages/serve.test.js | 12 +- smoketests/missing-packages/prettier.test.js | 36 +- .../webpack-bundle-analyzer.test.js | 12 +- .../webpack-dev-server.test.js | 17 +- smoketests/missing-packages/webpack.test.js | 10 +- test/api/CLI.test.js | 816 +++++++++-------- test/api/capitalizeFirstLetter.test.js | 12 +- test/api/get-package-manager.test.js | 88 +- test/api/prompt-installation.test.js | 76 +- test/api/prompt.test.js | 38 +- test/api/resolveConfig/env.webpack.config.cjs | 2 +- test/api/resolveConfig/resolveConfig.test.js | 67 +- test/api/resolveConfig/webpack.config.cjs | 22 +- test/api/resolveConfig/webpack.config1.cjs | 6 +- test/api/resolveConfig/webpack.config2.cjs | 8 +- .../resolveConfig/webpack.promise.config.cjs | 6 +- test/api/scaffold-utils.test.js | 96 +- test/build/analyze/analyze-flag.test.js | 18 +- test/build/analyze/analyze.config.js | 11 +- test/build/analyze/webpack.config.js | 2 +- .../bail/bail-and-watch-webpack.config.js | 4 +- test/build/bail/bail-multi-webpack.config.js | 16 +- test/build/bail/bail-webpack.config.js | 4 +- test/build/bail/bail.test.js | 15 +- test/build/bail/multi-webpack.config.js | 16 +- test/build/bail/no-bail-webpack.config.js | 4 +- test/build/bail/src/first.js | 2 +- test/build/bail/src/second.js | 2 +- test/build/bail/watch-webpack.config.js | 4 +- test/build/basic/basic.test.js | 103 ++- test/build/basic/entry.config.js | 4 +- test/build/basic/log.config.js | 4 +- test/build/basic/src/again.js | 2 +- test/build/basic/src/entry.js | 2 +- test/build/basic/src/other.js | 2 +- test/build/build-errors/errors.test.js | 36 +- .../build-variable/build-variable.test.js | 10 +- test/build/build-variable/webpack.config.js | 8 +- test/build/build-warnings/warnings.test.js | 40 +- .../bundle-variable/bundle-variable.test.js | 10 +- test/build/bundle-variable/webpack.config.js | 8 +- test/build/cache/cache.test.js | 184 ++-- test/build/cache/multi.config.js | 34 +- test/build/cache/src/main.js | 2 +- test/build/cache/webpack.config.js | 18 +- .../colors/colors-false.webpack.config.js | 2 +- .../colors/colors-true.webpack.config.js | 2 +- test/build/colors/colors.test.js | 124 ++- test/build/colors/multiple-configs.js | 16 +- test/build/colors/no-stats.webpack.config.js | 4 +- test/build/colors/src/first.js | 2 +- test/build/colors/src/second.js | 2 +- .../colors/stats-boolean.webpack.config.js | 2 +- .../colors/stats-string.webpack.config.js | 4 +- test/build/colors/webpack.config.js | 2 +- .../build/config-format/coffee/coffee.test.js | 10 +- test/build/config-format/coffee/main.js | 2 +- .../commonjs-default/commonjs-default.test.js | 8 +- .../config-format/commonjs-default/main.js | 2 +- .../commonjs-default/webpack.config.cjs | 10 +- .../config-format/commonjs/commonjs.test.js | 8 +- test/build/config-format/commonjs/main.js | 2 +- .../config-format/commonjs/webpack.config.cjs | 10 +- .../config-format/failure/failure.test.js | 16 +- test/build/config-format/mjs/main.js | 2 +- test/build/config-format/mjs/mjs.test.js | 8 +- .../config-format/mjs/webpack.config.mjs | 12 +- .../config-format/typescript-esnext/main.ts | 2 +- .../typescript-esnext/typescript.test.js | 18 +- .../typescript-esnext/webpack.config.ts | 10 +- test/build/config-format/typescript/main.ts | 2 +- .../typescript/typescript.test.js | 14 +- .../typescript/webpack.config.ts | 10 +- test/build/config-lookup/custom-name/a.js | 2 +- .../custom-name/config.webpack.js | 8 +- .../custom-name/config.webpack.mjs | 10 +- .../custom-name/custom-name.test.js | 27 +- test/build/config-lookup/dotfolder-array/a.js | 2 +- .../dotfolder-array/dotfolder-array.test.js | 16 +- .../dotfolder-single/dotfolder-single.test.js | 16 +- .../dotfolder-single/index_two.js | 2 +- test/build/config-lookup/relative/a.js | 2 +- .../relative/basic-config.test.js | 24 +- .../config-lookup/relative/webpack.config.js | 8 +- test/build/config-name/config-name.test.js | 107 ++- test/build/config-name/function-config.js | 24 +- test/build/config-name/single-config.js | 8 +- test/build/config-name/single-other-config.js | 8 +- test/build/config-name/src/first.js | 2 +- test/build/config-name/src/second.js | 2 +- test/build/config-name/src/third.js | 2 +- test/build/config-name/webpack.config.js | 26 +- test/build/config/absent/a.js | 2 +- .../build/config/absent/config-absent.test.js | 19 +- .../config/absent/webpack.config-absent.js | 8 +- test/build/config/basic/a.js | 2 +- test/build/config/basic/basic-config.test.js | 18 +- test/build/config/basic/webpack.config.js | 8 +- .../basic-config/default-js-config.test.js | 24 +- .../defaults/basic-config/webpack.config.js | 4 +- .../cjs-config/default-cjs-config.test.js | 24 +- .../defaults/cjs-config/webpack.config.cjs | 4 +- .../multiple-location-config.test.js | 14 +- .../dev-none-config.test.js | 14 +- .../mjs-config/default-mjs-config.test.js | 28 +- .../defaults/mjs-config/webpack.config.mjs | 4 +- .../with-mode/multiple-config.test.js | 16 +- .../defaults/with-mode/webpack.config.js | 8 +- .../config/empty-array/empty-array.test.js | 15 +- .../empty-function/empty-function.test.js | 15 +- .../empty-promise/empty-promise.test.js | 15 +- test/build/config/empty/empty.test.js | 15 +- .../error-array/config-array-error.test.js | 12 +- .../error-commonjs/config-error.test.js | 26 +- .../config/error-commonjs/webpack.config.js | 6 +- .../config/error-mjs/config-error.test.js | 38 +- .../build/config/error-mjs/webpack.config.mjs | 6 +- .../config/function/functional-config.test.js | 36 +- .../config/function/multi-webpack.config.js | 20 +- .../config/function/single-webpack.config.js | 6 +- test/build/config/function/src/first.js | 2 +- test/build/config/function/src/second.js | 2 +- .../invalid-export/invalid-export.test.js | 19 +- .../config/invalid-export/webpack.config.js | 2 +- test/build/config/invalid-path/a.js | 2 +- .../config/invalid-path/invalid-path.test.js | 19 +- .../config/invalid-path/webpack.config.js | 8 +- .../config/multiple-with-one-compilation/a.js | 2 +- .../multiple-with-one-compilation.test.js | 18 +- .../webpack.config.js | 8 +- test/build/config/multiple/init.js | 2 +- .../config/multiple/multiple-config.test.js | 19 +- test/build/config/multiple/webpack1.config.js | 12 +- test/build/config/multiple/webpack2.config.js | 12 +- .../no-config-array/no-config-array.test.js | 15 +- test/build/config/no-config-object/a.js | 2 +- .../no-config-object/no-config-object.test.js | 17 +- .../config/type/array-function-with-argv/a.js | 2 +- .../config/type/array-function-with-argv/b.js | 2 +- .../function-with-argv.test.js | 18 +- .../webpack.config.js | 12 +- .../config/type/array-function-with-env/a.js | 2 +- .../array-function-with-env.test.js | 18 +- .../config/type/array-function-with-env/b.js | 2 +- .../array-function-with-env/webpack.config.js | 12 +- test/build/config/type/array-functions/a.js | 2 +- .../array-functions/array-functions.test.js | 21 +- test/build/config/type/array-functions/b.js | 2 +- .../type/array-functions/webpack.config.js | 16 +- test/build/config/type/array-promises/a.js | 2 +- .../array-promises/array-promises.test.js | 18 +- test/build/config/type/array-promises/b.js | 2 +- .../type/array-promises/webpack.config.js | 16 +- test/build/config/type/array/a.js | 2 +- test/build/config/type/array/array.test.js | 29 +- .../build/config/type/array/webpack.config.js | 28 +- test/build/config/type/function-array/a.js | 2 +- test/build/config/type/function-array/b.js | 2 +- .../function-array/function-array.test.js | 21 +- .../type/function-array/webpack.config.js | 16 +- test/build/config/type/function-async/a.js | 2 +- .../function-async/function-async.test.js | 19 +- .../type/function-async/webpack.config.js | 6 +- test/build/config/type/function-promise/a.js | 2 +- .../function-promise/function-promise.test.js | 19 +- .../type/function-promise/webpack.config.js | 6 +- .../build/config/type/function-with-argv/a.js | 2 +- .../function-with-argv.test.js | 20 +- .../type/function-with-argv/webpack.config.js | 4 +- test/build/config/type/function-with-env/a.js | 4 +- .../function-with-env.test.js | 157 ++-- .../type/function-with-env/webpack.config.js | 34 +- .../function-with-env/webpack.env.config.js | 14 +- test/build/config/type/function/a.js | 2 +- .../config/type/function/function.test.js | 19 +- .../config/type/function/webpack.config.js | 6 +- test/build/config/type/promise-array/a.js | 2 +- test/build/config/type/promise-array/b.js | 2 +- .../type/promise-array/promise-array.test.js | 18 +- .../type/promise-array/webpack.config.js | 12 +- test/build/config/type/promise-function/a.js | 2 +- .../promise-function/promise-function.test.js | 16 +- .../type/promise-function/webpack.config.js | 6 +- test/build/config/type/promise/a.js | 2 +- .../build/config/type/promise/promise.test.js | 16 +- .../config/type/promise/webpack.config.js | 6 +- test/build/core-flags/amd-flag.test.js | 12 +- test/build/core-flags/bail-flag.test.js | 18 +- test/build/core-flags/cache-flags.test.js | 298 +++--- test/build/core-flags/context-flag.test.js | 23 +- .../core-flags/dependencies-flag.test.js | 16 +- test/build/core-flags/devtool-flag.test.js | 20 +- .../build/core-flags/entry-reset-flag.test.js | 24 +- .../build/core-flags/experiments-flag.test.js | 22 +- test/build/core-flags/externals-flags.test.js | 26 +- .../ignore-warnings-flag.test.js | 33 +- .../ignore-warnings/my-warning-loader.js | 2 +- .../core-flags/ignore-warnings/src/main.js | 2 +- .../ignore-warnings/webpack.config.js | 14 +- .../core-flags/infrastructure-logging.test.js | 26 +- test/build/core-flags/invalid-flag.test.js | 13 +- test/build/core-flags/mock/mock.js | 2 +- test/build/core-flags/module-flags.test.js | 146 +-- test/build/core-flags/node-flags.test.js | 20 +- .../core-flags/optimization-flags.test.js | 87 +- test/build/core-flags/output-flags.test.js | 180 ++-- .../build/core-flags/parallelism-flag.test.js | 18 +- .../core-flags/performance-flags.test.js | 20 +- test/build/core-flags/profile-flag.test.js | 18 +- test/build/core-flags/records-flag.test.js | 33 +- test/build/core-flags/resolve-flags.test.js | 98 +- test/build/core-flags/snapshot-flags.test.js | 29 +- test/build/core-flags/src/entry.js | 2 +- test/build/core-flags/src/main.js | 2 +- test/build/core-flags/stats-flags.test.js | 58 +- test/build/core-flags/watch-flags.test.js | 36 +- test/build/core-flags/webpack.cache.config.js | 14 +- test/build/core-flags/webpack.config.js | 10 +- test/build/custom-webpack/custom-webpack.js | 2 +- .../custom-webpack/custom-webpack.test.js | 20 +- test/build/custom-webpack/webpack.config.js | 2 +- test/build/defaults/a.js | 2 +- test/build/defaults/output-defaults.test.js | 37 +- .../devtool/array/source-map-array.test.js | 23 +- test/build/devtool/array/webpack.config.js | 28 +- .../devtool/object/source-map-object.test.js | 42 +- .../devtool/object/webpack.eval.config.js | 14 +- .../devtool/object/webpack.source.config.js | 14 +- test/build/entry/config-entry/1.js | 8 +- .../entry-with-config.test.js | 18 +- .../entry-with-config.test.js | 18 +- .../config-entry/entry-with-index/src/app.js | 2 +- .../entry-with-index/src/print.js | 2 +- .../entry-with-index/webpack.config.js | 12 +- .../defaults-empty/entry-single-arg.test.js | 8 +- .../defaults-index/entry-multi-args.test.js | 20 +- .../entry/flag-entry/entry-with-flag.test.js | 37 +- test/build/entry/flag-entry/src/a.js | 2 +- test/build/entry/flag-entry/src/index.cjs | 2 +- .../multiple-entries/multi-entries.test.js | 27 +- test/build/entry/multiple-entries/src/a.js | 2 +- test/build/entry/multiple-entries/src/b.js | 2 +- test/build/entry/multiple-entries/src/c.js | 2 +- test/build/entry/scss/home.js | 2 +- test/build/entry/scss/scss.test.js | 10 +- test/build/entry/scss/webpack.config.js | 14 +- test/build/env/array/array-env.test.js | 24 +- test/build/env/array/webpack.config.js | 16 +- test/build/env/object/object-env.test.js | 18 +- test/build/env/object/webpack.config.js | 8 +- .../build/error/error-in-plugin/error.test.js | 18 +- .../error/error-in-plugin/webpack.config.js | 2 +- .../invalid-schema/invalid-schema.test.js | 74 +- .../invalid-schema/webpack.mock.config.js | 2 +- .../webpack.plugin-mock.config.js | 6 +- test/build/hot/hot-flag.test.js | 48 +- test/build/hot/webpack.config.js | 4 +- test/build/import-local/import-local.test.js | 10 +- test/build/json/json.test.js | 133 +-- test/build/json/logging.config.js | 2 +- test/build/merge/config-absent/1.js | 2 +- .../config-absent/merge-config-absent.test.js | 20 +- test/build/merge/config-absent/some_entry.js | 2 +- test/build/merge/config/1.js | 8 +- test/build/merge/config/2.js | 6 +- test/build/merge/config/3.js | 4 +- test/build/merge/config/first-entry.js | 2 +- test/build/merge/config/merge-config.test.js | 52 +- test/build/merge/config/second-entry.js | 2 +- test/build/merge/config/third-entry.js | 2 +- .../mode-single-arg/mode-single-arg.test.js | 36 +- .../mode/mode-single-arg/webpack.config.js | 4 +- .../mode-with-config/mode-with-config.test.js | 93 +- .../mode/mode-with-config/webpack.config.js | 8 +- .../mode/mode-with-config/webpack.config2.js | 4 +- .../mode/mode-with-config/webpack.config3.js | 2 +- test/build/name/name.test.js | 10 +- test/build/name/webpack.config.js | 2 +- test/build/node-env/auto-mode.config.js | 2 +- test/build/node-env/node-env.test.js | 33 +- test/build/node-env/webpack.config.js | 2 +- test/build/node/a.js | 2 +- test/build/node/bootstrap.js | 2 +- test/build/node/bootstrap2.js | 2 +- test/build/node/node.test.js | 49 +- test/build/node/webpack.config.js | 8 +- test/build/output/a.js | 2 +- test/build/output/b.js | 2 +- test/build/output/c.js | 2 +- .../build/output/output-named-bundles.test.js | 35 +- test/build/output/webpack.config.js | 10 +- test/build/output/webpack.defaults.config.js | 6 +- test/build/output/webpack.multiple.config.js | 12 +- test/build/output/webpack.single.config.js | 12 +- test/build/prefetch/prefetch.test.js | 36 +- test/build/prefetch/src/p.js | 4 +- test/build/progress/progress-flag.test.js | 40 +- .../build/progress/webpack.progress.config.js | 4 +- .../start-finish-force-log.test.js | 44 +- .../webpack.config.array.js | 8 +- .../start-finish-force-log/webpack.config.js | 2 +- test/build/stats/config-no/main.js | 2 +- .../config-no/no-stats-with-config.test.js | 16 +- test/build/stats/config-no/webpack.config.js | 8 +- test/build/stats/config/stats.test.js | 50 +- test/build/stats/config/webpack.config.js | 8 +- test/build/stats/flags/stats.test.js | 76 +- test/build/stats/flags/webpack.config.js | 6 +- .../target/flag-test/target-flag.test.js | 84 +- test/build/target/flag-test/webpack.config.js | 8 +- test/build/target/node/main.js | 2 +- test/build/target/node/new.js | 2 +- test/build/target/node/node-test.test.js | 12 +- test/build/target/node/webpack.config.js | 6 +- test/build/unknown/unknown.test.js | 183 ++-- .../entry-absent/zero-config.test.js | 8 +- .../entry-present/zero-config.test.js | 10 +- .../with-config-path/basic.config.js | 6 +- .../with-config-path/error.config.js | 6 +- .../with-config-path/with-config-path.test.js | 51 +- .../without-config-path.test.js | 12 +- .../webpack.config.js | 6 +- .../without-config-path-error.test.js | 12 +- .../webpack.config.js | 12 +- ...ut-config-path-multi-compiler-mode.test.js | 12 +- ...thout-config-path-no-configuration.test.js | 12 +- .../without-config-path/webpack.config.js | 6 +- .../without-config-path.test.js | 12 +- test/help/help.test.js | 357 ++++---- test/info/info-output.test.js | 62 +- test/info/info-unknown.test.js | 8 +- test/init/init.test.js | 355 +++++--- test/loader/error-test/loader-error.test.js | 8 +- test/loader/error-test/src/index.ts | 4 +- test/loader/error-test/webpack.config.js | 14 +- test/loader/loader.test.js | 152 +++- .../warning-test/loader-warning.test.js | 10 +- test/loader/warning-test/my-loader.js | 2 +- test/loader/warning-test/src/main.js | 4 +- test/loader/warning-test/webpack.config.js | 18 +- test/plugin/plugin.test.js | 165 +++- .../dev-server-output-public-path.config.js | 10 +- test/serve/basic/function-with-argv.config.js | 10 +- test/serve/basic/function-with-env.config.js | 10 +- .../basic/helper/base-dev-server.config.js | 8 +- test/serve/basic/log.config.js | 8 +- ...ti-dev-server-output-public-path.config.js | 28 +- test/serve/basic/multi-dev-server.config.js | 22 +- .../basic/multi-output-public-path.config.js | 24 +- test/serve/basic/multi.config.js | 20 +- .../serve/basic/multiple-dev-server.config.js | 22 +- test/serve/basic/output-public-path.config.js | 12 +- .../basic/same-ports-dev-serever.config.js | 14 +- test/serve/basic/serve-basic.test.js | 529 ++++++----- test/serve/basic/serve.config.js | 10 +- test/serve/basic/src/entry.js | 2 +- test/serve/basic/src/other.js | 2 +- test/serve/basic/stats.config.js | 10 +- test/serve/basic/watch.config.js | 10 +- test/serve/basic/webpack.config.js | 10 +- .../invalid-schema/invalid-schema.test.js | 46 +- .../webpack-dev-server.config.mock.js | 4 +- .../invalid-schema/webpack.config.mock.js | 2 +- test/serve/serve-variable/serve-basic.test.js | 22 +- test/serve/serve-variable/webpack.config.js | 8 +- .../serve-custom-config.test.js | 58 +- test/serve/with-custom-port/webpack.config.js | 10 +- test/utils/cli-plugin-test/main.js | 2 +- test/utils/cli-plugin-test/plugin.test.js | 14 +- test/utils/cli-plugin-test/webpack.config.js | 16 +- test/utils/exec-in-directory.js | 2 +- test/utils/test-utils.js | 86 +- test/utils/test-utils.test.js | 83 +- test/utils/webpack-cli-test-plugin.js | 4 +- test/version/version.test.js | 335 +++---- test/watch/analyze/analyze-flag.test.js | 10 +- test/watch/analyze/analyze.config.js | 11 +- test/watch/analyze/webpack.config.js | 2 +- .../bail/bail-and-watch-webpack.config.js | 4 +- test/watch/bail/bail-multi-webpack.config.js | 16 +- test/watch/bail/bail-webpack.config.js | 4 +- test/watch/bail/bail.test.js | 49 +- test/watch/bail/multi-webpack.config.js | 16 +- test/watch/bail/no-bail-webpack.config.js | 4 +- test/watch/bail/src/first.js | 2 +- test/watch/bail/src/second.js | 2 +- test/watch/bail/watch-webpack.config.js | 4 +- test/watch/basic/basic.test.js | 121 ++- test/watch/basic/log.config.js | 4 +- test/watch/basic/src/entry.js | 2 +- test/watch/stats/multi-webpack.config.js | 32 +- test/watch/stats/stats-and-watch.test.js | 17 +- test/watch/stats/webpack.config.js | 15 +- test/watch/stdin/multi-serve.config.js | 2 +- test/watch/stdin/multi-watch.config.js | 2 +- test/watch/stdin/src/second.js | 2 +- test/watch/stdin/stdin.test.js | 40 +- .../watch-variable/watch-variable.test.js | 44 +- test/watch/watch-variable/webpack.config.js | 8 +- 458 files changed, 6950 insertions(+), 5238 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index d295391be7a..9f22d86e981 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -4,7 +4,7 @@ codecov: coverage: precision: 2 round: down - range: '50...100' + range: "50...100" parsers: gcov: @@ -15,6 +15,6 @@ parsers: macro: no comment: - layout: 'reach,diff,flags,files,footer' + layout: "reach,diff,flags,files,footer" behavior: default require_changes: no diff --git a/.eslintrc.js b/.eslintrc.js index 2cd5cba0359..8a997fa48f2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,12 +1,17 @@ module.exports = { root: true, reportUnusedDisableDirectives: true, - extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:prettier/recommended', 'prettier'], - parserOptions: { ecmaVersion: 2018, sourceType: 'script' }, - plugins: ['node'], + extends: [ + "eslint:recommended", + "plugin:node/recommended", + "plugin:prettier/recommended", + "prettier", + ], + parserOptions: { ecmaVersion: 2018, sourceType: "script" }, + plugins: ["node"], settings: { node: { - allowModules: ['@webpack-cli/generators'], + allowModules: ["@webpack-cli/generators"], }, }, env: { @@ -15,27 +20,30 @@ module.exports = { jest: true, }, rules: { - quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: false }], - 'no-process-exit': 'off', - 'no-template-curly-in-string': 'error', - 'no-caller': 'error', - 'no-extra-bind': 'error', - 'no-loop-func': 'error', - 'no-undef': 'error', + "no-process-exit": "off", + "no-template-curly-in-string": "error", + "no-caller": "error", + "no-extra-bind": "error", + "no-loop-func": "error", + "no-undef": "error", }, overrides: [ { settings: { node: { - tryExtensions: ['.ts', '.tsx', '.js', '.jsx', '.json'], + tryExtensions: [".ts", ".tsx", ".js", ".jsx", ".json"], }, }, - files: ['**/*.ts'], - extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], + files: ["**/*.ts"], + extends: [ + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "prettier", + ], + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint"], rules: { - 'node/no-unsupported-features/es-syntax': 'off', + "node/no-unsupported-features/es-syntax": "off", }, }, ], diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index a96266fed03..ba266dbec29 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -1,7 +1,7 @@ --- name: "[BUG]: \U0001F41EReport" about: "Template for \U0001F98E's you encounter with webpack-cli" -labels: 'Bug' +labels: "Bug" --- **Describe the bug** diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md index 71aecb8c586..643a7d5fe36 100644 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -1,7 +1,7 @@ --- name: "[FEATURE]: Feature request \U0001F914" about: "Suggest ideas you wish webpack-cli had \U0001F680" -labels: 'Feature Request' +labels: "Feature Request" --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8323e7c9467..8505d9a5fdf 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,10 @@ version: 2 updates: - package-ecosystem: npm - directory: '/' + directory: "/" schedule: interval: daily - time: '04:00' + time: "04:00" timezone: Europe/Berlin open-pull-requests-limit: 10 versioning-strategy: lockfile-only diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 8cfd8a22a9a..caff4b99a80 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,7 +12,7 @@ on: workflow_dispatch: inputs: tags: - description: 'Test description' + description: "Test description" jobs: lint: @@ -115,7 +115,7 @@ jobs: - uses: actions/setup-node@v1 with: - node-version: '12.x' + node-version: "12.x" - run: npm install diff --git a/commitlint.config.js b/commitlint.config.js index 2f9d1aa0e6c..db74d15522c 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,3 +1,3 @@ module.exports = { - extends: ['@commitlint/config-conventional'], + extends: ["@commitlint/config-conventional"], }; diff --git a/jest.config.js b/jest.config.js index ae3797dcc82..af8a0297593 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,25 +1,30 @@ -const { cli } = require('webpack'); +const { cli } = require("webpack"); // Ignore core-flags test for webpack@4 const ignorePattern = - typeof cli !== 'undefined' ? ['/node_modules/'] : ['/node_modules/', '/test/build/core-flags']; + typeof cli !== "undefined" + ? ["/node_modules/"] + : ["/node_modules/", "/test/build/core-flags"]; module.exports = { testPathIgnorePatterns: ignorePattern, - testEnvironment: 'node', + testEnvironment: "node", collectCoverage: true, - coverageDirectory: '.nyc_output', - coverageReporters: ['json'], - coveragePathIgnorePatterns: ['/test/'], + coverageDirectory: ".nyc_output", + coverageReporters: ["json"], + coveragePathIgnorePatterns: ["/test/"], transform: { - '^.+\\.(ts)?$': 'ts-jest', + "^.+\\.(ts)?$": "ts-jest", }, - testRegex: ['/test/.*\\.(test.js|test.ts)$'], - moduleFileExtensions: ['ts', 'js', 'json'], - snapshotResolver: '/scripts/snapshotResolver.js', - watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'], - setupFilesAfterEnv: ['/setupTest.js'], - globalTeardown: '/scripts/cleanupTest.js', - globalSetup: '/scripts/globalSetup.js', - modulePathIgnorePatterns: ['/test/loader/test-loader', '/test/plugin/test-plugin'], + testRegex: ["/test/.*\\.(test.js|test.ts)$"], + moduleFileExtensions: ["ts", "js", "json"], + snapshotResolver: "/scripts/snapshotResolver.js", + watchPlugins: ["jest-watch-typeahead/filename", "jest-watch-typeahead/testname"], + setupFilesAfterEnv: ["/setupTest.js"], + globalTeardown: "/scripts/cleanupTest.js", + globalSetup: "/scripts/globalSetup.js", + modulePathIgnorePatterns: [ + "/test/loader/test-loader", + "/test/plugin/test-plugin", + ], }; diff --git a/lint-staged.config.js b/lint-staged.config.js index 3a61f2cf20b..e487d8f7c5a 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,4 +1,4 @@ module.exports = { - '*.{json,md,yml,css}': ['prettier --write'], - '*.{js,ts}': ['eslint --fix', 'prettier --write'], + "*.{json,md,yml,css}": ["prettier --write"], + "*.{js,ts}": ["eslint --fix", "prettier --write"], }; diff --git a/open-bot.yml b/open-bot.yml index 0e6a5847211..aedfe64095e 100644 --- a/open-bot.yml +++ b/open-bot.yml @@ -1,4 +1,4 @@ -bot: 'webpack-bot' +bot: "webpack-bot" rules: # Add ci-ok, ci-not-ok labels depending on travis status # comment to point the user to the results @@ -8,16 +8,16 @@ rules: pull_request: mergeable: true status_1: - context: 'continuous-integration/travis-ci/pr' + context: "continuous-integration/travis-ci/pr" ensure_1: - value: '{{status_1.state}}' - equals: 'success' + value: "{{status_1.state}}" + equals: "success" actions: label: - add: 'PR: CI-ok' - remove: 'PR: CI-not-ok' + add: "PR: CI-ok" + remove: "PR: CI-not-ok" comment: - identifier: 'ci-result' + identifier: "ci-result" message: |- Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. - filters: @@ -25,15 +25,15 @@ rules: pull_request: mergeable: true status_1: - context: 'continuous-integration/travis-ci/pr' + context: "continuous-integration/travis-ci/pr" any: ensure_1: - value: '{{status_1.state}}' - equals: 'failure' + value: "{{status_1.state}}" + equals: "failure" actions: label: - add: 'PR: CI-not-ok' - remove: 'PR: CI-ok' + add: "PR: CI-not-ok" + remove: "PR: CI-ok" set: id: report_ci value: yep @@ -41,27 +41,27 @@ rules: # Report specific error message if jest tests fails - filters: ensure: - value: '{{report_ci}}' + value: "{{report_ci}}" equals: yep commit: true status: - context: 'continuous-integration/travis-ci/pr' + context: "continuous-integration/travis-ci/pr" travis_job: - state: 'failed' + state: "failed" allow_failure: false config: env: JOB_PART=integration fetch: travis_job.log string_cleanup: id: logResult - value: '{{{fetch}}}' + value: "{{{fetch}}}" remove: - "^[\\s\\S]+?npm run travis:\\$JOB_PART\n*" - "npm ERR!.*\n" - "\n*=============================================================================\n[\\s\\S]*" actions: comment: - identifier: 'ci-result' + identifier: "ci-result" message: |- @{{commit.author.login}} Please review the following output log for errors: @@ -77,26 +77,26 @@ rules: # Report specific error message if linting fails - filters: ensure: - value: '{{report_ci}}' + value: "{{report_ci}}" equals: yep commit: true status: - context: 'continuous-integration/travis-ci/pr' + context: "continuous-integration/travis-ci/pr" travis_job: - state: 'failed' + state: "failed" config: env: JOB_PART=lint fetch: travis_job.log string_cleanup: id: logResult - value: '{{{fetch}}}' + value: "{{{fetch}}}" remove: - "^[\\s\\S]+?npm run travis:\\$JOB_PART\n*" - "npm ERR!.*\n" - "\n*The command \"npm run travis:\\$JOB_PART\" exited [\\s\\S]*" actions: comment: - identifier: 'ci-result' + identifier: "ci-result" message: |- @{{commit.author.login}} The tests look fine, but there are code style issue in your Pull Request. Please review the following: @@ -112,14 +112,14 @@ rules: # Report a general error message - filters: ensure: - value: '{{report_ci}}' + value: "{{report_ci}}" equals: yep commit: true status_1: - context: 'continuous-integration/travis-ci/pr' + context: "continuous-integration/travis-ci/pr" actions: comment: - identifier: 'ci-result' + identifier: "ci-result" message: |- @{{commit.author.login}} The most important CI builds failed. This way your PR can't be merged. @@ -133,18 +133,18 @@ rules: mergeable: false actions: label: - add: 'PR: conflict' + add: "PR: conflict" remove: - - 'PR: tests-needed' - - 'PR: CI-ok' - - 'PR: CI-not-ok' + - "PR: tests-needed" + - "PR: CI-ok" + - "PR: CI-not-ok" - filters: open: true pull_request: mergeable: true actions: label: - remove: 'PR: conflict' + remove: "PR: conflict" # add unreviewed, reviewed, review-outdated labels # comment to ping reviewer @@ -156,15 +156,15 @@ rules: review: state: APPROVED|CHANGES_REQUESTED ensure: - value: '{{review.state}}' + value: "{{review.state}}" equals: APPROVED actions: label: - add: 'PR: reviewed-approved' + add: "PR: reviewed-approved" remove: - - 'PR: review-outdated' - - 'PR: unreviewed' - - 'PR: reviewed' + - "PR: review-outdated" + - "PR: unreviewed" + - "PR: reviewed" - filters: open: true in_order: @@ -172,15 +172,15 @@ rules: review: state: APPROVED|CHANGES_REQUESTED ensure: - value: '{{review.state}}' + value: "{{review.state}}" equals: CHANGES_REQUESTED actions: label: - add: 'PR: reviewed-changes-requested' + add: "PR: reviewed-changes-requested" remove: - - 'PR: review-outdated' - - 'PR: unreviewed' - - 'PR: reviewed' + - "PR: review-outdated" + - "PR: unreviewed" + - "PR: reviewed" - filters: open: true in_order: @@ -188,20 +188,20 @@ rules: state: APPROVED|CHANGES_REQUESTED commit: true not: - label: 'review-outdated' + label: "review-outdated" ensure: - value: '{{commit.author.login}}' - notEquals: '{{review.user.login}}' + value: "{{commit.author.login}}" + notEquals: "{{review.user.login}}" actions: label: - add: 'PR: review-outdated' + add: "PR: review-outdated" remove: - - 'PR: reviewed-approved' - - 'PR: reviewed-changes-requested' - - 'PR: unreviewed' - - 'PR: reviewed' + - "PR: reviewed-approved" + - "PR: reviewed-changes-requested" + - "PR: unreviewed" + - "PR: reviewed" comment: - identifier: 'review-outdated' + identifier: "review-outdated" message: |- @{{commit.author.login}} Thanks for your update. @@ -215,17 +215,17 @@ rules: review: state: APPROVED|CHANGES_REQUESTED actions: - label: 'PR: unreviewed' + label: "PR: unreviewed" # add small label to small pull requests - filters: open: true pull_request: - additions: '<= 10' - deletions: '<= 10' - changed_files: '<= 2' + additions: "<= 10" + deletions: "<= 10" + changed_files: "<= 2" actions: - label: 'PR: small' + label: "PR: small" # add non-master label to pull request to other branch - filters: @@ -234,11 +234,11 @@ rules: minimum: 1d maximum: 1w pull_request: - head_ref: '^master$' - permission: 'read|none' + head_ref: "^master$" + permission: "read|none" actions: comment: - identifier: 'head-master' + identifier: "head-master" edit: true message: |- Hi @{{pull_request.user.login}}. @@ -256,12 +256,12 @@ rules: not: comment_1: matching: "moved\\-by\\-bot" - author: '.' + author: "." permission: - user: '{{comment.actor.login}}' + user: "{{comment.actor.login}}" actions: new_issue: - target: '{{{comment_match.[1]}}}' + target: "{{{comment_match.[1]}}}" body: |- {{{issue.body}}} @@ -284,8 +284,8 @@ rules: not: label: inactive ensure: - value: '{{issue.reactions.[+1]}}' - range: '< 10' + value: "{{issue.reactions.[+1]}}" + range: "< 10" last_action_age: 26w # half a year actions: comment: diff --git a/packages/configtest/src/index.ts b/packages/configtest/src/index.ts index caa31de3f49..025ef647d29 100644 --- a/packages/configtest/src/index.ts +++ b/packages/configtest/src/index.ts @@ -5,10 +5,10 @@ class ConfigTestCommand { await cli.makeCommand( { - name: 'configtest [config-path]', - alias: 't', - description: 'Validate a webpack configuration.', - pkg: '@webpack-cli/configtest', + name: "configtest [config-path]", + alias: "t", + description: "Validate a webpack configuration.", + pkg: "@webpack-cli/configtest", }, [], async (configPath: string | undefined): Promise => { @@ -28,11 +28,11 @@ class ConfigTestCommand { } if (configPaths.size === 0) { - logger.error('No configuration found.'); + logger.error("No configuration found."); process.exit(2); } - logger.info(`Validate '${Array.from(configPaths).join(' ,')}'.`); + logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); try { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -52,7 +52,9 @@ class ConfigTestCommand { process.exit(2); } - logger.success('There are no validation errors in the given webpack configuration.'); + logger.success( + "There are no validation errors in the given webpack configuration.", + ); }, ); } diff --git a/packages/generators/README.md b/packages/generators/README.md index 5b66e5a9690..22c00e6ba93 100644 --- a/packages/generators/README.md +++ b/packages/generators/README.md @@ -19,7 +19,12 @@ To run the package programmatically, install it as a dependency. When using the ### Node ```js -const { addonGenerator, initGenerator, loaderGenerator, pluginGenerator } = require('@webpack-cli/generators'); +const { + addonGenerator, + initGenerator, + loaderGenerator, + pluginGenerator, +} = require("@webpack-cli/generators"); // ... compose with yeoman env or add a generator to your own yeoman project ``` diff --git a/packages/generators/addon-template/package.json.js b/packages/generators/addon-template/package.json.js index 28ce806a7a7..3a18def4000 100644 --- a/packages/generators/addon-template/package.json.js +++ b/packages/generators/addon-template/package.json.js @@ -1,7 +1,7 @@ module.exports = (name) => { return { - version: '1.0.0', - description: 'webpack loader', + version: "1.0.0", + description: "webpack loader", name, }; }; diff --git a/packages/generators/init-template/default/index.js b/packages/generators/init-template/default/index.js index a420803c09e..019c0f4bc8e 100644 --- a/packages/generators/init-template/default/index.js +++ b/packages/generators/init-template/default/index.js @@ -1 +1 @@ -console.log('Hello World!'); +console.log("Hello World!"); diff --git a/packages/generators/init-template/default/package.json.js b/packages/generators/init-template/default/package.json.js index d50cd74f5a4..3f45ce163f2 100644 --- a/packages/generators/init-template/default/package.json.js +++ b/packages/generators/init-template/default/package.json.js @@ -1,18 +1,18 @@ module.exports = (isUsingDevServer) => { const scripts = { - build: 'webpack --mode=production --node-env=production', - 'build:dev': 'webpack --mode=development', - 'build:prod': 'webpack --mode=production --node-env=production', - watch: 'webpack --watch', + build: "webpack --mode=production --node-env=production", + "build:dev": "webpack --mode=development", + "build:prod": "webpack --mode=production --node-env=production", + watch: "webpack --watch", }; if (isUsingDevServer) { - scripts.serve = 'webpack serve'; + scripts.serve = "webpack serve"; } return { - version: '1.0.0', - description: 'My webpack project', - name: 'my-webpack-project', + version: "1.0.0", + description: "My webpack project", + name: "my-webpack-project", scripts, }; }; diff --git a/packages/generators/init-template/default/postcss.config.js b/packages/generators/init-template/default/postcss.config.js index 13efa3d39c3..8855b03e6ea 100644 --- a/packages/generators/init-template/default/postcss.config.js +++ b/packages/generators/init-template/default/postcss.config.js @@ -1,5 +1,5 @@ module.exports = { // Add you postcss configuration here // Learn more about it at https://github.com/webpack-contrib/postcss-loader#config-files - plugins: [['autoprefixer']], + plugins: [["autoprefixer"]], }; diff --git a/packages/generators/src/addon-generator.ts b/packages/generators/src/addon-generator.ts index 7206853e592..270cdffcbc4 100644 --- a/packages/generators/src/addon-generator.ts +++ b/packages/generators/src/addon-generator.ts @@ -1,8 +1,8 @@ -import fs from 'fs'; -import path from 'path'; -import Generator from 'yeoman-generator'; +import fs from "fs"; +import path from "path"; +import Generator from "yeoman-generator"; -import { List } from './utils/scaffold-utils'; +import { List } from "./utils/scaffold-utils"; // Helper to get the template-directory content @@ -57,14 +57,16 @@ const addonGenerator = ( public async prompting(): Promise { if (!this.supportedTemplates.includes(this.template)) { - this.utils.logger.warn(`⚠ ${this.template} is not a valid template, please select one from below`); + this.utils.logger.warn( + `⚠ ${this.template} is not a valid template, please select one from below`, + ); const { selectedTemplate } = await List( this, - 'selectedTemplate', - 'Select a valid template from below:', + "selectedTemplate", + "Select a valid template from below:", this.supportedTemplates, - 'default', + "default", false, ); @@ -88,7 +90,7 @@ const addonGenerator = ( try { fs.mkdirSync(pathToProjectDir, { recursive: true }); } catch (error) { - this.utils.logger.error('Failed to create directory'); + this.utils.logger.error("Failed to create directory"); this.utils.logger.error(error); } this.destinationRoot(pathToProjectDir); @@ -96,9 +98,12 @@ const addonGenerator = ( } public writing(): void { - const packageJsonTemplatePath = '../addon-template/package.json.js'; - // eslint-disable-next-line @typescript-eslint/no-var-requires - this.fs.extendJSON(this.destinationPath('package.json'), require(packageJsonTemplatePath)(this.props.name)); + const packageJsonTemplatePath = "../addon-template/package.json.js"; + this.fs.extendJSON( + this.destinationPath("package.json"), + // eslint-disable-next-line @typescript-eslint/no-var-requires + require(packageJsonTemplatePath)(this.props.name), + ); let files = []; try { @@ -110,20 +115,27 @@ const addonGenerator = ( } // Template file paths should be of the form `path/to/_file.js.tpl` - const copyTemplateFiles = files.filter((filePath) => path.basename(filePath).startsWith('_')); + const copyTemplateFiles = files.filter((filePath) => + path.basename(filePath).startsWith("_"), + ); // File paths should be of the form `path/to/file.js.tpl` const copyFiles = files.filter((filePath) => !copyTemplateFiles.includes(filePath)); copyFiles.forEach((filePath) => { // `absolute-path/to/file.js.tpl` -> `destination-path/file.js` - const destFilePath = path.relative(this.resolvedTemplatePath, filePath).replace('.tpl', ''); + const destFilePath = path + .relative(this.resolvedTemplatePath, filePath) + .replace(".tpl", ""); this.fs.copyTpl(filePath, this.destinationPath(destFilePath)); }); copyTemplateFiles.forEach((filePath) => { // `absolute-path/to/_file.js.tpl` -> `destination-path/file.js` - const destFilePath = path.relative(this.resolvedTemplatePath, filePath).replace('_', '').replace('.tpl', ''); + const destFilePath = path + .relative(this.resolvedTemplatePath, filePath) + .replace("_", "") + .replace(".tpl", ""); this.fs.copyTpl(filePath, this.destinationPath(destFilePath), templateFn(this)); }); } @@ -132,10 +144,10 @@ const addonGenerator = ( const packager = this.utils.getPackageManager(); const opts: { dev?: boolean; - 'save-dev'?: boolean; - } = packager === 'yarn' ? { dev: true } : { 'save-dev': true }; + "save-dev"?: boolean; + } = packager === "yarn" ? { dev: true } : { "save-dev": true }; - this.scheduleInstallTask(packager, ['webpack-defaults', 'bluebird'], opts); + this.scheduleInstallTask(packager, ["webpack-defaults", "bluebird"], opts); } }; }; diff --git a/packages/generators/src/handlers.ts b/packages/generators/src/handlers.ts index fe2f36ff63d..5c5061b1f4c 100644 --- a/packages/generators/src/handlers.ts +++ b/packages/generators/src/handlers.ts @@ -1,4 +1,4 @@ -import * as defaultHandler from './handlers/default'; +import * as defaultHandler from "./handlers/default"; export default { default: defaultHandler, diff --git a/packages/generators/src/handlers/default.ts b/packages/generators/src/handlers/default.ts index c607c07a695..d34cbf8ba4e 100644 --- a/packages/generators/src/handlers/default.ts +++ b/packages/generators/src/handlers/default.ts @@ -1,7 +1,7 @@ -import path from 'path'; -import { CustomGenerator } from '../types'; +import path from "path"; +import { CustomGenerator } from "../types"; -const templatePath = path.resolve(__dirname, '../../init-template/default'); +const templatePath = path.resolve(__dirname, "../../init-template/default"); const resolveFile = (file: string): string => { return path.resolve(templatePath, file); }; @@ -12,43 +12,57 @@ const resolveFile = (file: string): string => { * @param Question Contains questions */ -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export async function questions(self: CustomGenerator, Question: Record): Promise { +export async function questions( + self: CustomGenerator, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Question: Record, +): Promise { // Handle JS language solutions const { langType } = await Question.List( self, - 'langType', - 'Which of the following JS solutions do you want to use?', - ['none', 'ES6', 'Typescript'], - 'none', + "langType", + "Which of the following JS solutions do you want to use?", + ["none", "ES6", "Typescript"], + "none", self.force, ); switch (langType) { - case 'ES6': - self.dependencies = [...self.dependencies, 'babel-loader', '@babel/core', '@babel/preset-env']; + case "ES6": + self.dependencies = [ + ...self.dependencies, + "babel-loader", + "@babel/core", + "@babel/preset-env", + ]; break; - case 'Typescript': - self.dependencies = [...self.dependencies, 'typescript', 'ts-loader']; + case "Typescript": + self.dependencies = [...self.dependencies, "typescript", "ts-loader"]; break; } // Configure devServer configuraion - const { devServer } = await Question.Confirm(self, 'devServer', 'Do you want to use webpack-dev-server?', true, self.force); + const { devServer } = await Question.Confirm( + self, + "devServer", + "Do you want to use webpack-dev-server?", + true, + self.force, + ); if (devServer) { - self.dependencies = [...self.dependencies, 'webpack-dev-server']; + self.dependencies = [...self.dependencies, "webpack-dev-server"]; } // Handle addition of html-webpack-plugin const { htmlWebpackPlugin } = await Question.Confirm( self, - 'htmlWebpackPlugin', - 'Do you want to simplify the creation of HTML files for your bundle?', + "htmlWebpackPlugin", + "Do you want to simplify the creation of HTML files for your bundle?", true, self.force, ); if (htmlWebpackPlugin) { - self.dependencies = [...self.dependencies, 'html-webpack-plugin']; + self.dependencies = [...self.dependencies, "html-webpack-plugin"]; } // Store all answers for generation @@ -57,65 +71,83 @@ export async function questions(self: CustomGenerator, Question: Record { - options.generationPath = generationPath || '.'; + options.generationPath = generationPath || "."; - const env = yeoman.createEnv([], { cwd: options.generationPath }); - const generatorName = 'webpack-init-generator'; + const env = yeoman.createEnv([], { + cwd: options.generationPath, + }); + const generatorName = "webpack-init-generator"; env.registerStub(initGenerator, generatorName); env.run(generatorName, { cli, options }, () => { - logger.success('Project has been initialised with webpack!'); + logger.success("Project has been initialised with webpack!"); }); }, ); await cli.makeCommand( { - name: 'loader [output-path]', - alias: 'l', - description: 'Scaffold a loader.', + name: "loader [output-path]", + alias: "l", + description: "Scaffold a loader.", argsDescription: { - 'output-path': 'Path to the output directory, e.g. ./loaderName', + "output-path": "Path to the output directory, e.g. ./loaderName", }, - usage: '[output-path] [options]', - pkg: '@webpack-cli/generators', + usage: "[output-path] [options]", + pkg: "@webpack-cli/generators", }, [ { - name: 'template', - alias: 't', - configs: [{ type: 'string' }], - description: 'Type of template', - defaultValue: 'default', + name: "template", + alias: "t", + configs: [{ type: "string" }], + description: "Type of template", + defaultValue: "default", }, ], async (outputPath, options) => { const env = yeoman.createEnv([], { cwd: outputPath }); - const generatorName = 'webpack-loader-generator'; + const generatorName = "webpack-loader-generator"; env.registerStub(loaderGenerator, generatorName); env.run(generatorName, { cli, options }, () => { - logger.success('Loader template has been successfully scaffolded.'); + logger.success("Loader template has been successfully scaffolded."); }); }, ); await cli.makeCommand( { - name: 'plugin [output-path]', - alias: 'p', - description: 'Scaffold a plugin.', + name: "plugin [output-path]", + alias: "p", + description: "Scaffold a plugin.", argsDescription: { - 'output-path': 'Path to the output directory, e.g. ./pluginName', + "output-path": "Path to the output directory, e.g. ./pluginName", }, - usage: '[output-path] [options]', - pkg: '@webpack-cli/generators', + usage: "[output-path] [options]", + pkg: "@webpack-cli/generators", }, [ { - name: 'template', - alias: 't', - configs: [{ type: 'string' }], - description: 'Type of template', - defaultValue: 'default', + name: "template", + alias: "t", + configs: [{ type: "string" }], + description: "Type of template", + defaultValue: "default", }, ], async (outputPath, options) => { const env = yeoman.createEnv([], { cwd: outputPath }); - const generatorName = 'webpack-plugin-generator'; + const generatorName = "webpack-plugin-generator"; env.registerStub(pluginGenerator, generatorName); env.run(generatorName, { cli, options }, () => { - logger.success('Plugin template has been successfully scaffolded.'); + logger.success("Plugin template has been successfully scaffolded."); }); }, ); diff --git a/packages/generators/src/init-generator.ts b/packages/generators/src/init-generator.ts index 2032b95f353..1006e2aeb5a 100644 --- a/packages/generators/src/init-generator.ts +++ b/packages/generators/src/init-generator.ts @@ -1,12 +1,12 @@ -import { blue, yellow } from 'colorette'; -import path from 'path'; -import * as Question from './utils/scaffold-utils'; +import { blue, yellow } from "colorette"; +import path from "path"; +import * as Question from "./utils/scaffold-utils"; -import { CustomGenerator } from './types'; -import { existsSync, mkdirSync } from 'fs'; -import handlers from './handlers'; +import { CustomGenerator } from "./types"; +import { existsSync, mkdirSync } from "fs"; +import handlers from "./handlers"; -import { readFileSync, writeFileSync } from 'fs'; +import { readFileSync, writeFileSync } from "fs"; /** * @@ -38,7 +38,7 @@ export default class InitGenerator extends CustomGenerator { this.generationPath = options.generationPath; this.resolvedGenerationPath = path.resolve(process.cwd(), this.generationPath); this.force = options.force; - this.dependencies = ['webpack', 'webpack-cli']; + this.dependencies = ["webpack", "webpack-cli"]; this.supportedTemplates = Object.keys(handlers); this.answers = {}; const { cli } = opts; @@ -48,7 +48,11 @@ export default class InitGenerator extends CustomGenerator { // eslint-disable-next-line @typescript-eslint/no-explicit-any public async prompting(): Promise { if (!existsSync(this.resolvedGenerationPath)) { - this.utils.logger.log(`${blue('ℹ INFO ')} supplied generation path doesn't exist, required folders will be created.`); + this.utils.logger.log( + `${blue( + "ℹ INFO ", + )} supplied generation path doesn't exist, required folders will be created.`, + ); try { mkdirSync(this.resolvedGenerationPath, { recursive: true }); } catch (error) { @@ -58,14 +62,16 @@ export default class InitGenerator extends CustomGenerator { } if (!this.supportedTemplates.includes(this.template)) { - this.utils.logger.warn(`⚠ ${this.template} is not a valid template, please select one from below`); + this.utils.logger.warn( + `⚠ ${this.template} is not a valid template, please select one from below`, + ); const { selectedTemplate } = await Question.List( this, - 'selectedTemplate', - 'Select a valid template from below:', + "selectedTemplate", + "Select a valid template from below:", this.supportedTemplates, - 'default', + "default", false, ); @@ -77,18 +83,18 @@ export default class InitGenerator extends CustomGenerator { // Handle installation of prettier try { // eslint-disable-next-line node/no-extraneous-require - require.resolve('prettier'); + require.resolve("prettier"); } catch (err) { const { installPrettier } = await Question.Confirm( this, - 'installPrettier', - 'Do you like to install prettier to format generated configuration?', + "installPrettier", + "Do you like to install prettier to format generated configuration?", true, false, ); if (installPrettier) { - this.dependencies.push('prettier'); + this.dependencies.push("prettier"); } } } @@ -97,14 +103,16 @@ export default class InitGenerator extends CustomGenerator { const packager = this.utils.getPackageManager(); const opts: { dev?: boolean; - 'save-dev'?: boolean; - } = packager === 'yarn' ? { dev: true } : { 'save-dev': true }; + "save-dev"?: boolean; + } = packager === "yarn" ? { dev: true } : { "save-dev": true }; - this.scheduleInstallTask(packager, this.dependencies, opts, { cwd: this.generationPath }); + this.scheduleInstallTask(packager, this.dependencies, opts, { + cwd: this.generationPath, + }); } public writing(): void { - this.utils.logger.log(`${blue('ℹ INFO ')} Initialising project...`); + this.utils.logger.log(`${blue("ℹ INFO ")} Initialising project...`); handlers[this.template].generate(this); } @@ -112,12 +120,20 @@ export default class InitGenerator extends CustomGenerator { // Prettify configuration file if possible try { // eslint-disable-next-line node/no-extraneous-require, @typescript-eslint/no-var-requires - const prettier = require('prettier'); - const source = readFileSync(this.configurationPath, { encoding: 'utf8' }); - const formattedSource = prettier.format(source, { parser: 'babel' }); + const prettier = require("prettier"); + const source = readFileSync(this.configurationPath, { + encoding: "utf8", + }); + const formattedSource = prettier.format(source, { + parser: "babel", + }); writeFileSync(this.configurationPath, formattedSource); } catch (err) { - this.utils.logger.log(`${yellow(`⚠ Generated configuration may not be properly formatted as prettier is not installed.`)}`); + this.utils.logger.log( + `${yellow( + `⚠ Generated configuration may not be properly formatted as prettier is not installed.`, + )}`, + ); return; } } diff --git a/packages/generators/src/loader-generator.ts b/packages/generators/src/loader-generator.ts index 4131e0b1474..fe4ce3c0722 100644 --- a/packages/generators/src/loader-generator.ts +++ b/packages/generators/src/loader-generator.ts @@ -1,6 +1,6 @@ -import path from 'path'; -import addonGenerator from './addon-generator'; -import { toKebabCase } from './utils/helpers'; +import path from "path"; +import addonGenerator from "./addon-generator"; +import { toKebabCase } from "./utils/helpers"; /** * Formats a string into webpack loader format @@ -13,7 +13,7 @@ export function makeLoaderName(name: string): string { name = toKebabCase(name); if (!/loader$/.test(name)) { - name += '-loader'; + name += "-loader"; } return name; @@ -31,15 +31,15 @@ export function makeLoaderName(name: string): string { export const LoaderGenerator = addonGenerator( [ { - default: 'my-loader', + default: "my-loader", filter: makeLoaderName, - message: 'Loader name', - name: 'name', - type: 'input', + message: "Loader name", + name: "name", + type: "input", validate: (str: string): boolean => str.length > 0, }, ], - path.resolve(__dirname, '../loader-template'), + path.resolve(__dirname, "../loader-template"), (gen): Record => ({ name: gen.props.name }), ); diff --git a/packages/generators/src/plugin-generator.ts b/packages/generators/src/plugin-generator.ts index 832775e3e32..3cb8e28f7c2 100644 --- a/packages/generators/src/plugin-generator.ts +++ b/packages/generators/src/plugin-generator.ts @@ -1,6 +1,6 @@ -import path from 'path'; -import addonGenerator from './addon-generator'; -import { toKebabCase, toUpperCamelCase } from './utils/helpers'; +import path from "path"; +import addonGenerator from "./addon-generator"; +import { toKebabCase, toUpperCamelCase } from "./utils/helpers"; /** * A yeoman generator class for creating a webpack @@ -13,16 +13,18 @@ import { toKebabCase, toUpperCamelCase } from './utils/helpers'; export const PluginGenerator = addonGenerator( [ { - default: 'my-webpack-plugin', + default: "my-webpack-plugin", filter: toKebabCase, - message: 'Plugin name', - name: 'name', - type: 'input', + message: "Plugin name", + name: "name", + type: "input", validate: (str: string): boolean => str.length > 0, }, ], - path.resolve(__dirname, '../plugin-template'), - (gen): Record => ({ name: toUpperCamelCase(gen.props.name) }), + path.resolve(__dirname, "../plugin-template"), + (gen): Record => ({ + name: toUpperCamelCase(gen.props.name), + }), ); export default PluginGenerator; diff --git a/packages/generators/src/types/index.ts b/packages/generators/src/types/index.ts index 16b610934ac..142e74184ae 100644 --- a/packages/generators/src/types/index.ts +++ b/packages/generators/src/types/index.ts @@ -1,4 +1,4 @@ -import Generator from 'yeoman-generator'; +import Generator from "yeoman-generator"; export class CustomGenerator extends Generator { public force: boolean; diff --git a/packages/generators/src/update-generator.ts b/packages/generators/src/update-generator.ts index 9f2adbc15de..83e32c6dbda 100644 --- a/packages/generators/src/update-generator.ts +++ b/packages/generators/src/update-generator.ts @@ -1,3 +1,3 @@ -import Generator from 'yeoman-generator'; +import Generator from "yeoman-generator"; export default class UpdateGenerator extends Generator {} diff --git a/packages/generators/src/utils/helpers.ts b/packages/generators/src/utils/helpers.ts index 550c11beca3..1c6291d7877 100644 --- a/packages/generators/src/utils/helpers.ts +++ b/packages/generators/src/utils/helpers.ts @@ -6,7 +6,7 @@ const regex = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+ * @returns output string */ export function toKebabCase(str: string): string { - return str.match(regex).join('-').toLowerCase(); + return str.match(regex).join("-").toLowerCase(); } /** @@ -18,5 +18,5 @@ export function toUpperCamelCase(str: string): string { return str .match(regex) .map((x) => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase()) - .join(''); + .join(""); } diff --git a/packages/generators/src/utils/scaffold-utils.ts b/packages/generators/src/utils/scaffold-utils.ts index c7064a02559..08babde5720 100644 --- a/packages/generators/src/utils/scaffold-utils.ts +++ b/packages/generators/src/utils/scaffold-utils.ts @@ -1,4 +1,4 @@ -import Generator from 'yeoman-generator'; +import Generator from "yeoman-generator"; type CustomGeneratorStringPrompt = { [x: string]: string } | Promise<{ [x: string]: string }>; type CustomGeneratorBoolPrompt = { [x: string]: boolean } | Promise<{ [x: string]: boolean }>; @@ -17,15 +17,21 @@ export function List( return { [name]: defaultChoice }; } - return self.prompt([{ choices, message, name, type: 'list', default: defaultChoice }]); + return self.prompt([{ choices, message, name, type: "list", default: defaultChoice }]); } -export function Input(self: Generator, name: string, message: string, defaultChoice?: string, skip = false): CustomGeneratorStringPrompt { +export function Input( + self: Generator, + name: string, + message: string, + defaultChoice?: string, + skip = false, +): CustomGeneratorStringPrompt { if (skip) { return { [name]: defaultChoice }; } - return self.prompt([{ default: defaultChoice, message, name, type: 'input' }]); + return self.prompt([{ default: defaultChoice, message, name, type: "input" }]); } export function InputValidate( @@ -40,7 +46,12 @@ export function InputValidate( return { [name]: defaultChoice }; } - const input: Generator.Question = { message, name, type: 'input', validate: cb }; + const input: Generator.Question = { + message, + name, + type: "input", + validate: cb, + }; if (defaultChoice) { input.default = defaultChoice; @@ -49,10 +60,16 @@ export function InputValidate( return self.prompt([input]); } -export function Confirm(self: Generator, name: string, message: string, defaultChoice = true, skip = false): CustomGeneratorBoolPrompt { +export function Confirm( + self: Generator, + name: string, + message: string, + defaultChoice = true, + skip = false, +): CustomGeneratorBoolPrompt { if (skip) { return { [name]: defaultChoice }; } - return self.prompt([{ default: defaultChoice, message, name, type: 'confirm' }]); + return self.prompt([{ default: defaultChoice, message, name, type: "confirm" }]); } diff --git a/packages/info/src/index.ts b/packages/info/src/index.ts index 25f2db77d79..fddf308f01c 100644 --- a/packages/info/src/index.ts +++ b/packages/info/src/index.ts @@ -1,4 +1,4 @@ -import envinfo from 'envinfo'; +import envinfo from "envinfo"; interface Information { Binaries?: string[]; @@ -10,23 +10,23 @@ interface Information { } const DEFAULT_DETAILS: Information = { - Binaries: ['Node', 'Yarn', 'npm'], + Binaries: ["Node", "Yarn", "npm"], Browsers: [ - 'Brave Browser', - 'Chrome', - 'Chrome Canary', - 'Edge', - 'Firefox', - 'Firefox Developer Edition', - 'Firefox Nightly', - 'Internet Explorer', - 'Safari', - 'Safari Technology Preview', + "Brave Browser", + "Chrome", + "Chrome Canary", + "Edge", + "Firefox", + "Firefox Developer Edition", + "Firefox Nightly", + "Internet Explorer", + "Safari", + "Safari Technology Preview", ], - Monorepos: ['Yarn Workspaces', 'Lerna'], - System: ['OS', 'CPU', 'Memory'], - npmGlobalPackages: ['webpack', 'webpack-cli'], - npmPackages: '*webpack*', + Monorepos: ["Yarn Workspaces", "Lerna"], + System: ["OS", "CPU", "Memory"], + npmGlobalPackages: ["webpack", "webpack-cli"], + npmPackages: "*webpack*", }; class InfoCommand { @@ -36,22 +36,23 @@ class InfoCommand { await cli.makeCommand( { - name: 'info', - alias: 'i', - description: 'Outputs information about your system.', - usage: '[options]', - pkg: '@webpack-cli/info', + name: "info", + alias: "i", + description: "Outputs information about your system.", + usage: "[options]", + pkg: "@webpack-cli/info", }, [ { - name: 'output', - alias: 'o', + name: "output", + alias: "o", configs: [ { - type: 'string', + type: "string", }, ], - description: 'To get the output in a specified format ( accept json or markdown )', + description: + "To get the output in a specified format ( accept json or markdown )", }, ], async (options) => { @@ -61,14 +62,14 @@ class InfoCommand { if (output) { // Remove quotes if exist - output = output.replace(/['"]+/g, ''); + output = output.replace(/['"]+/g, ""); switch (output) { - case 'markdown': - envinfoConfig['markdown'] = true; + case "markdown": + envinfoConfig["markdown"] = true; break; - case 'json': - envinfoConfig['json'] = true; + case "json": + envinfoConfig["json"] = true; break; default: logger.error(`'${output}' is not a valid value for output`); @@ -78,8 +79,8 @@ class InfoCommand { let info = await envinfo.run(DEFAULT_DETAILS, envinfoConfig); - info = info.replace(/npmPackages/g, 'Packages'); - info = info.replace(/npmGlobalPackages/g, 'Global Packages'); + info = info.replace(/npmPackages/g, "Packages"); + info = info.replace(/npmGlobalPackages/g, "Global Packages"); logger.raw(info); }, diff --git a/packages/serve/src/index.ts b/packages/serve/src/index.ts index 2235c563073..fe4432add48 100644 --- a/packages/serve/src/index.ts +++ b/packages/serve/src/index.ts @@ -1,4 +1,4 @@ -import startDevServer from './startDevServer'; +import startDevServer from "./startDevServer"; class ServeCommand { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any @@ -7,7 +7,7 @@ class ServeCommand { const loadDevServerOptions = () => { // eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-extraneous-require - const options = require('webpack-dev-server/bin/cli-flags'); + const options = require("webpack-dev-server/bin/cli-flags"); // Old options format // { devServer: [{...}, {}...] } @@ -26,12 +26,12 @@ class ServeCommand { await cli.makeCommand( { - name: 'serve [entries...]', - alias: ['server', 's'], - description: 'Run the webpack dev server.', - usage: '[entries...] [options]', - pkg: '@webpack-cli/serve', - dependencies: ['webpack-dev-server'], + name: "serve [entries...]", + alias: ["server", "s"], + description: "Run the webpack dev server.", + usage: "[entries...] [options]", + pkg: "@webpack-cli/serve", + dependencies: ["webpack-dev-server"], }, () => { let devServerFlags = []; @@ -39,11 +39,15 @@ class ServeCommand { try { devServerFlags = loadDevServerOptions(); } catch (error) { - logger.error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${error}`); + logger.error( + `You need to install 'webpack-dev-server' for running 'webpack serve'.\n${error}`, + ); process.exit(2); } - const builtInOptions = cli.getBuiltInOptions().filter((option) => option.name !== 'watch'); + const builtInOptions = cli + .getBuiltInOptions() + .filter((option) => option.name !== "watch"); return [...builtInOptions, ...devServerFlags]; }, @@ -69,13 +73,17 @@ class ServeCommand { const kebabedOption = cli.utils.toKebabCase(optionName); // `webpack-dev-server` has own logic for the `--hot` option const isBuiltInOption = - kebabedOption !== 'hot' && builtInOptions.find((builtInOption) => builtInOption.name === kebabedOption); + kebabedOption !== "hot" && + builtInOptions.find( + (builtInOption) => builtInOption.name === kebabedOption, + ); if (isBuiltInOption) { webpackOptions[optionName] = options[optionName]; } else { const needToProcess = devServerFlags.find( - (devServerOption) => devServerOption.name === kebabedOption && devServerOption.processor, + (devServerOption) => + devServerOption.name === kebabedOption && devServerOption.processor, ); if (needToProcess) { @@ -94,7 +102,10 @@ class ServeCommand { webpackOptions.entry = [...entries, ...(webpackOptions.entry || [])]; } - webpackOptions.argv = { ...options, env: { WEBPACK_SERVE: true, ...options.env } }; + webpackOptions.argv = { + ...options, + env: { WEBPACK_SERVE: true, ...options.env }, + }; const compiler = await cli.createCompiler(webpackOptions); @@ -112,7 +123,7 @@ class ServeCommand { delete devServerOptions.stdin; } - process.stdin.on('end', () => { + process.stdin.on("end", () => { Promise.all( servers.map((server) => { return new Promise((resolve) => { diff --git a/packages/serve/src/startDevServer.ts b/packages/serve/src/startDevServer.ts index e1d7e2fb9aa..e740145daeb 100644 --- a/packages/serve/src/startDevServer.ts +++ b/packages/serve/src/startDevServer.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-var-requires */ -import { devServerOptionsType } from './types'; +import { devServerOptionsType } from "./types"; /** * @@ -25,15 +25,20 @@ export default async function startDevServer( try { // eslint-disable-next-line node/no-extraneous-require - devServerVersion = require('webpack-dev-server/package.json').version; + devServerVersion = require("webpack-dev-server/package.json").version; // eslint-disable-next-line node/no-extraneous-require - Server = require('webpack-dev-server/lib/Server'); + Server = require("webpack-dev-server/lib/Server"); } catch (err) { - logger.error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${err}`); + logger.error( + `You need to install 'webpack-dev-server' for running 'webpack serve'.\n${err}`, + ); process.exit(2); } - const mergeOptions = (devServerOptions: devServerOptionsType, devServerCliOptions: devServerOptionsType): devServerOptionsType => { + const mergeOptions = ( + devServerOptions: devServerOptionsType, + devServerCliOptions: devServerOptionsType, + ): devServerOptionsType => { // CLI options should take precedence over devServer options, // and CLI options should have no default values included const options = { ...devServerOptions, ...devServerCliOptions }; @@ -41,7 +46,10 @@ export default async function startDevServer( if (devServerOptions.client && devServerCliOptions.client) { // the user could set some client options in their devServer config, // then also specify client options on the CLI - options.client = { ...devServerOptions.client, ...devServerCliOptions.client }; + options.client = { + ...devServerOptions.client, + ...devServerCliOptions.client, + }; } return options; @@ -52,7 +60,9 @@ export default async function startDevServer( let compilersWithDevServerOption; if (isMultiCompiler) { - compilersWithDevServerOption = compiler.compilers.filter((compiler) => compiler.options.devServer); + compilersWithDevServerOption = compiler.compilers.filter( + (compiler) => compiler.options.devServer, + ); // No compilers found with the `devServer` option, let's use first compiler if (compilersWithDevServerOption.length === 0) { @@ -62,20 +72,25 @@ export default async function startDevServer( compilersWithDevServerOption = [compiler]; } - const isDevServer4 = devServerVersion.startsWith('4'); + const isDevServer4 = devServerVersion.startsWith("4"); const usedPorts = []; const devServersOptions = []; for (const compilerWithDevServerOption of compilersWithDevServerOption) { - const options = mergeOptions(compilerWithDevServerOption.options.devServer || {}, devServerCliOptions); + const options = mergeOptions( + compilerWithDevServerOption.options.devServer || {}, + devServerCliOptions, + ); if (!isDevServer4) { const getPublicPathOption = (): string => { const normalizePublicPath = (publicPath): string => - typeof publicPath === 'undefined' || publicPath === 'auto' ? '/' : publicPath; + typeof publicPath === "undefined" || publicPath === "auto" ? "/" : publicPath; if (cliOptions.outputPublicPath) { - return normalizePublicPath(compilerWithDevServerOption.options.output.publicPath); + return normalizePublicPath( + compilerWithDevServerOption.options.output.publicPath, + ); } // webpack-dev-server@3 @@ -97,7 +112,7 @@ export default async function startDevServer( return compilerWithDevServerOption.options.stats; }; - options.host = options.host || 'localhost'; + options.host = options.host || "localhost"; options.port = options.port || 8080; options.stats = getStatsOption(); options.publicPath = getPublicPathOption(); @@ -108,7 +123,7 @@ export default async function startDevServer( if (usedPorts.find((port) => portNumber === port)) { throw new Error( - 'Unique ports must be specified for each devServer option in your webpack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.', + "Unique ports must be specified for each devServer option in your webpack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.", ); } diff --git a/packages/serve/src/types.ts b/packages/serve/src/types.ts index 2195684f43d..8eefb21c0ca 100644 --- a/packages/serve/src/types.ts +++ b/packages/serve/src/types.ts @@ -37,7 +37,7 @@ export type devServerOptionsType = { }; enum hotOptionEnum { - only = 'only', + only = "only", } type devServerClientOptions = { @@ -62,10 +62,10 @@ type clientOverlay = { }; enum devServerClientLogging { - none = 'none', - error = 'error', - warn = 'warn', - info = 'info', - log = 'log', - verbose = 'verbose', + none = "none", + error = "error", + warn = "warn", + info = "info", + log = "log", + verbose = "verbose", } diff --git a/packages/webpack-cli/bin/cli.js b/packages/webpack-cli/bin/cli.js index 9a9f5f02a59..d62a625831c 100755 --- a/packages/webpack-cli/bin/cli.js +++ b/packages/webpack-cli/bin/cli.js @@ -1,16 +1,16 @@ #!/usr/bin/env node -'use strict'; +"use strict"; -const Module = require('module'); +const Module = require("module"); const originalModuleCompile = Module.prototype._compile; -require('v8-compile-cache'); +require("v8-compile-cache"); -const importLocal = require('import-local'); -const runCLI = require('../lib/bootstrap'); -const utils = require('../lib/utils'); +const importLocal = require("import-local"); +const runCLI = require("../lib/bootstrap"); +const utils = require("../lib/utils"); if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) { // Prefer the local installation of `webpack-cli` @@ -19,23 +19,27 @@ if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) { } } -process.title = 'webpack'; +process.title = "webpack"; -if (utils.packageExists('webpack')) { +if (utils.packageExists("webpack")) { runCLI(process.argv, originalModuleCompile); } else { const { promptInstallation, logger, colors } = utils; - promptInstallation('webpack', () => { - utils.logger.error(`It looks like ${colors.bold('webpack')} is not installed.`); + promptInstallation("webpack", () => { + utils.logger.error(`It looks like ${colors.bold("webpack")} is not installed.`); }) .then(() => { - logger.success(`${colors.bold('webpack')} was installed successfully.`); + logger.success(`${colors.bold("webpack")} was installed successfully.`); runCLI(process.argv, originalModuleCompile); }) .catch(() => { - logger.error(`Action Interrupted, Please try once again or install ${colors.bold('webpack')} manually.`); + logger.error( + `Action Interrupted, Please try once again or install ${colors.bold( + "webpack", + )} manually.`, + ); process.exit(2); }); diff --git a/packages/webpack-cli/lib/bootstrap.js b/packages/webpack-cli/lib/bootstrap.js index 0a83a81c9e2..72499f8a364 100644 --- a/packages/webpack-cli/lib/bootstrap.js +++ b/packages/webpack-cli/lib/bootstrap.js @@ -1,5 +1,5 @@ -const WebpackCLI = require('./webpack-cli'); -const utils = require('./utils'); +const WebpackCLI = require("./webpack-cli"); +const utils = require("./utils"); const runCLI = async (args, originalModuleCompile) => { try { diff --git a/packages/webpack-cli/lib/index.js b/packages/webpack-cli/lib/index.js index 0af01e8eb7c..76a626301f7 100644 --- a/packages/webpack-cli/lib/index.js +++ b/packages/webpack-cli/lib/index.js @@ -1,5 +1,5 @@ -const CLI = require('./webpack-cli'); -const utils = require('./utils'); +const CLI = require("./webpack-cli"); +const utils = require("./utils"); module.exports = CLI; module.exports.utils = utils; diff --git a/packages/webpack-cli/lib/plugins/CLIPlugin.js b/packages/webpack-cli/lib/plugins/CLIPlugin.js index c9a0963431c..7668857d341 100644 --- a/packages/webpack-cli/lib/plugins/CLIPlugin.js +++ b/packages/webpack-cli/lib/plugins/CLIPlugin.js @@ -4,8 +4,10 @@ class CLIPlugin { } setupHotPlugin(compiler) { - const { HotModuleReplacementPlugin } = compiler.webpack || require('webpack'); - const hotModuleReplacementPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin)); + const { HotModuleReplacementPlugin } = compiler.webpack || require("webpack"); + const hotModuleReplacementPlugin = Boolean( + compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin), + ); if (!hotModuleReplacementPlugin) { new HotModuleReplacementPlugin().apply(compiler); @@ -13,15 +15,17 @@ class CLIPlugin { } setupPrefetchPlugin(compiler) { - const { PrefetchPlugin } = compiler.webpack || require('webpack'); + const { PrefetchPlugin } = compiler.webpack || require("webpack"); new PrefetchPlugin(null, this.options.prefetch).apply(compiler); } async setupBundleAnalyzerPlugin(compiler) { // eslint-disable-next-line node/no-extraneous-require - const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); - const bundleAnalyzerPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof BundleAnalyzerPlugin)); + const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); + const bundleAnalyzerPlugin = Boolean( + compiler.options.plugins.find((plugin) => plugin instanceof BundleAnalyzerPlugin), + ); if (!bundleAnalyzerPlugin) { new BundleAnalyzerPlugin().apply(compiler); @@ -29,17 +33,21 @@ class CLIPlugin { } setupProgressPlugin(compiler) { - const { ProgressPlugin } = compiler.webpack || require('webpack'); - const progressPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin)); + const { ProgressPlugin } = compiler.webpack || require("webpack"); + const progressPlugin = Boolean( + compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin), + ); if (!progressPlugin) { - new ProgressPlugin({ profile: this.options.progress === 'profile' }).apply(compiler); + new ProgressPlugin({ + profile: this.options.progress === "profile", + }).apply(compiler); } } setupHelpfulOutput(compiler) { - const pluginName = 'webpack-cli'; - const getCompilationName = () => (compiler.name ? `'${compiler.name}'` : ''); + const pluginName = "webpack-cli"; + const getCompilationName = () => (compiler.name ? `'${compiler.name}'` : ""); const logCompilation = (message) => { if (process.env.WEBPACK_CLI_START_FINISH_FORCE_LOG) { process.stderr.write(message); @@ -53,10 +61,12 @@ class CLIPlugin { compiler.hooks.run.tap(pluginName, () => { const name = getCompilationName(); - logCompilation(`Compiler${name ? ` ${name}` : ''} starting... `); + logCompilation(`Compiler${name ? ` ${name}` : ""} starting... `); if (configPath) { - this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`); + this.logger.log( + `Compiler${name ? ` ${name}` : ""} is using config: '${configPath}'`, + ); } }); @@ -64,15 +74,19 @@ class CLIPlugin { const { bail, watch } = compiler.options; if (bail && watch) { - this.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.', + ); } const name = getCompilationName(); - logCompilation(`Compiler${name ? ` ${name}` : ''} starting... `); + logCompilation(`Compiler${name ? ` ${name}` : ""} starting... `); if (configPath) { - this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`); + this.logger.log( + `Compiler${name ? ` ${name}` : ""} is using config: '${configPath}'`, + ); } }); @@ -86,18 +100,20 @@ class CLIPlugin { (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, () => { const name = getCompilationName(); - logCompilation(`Compiler${name ? ` ${name}` : ''} finished`); + logCompilation(`Compiler${name ? ` ${name}` : ""} finished`); process.nextTick(() => { if (compiler.watchMode) { - this.logger.log(`Compiler${name ? `${name}` : ''} is watching files for updates...`); + this.logger.log( + `Compiler${name ? `${name}` : ""} is watching files for updates...`, + ); } }); }); } apply(compiler) { - this.logger = compiler.getInfrastructureLogger('webpack-cli'); + this.logger = compiler.getInfrastructureLogger("webpack-cli"); if (this.options.progress) { this.setupProgressPlugin(compiler); diff --git a/packages/webpack-cli/lib/utils/capitalize-first-letter.js b/packages/webpack-cli/lib/utils/capitalize-first-letter.js index 3ddf802630a..e8c129e2a86 100644 --- a/packages/webpack-cli/lib/utils/capitalize-first-letter.js +++ b/packages/webpack-cli/lib/utils/capitalize-first-letter.js @@ -1,6 +1,6 @@ const capitalizeFirstLetter = (string) => { - if (typeof string !== 'string') { - return ''; + if (typeof string !== "string") { + return ""; } return string.charAt(0).toUpperCase() + string.slice(1); diff --git a/packages/webpack-cli/lib/utils/dynamic-import-loader.js b/packages/webpack-cli/lib/utils/dynamic-import-loader.js index a9dbedc197b..6981496934e 100644 --- a/packages/webpack-cli/lib/utils/dynamic-import-loader.js +++ b/packages/webpack-cli/lib/utils/dynamic-import-loader.js @@ -2,7 +2,7 @@ function dynamicImportLoader() { let importESM; try { - importESM = new Function('id', 'return import(id);'); + importESM = new Function("id", "return import(id);"); } catch (e) { importESM = null; } diff --git a/packages/webpack-cli/lib/utils/get-package-manager.js b/packages/webpack-cli/lib/utils/get-package-manager.js index 616e64b31c2..fa67d192810 100644 --- a/packages/webpack-cli/lib/utils/get-package-manager.js +++ b/packages/webpack-cli/lib/utils/get-package-manager.js @@ -1,8 +1,8 @@ -const fs = require('fs'); -const path = require('path'); -const { sync } = require('execa'); +const fs = require("fs"); +const path = require("path"); +const { sync } = require("execa"); -const utils = require('./index'); +const utils = require("./index"); /** * @@ -12,29 +12,29 @@ const utils = require('./index'); * @returns {String} - The package manager name */ function getPackageManager() { - const hasLocalNpm = fs.existsSync(path.resolve(process.cwd(), 'package-lock.json')); + const hasLocalNpm = fs.existsSync(path.resolve(process.cwd(), "package-lock.json")); if (hasLocalNpm) { - return 'npm'; + return "npm"; } - const hasLocalYarn = fs.existsSync(path.resolve(process.cwd(), 'yarn.lock')); + const hasLocalYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); if (hasLocalYarn) { - return 'yarn'; + return "yarn"; } - const hasLocalPnpm = fs.existsSync(path.resolve(process.cwd(), 'pnpm-lock.yaml')); + const hasLocalPnpm = fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml")); if (hasLocalPnpm) { - return 'pnpm'; + return "pnpm"; } try { // the sync function below will fail if npm is not installed, // an error will be thrown - if (sync('npm', ['--version'])) { - return 'npm'; + if (sync("npm", ["--version"])) { + return "npm"; } } catch (e) { // Nothing @@ -43,8 +43,8 @@ function getPackageManager() { try { // the sync function below will fail if yarn is not installed, // an error will be thrown - if (sync('yarn', ['--version'])) { - return 'yarn'; + if (sync("yarn", ["--version"])) { + return "yarn"; } } catch (e) { // Nothing @@ -53,11 +53,11 @@ function getPackageManager() { try { // the sync function below will fail if pnpm is not installed, // an error will be thrown - if (sync('pnpm', ['--version'])) { - return 'pnpm'; + if (sync("pnpm", ["--version"])) { + return "pnpm"; } } catch (e) { - utils.logger.error('No package manager found.'); + utils.logger.error("No package manager found."); process.exit(2); } } diff --git a/packages/webpack-cli/lib/utils/index.js b/packages/webpack-cli/lib/utils/index.js index 045c98f2aab..800174bec22 100644 --- a/packages/webpack-cli/lib/utils/index.js +++ b/packages/webpack-cli/lib/utils/index.js @@ -1,49 +1,49 @@ module.exports = { get colors() { - return require('colorette'); + return require("colorette"); }, get levenshtein() { - return require('fastest-levenshtein'); + return require("fastest-levenshtein"); }, get interpret() { - return require('interpret'); + return require("interpret"); }, get rechoir() { - return require('rechoir'); + return require("rechoir"); }, get capitalizeFirstLetter() { - return require('./capitalize-first-letter'); + return require("./capitalize-first-letter"); }, get dynamicImportLoader() { - return require('./dynamic-import-loader'); + return require("./dynamic-import-loader"); }, get getPackageManager() { - return require('./get-package-manager'); + return require("./get-package-manager"); }, get logger() { - return require('./logger'); + return require("./logger"); }, get packageExists() { - return require('./package-exists'); + return require("./package-exists"); }, get promptInstallation() { - return require('./prompt-installation'); + return require("./prompt-installation"); }, get runCommand() { - return require('./run-command'); + return require("./run-command"); }, get toKebabCase() { - return require('./to-kebab-case'); + return require("./to-kebab-case"); }, }; diff --git a/packages/webpack-cli/lib/utils/logger.js b/packages/webpack-cli/lib/utils/logger.js index b0d37baafd8..88ee114bb1d 100644 --- a/packages/webpack-cli/lib/utils/logger.js +++ b/packages/webpack-cli/lib/utils/logger.js @@ -1,5 +1,5 @@ -const utils = require('./index'); -const util = require('util'); +const utils = require("./index"); +const util = require("util"); module.exports = { error: (val) => console.error(`[webpack-cli] ${utils.colors.red(util.format(val))}`), diff --git a/packages/webpack-cli/lib/utils/prompt-installation.js b/packages/webpack-cli/lib/utils/prompt-installation.js index ef029f9c0ba..10794efe224 100644 --- a/packages/webpack-cli/lib/utils/prompt-installation.js +++ b/packages/webpack-cli/lib/utils/prompt-installation.js @@ -1,5 +1,5 @@ -const utils = require('./index'); -const prompt = require('./prompt'); +const utils = require("./index"); +const prompt = require("./prompt"); /** * @@ -19,17 +19,23 @@ async function promptInstallation(packageName, preMessage) { } // yarn uses 'add' command, rest npm and pnpm both use 'install' - const commandToBeRun = `${packageManager} ${[packageManager === 'yarn' ? 'add' : 'install', '-D', packageName].join(' ')}`; + const commandToBeRun = `${packageManager} ${[ + packageManager === "yarn" ? "add" : "install", + "-D", + packageName, + ].join(" ")}`; const { colors } = utils; let installConfirm; try { installConfirm = await prompt({ - message: `[webpack-cli] Would you like to install '${colors.green(packageName)}' package? (That will run '${colors.green( - commandToBeRun, - )}') (${colors.yellow('Y/n')})`, - defaultResponse: 'Y', + message: `[webpack-cli] Would you like to install '${colors.green( + packageName, + )}' package? (That will run '${colors.green(commandToBeRun)}') (${colors.yellow( + "Y/n", + )})`, + defaultResponse: "Y", stream: process.stderr, }); } catch (error) { diff --git a/packages/webpack-cli/lib/utils/prompt.js b/packages/webpack-cli/lib/utils/prompt.js index b8fbdf29fed..e28b944b2a1 100644 --- a/packages/webpack-cli/lib/utils/prompt.js +++ b/packages/webpack-cli/lib/utils/prompt.js @@ -1,5 +1,5 @@ const prompt = ({ message, defaultResponse, stream }) => { - const readline = require('readline'); + const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: stream, @@ -13,7 +13,7 @@ const prompt = ({ message, defaultResponse, stream }) => { const response = (answer || defaultResponse).toLowerCase(); // Resolve with the input response - if (response === 'y' || response === 'yes') { + if (response === "y" || response === "yes") { resolve(true); } else { resolve(false); diff --git a/packages/webpack-cli/lib/utils/run-command.js b/packages/webpack-cli/lib/utils/run-command.js index 58463661c27..62b75da9e69 100644 --- a/packages/webpack-cli/lib/utils/run-command.js +++ b/packages/webpack-cli/lib/utils/run-command.js @@ -1,9 +1,9 @@ -const execa = require('execa'); -const utils = require('./index'); +const execa = require("execa"); +const utils = require("./index"); async function runCommand(command, args = []) { try { - await execa(command, args, { stdio: 'inherit', shell: true }); + await execa(command, args, { stdio: "inherit", shell: true }); } catch (error) { utils.logger.error(error.message); process.exit(2); diff --git a/packages/webpack-cli/lib/utils/to-kebab-case.js b/packages/webpack-cli/lib/utils/to-kebab-case.js index fb241fbdc94..be7e976a3c7 100644 --- a/packages/webpack-cli/lib/utils/to-kebab-case.js +++ b/packages/webpack-cli/lib/utils/to-kebab-case.js @@ -1,5 +1,5 @@ const toKebabCase = (str) => { - return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase(); + return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(); }; module.exports = toKebabCase; diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index cd39489449a..eca0feaa275 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -1,30 +1,35 @@ -const fs = require('fs'); -const path = require('path'); -const { pathToFileURL } = require('url'); -const Module = require('module'); +const fs = require("fs"); +const path = require("path"); +const { pathToFileURL } = require("url"); +const Module = require("module"); -const { program, Option } = require('commander'); -const utils = require('./utils'); +const { program, Option } = require("commander"); +const utils = require("./utils"); class WebpackCLI { constructor() { // Global - this.webpack = require(process.env.WEBPACK_PACKAGE || 'webpack'); + this.webpack = require(process.env.WEBPACK_PACKAGE || "webpack"); this.logger = utils.logger; this.utils = utils; // Initialize program this.program = program; - this.program.name('webpack'); + this.program.name("webpack"); this.program.configureOutput({ writeErr: this.logger.error, - outputError: (str, write) => write(`Error: ${this.utils.capitalizeFirstLetter(str.replace(/^error:/, '').trim())}`), + outputError: (str, write) => + write( + `Error: ${this.utils.capitalizeFirstLetter(str.replace(/^error:/, "").trim())}`, + ), }); } async makeCommand(commandOptions, options, action) { const alreadyLoaded = this.program.commands.find( - (command) => command.name() === commandOptions.name.split(' ')[0] || command.aliases().includes(commandOptions.alias), + (command) => + command.name() === commandOptions.name.split(" ")[0] || + command.aliases().includes(commandOptions.alias), ); if (alreadyLoaded) { @@ -54,7 +59,7 @@ class WebpackCLI { if (commandOptions.pkg) { command.pkg = commandOptions.pkg; } else { - command.pkg = 'webpack-cli'; + command.pkg = "webpack-cli"; } const { forHelp } = this.program; @@ -77,21 +82,23 @@ class WebpackCLI { await promptInstallation(dependency, () => { this.logger.error( - `For using '${colors.green(commandOptions.name.split(' ')[0])}' command you need to install: '${colors.green( - dependency, - )}' package`, + `For using '${colors.green( + commandOptions.name.split(" ")[0], + )}' command you need to install: '${colors.green(dependency)}' package`, ); }); } } if (options) { - if (typeof options === 'function') { + if (typeof options === "function") { if (forHelp && !allDependenciesInstalled) { command.description( - `${commandOptions.description} To see all available options you need to install ${commandOptions.dependencies + `${ + commandOptions.description + } To see all available options you need to install ${commandOptions.dependencies .map((dependency) => `'${dependency}'`) - .join(',')}.`, + .join(",")}.`, ); options = []; } else { @@ -120,36 +127,36 @@ class WebpackCLI { option.configs.forEach((config) => { // Possible value: "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset" switch (config.type) { - case 'reset': + case "reset": mainOptionType.add(Boolean); break; - case 'boolean': + case "boolean": if (!needNegativeOption) { needNegativeOption = true; } mainOptionType.add(Boolean); break; - case 'number': + case "number": mainOptionType.add(Number); break; - case 'string': - case 'path': - case 'RegExp': + case "string": + case "path": + case "RegExp": mainOptionType.add(String); break; - case 'enum': { + case "enum": { let hasFalseEnum = false; const enumTypes = config.values.map((value) => { switch (typeof value) { - case 'string': + case "string": mainOptionType.add(String); break; - case 'number': + case "number": mainOptionType.add(Number); break; - case 'boolean': + case "boolean": if (!hasFalseEnum && value === false) { hasFalseEnum = true; break; @@ -171,7 +178,7 @@ class WebpackCLI { mainOption = { flags: option.alias ? `-${option.alias}, --${option.name}` : `--${option.name}`, - description: option.description || '', + description: option.description || "", type: mainOptionType, multiple: option.multiple, defaultValue: option.defaultValue, @@ -180,15 +187,19 @@ class WebpackCLI { if (needNegativeOption) { negativeOption = { flags: `--no-${option.name}`, - description: option.negatedDescription ? option.negatedDescription : `Negative '${option.name}' option.`, + description: option.negatedDescription + ? option.negatedDescription + : `Negative '${option.name}' option.`, }; } } else { mainOption = { flags: option.alias ? `-${option.alias}, --${option.name}` : `--${option.name}`, // TODO `describe` used by `webpack-dev-server@3` - description: option.description || option.describe || '', - type: option.type ? new Set(Array.isArray(option.type) ? option.type : [option.type]) : new Set([Boolean]), + description: option.description || option.describe || "", + type: option.type + ? new Set(Array.isArray(option.type) ? option.type : [option.type]) + : new Set([Boolean]), multiple: option.multiple, defaultValue: option.defaultValue, }; @@ -196,15 +207,17 @@ class WebpackCLI { if (option.negative) { negativeOption = { flags: `--no-${option.name}`, - description: option.negatedDescription ? option.negatedDescription : `Negative '${option.name}' option.`, + description: option.negatedDescription + ? option.negatedDescription + : `Negative '${option.name}' option.`, }; } } if (mainOption.type.size > 1 && mainOption.type.has(Boolean)) { - mainOption.flags = `${mainOption.flags} [value${mainOption.multiple ? '...' : ''}]`; + mainOption.flags = `${mainOption.flags} [value${mainOption.multiple ? "..." : ""}]`; } else if (mainOption.type.size > 0 && !mainOption.type.has(Boolean)) { - mainOption.flags = `${mainOption.flags} `; + mainOption.flags = `${mainOption.flags} `; } if (mainOption.type.size === 1) { @@ -218,7 +231,9 @@ class WebpackCLI { skipDefault = false; } - return mainOption.multiple ? [].concat(prev).concat(Number(value)) : Number(value); + return mainOption.multiple + ? [].concat(prev).concat(Number(value)) + : Number(value); }) .default(mainOption.defaultValue); @@ -243,7 +258,10 @@ class WebpackCLI { command.addOption(optionForCommand); } else if (mainOption.type.has(Boolean)) { - const optionForCommand = new Option(mainOption.flags, mainOption.description).default(mainOption.defaultValue); + const optionForCommand = new Option( + mainOption.flags, + mainOption.description, + ).default(mainOption.defaultValue); optionForCommand.helpLevel = option.helpLevel; @@ -260,7 +278,11 @@ class WebpackCLI { } else if (mainOption.type.size > 1) { let skipDefault = true; - const optionForCommand = new Option(mainOption.flags, mainOption.description, mainOption.defaultValue) + const optionForCommand = new Option( + mainOption.flags, + mainOption.description, + mainOption.defaultValue, + ) .argParser((value, prev = []) => { if (mainOption.defaultValue && mainOption.multiple && skipDefault) { prev = []; @@ -271,7 +293,9 @@ class WebpackCLI { const numberValue = Number(value); if (!isNaN(numberValue)) { - return mainOption.multiple ? [].concat(prev).concat(numberValue) : numberValue; + return mainOption.multiple + ? [].concat(prev).concat(numberValue) + : numberValue; } } @@ -311,53 +335,54 @@ class WebpackCLI { } const minimumHelpFlags = [ - 'config', - 'config-name', - 'merge', - 'env', - 'mode', - 'watch', - 'watch-options-stdin', - 'stats', - 'devtool', - 'entry', - 'target', - 'progress', - 'json', - 'name', - 'output-path', - 'node-env', + "config", + "config-name", + "merge", + "env", + "mode", + "watch", + "watch-options-stdin", + "stats", + "devtool", + "entry", + "target", + "progress", + "json", + "name", + "output-path", + "node-env", ]; const builtInFlags = [ // For configs { - name: 'config', - alias: 'c', + name: "config", + alias: "c", configs: [ { - type: 'string', + type: "string", }, ], multiple: true, - description: 'Provide path to a webpack configuration file e.g. ./webpack.config.js.', + description: + "Provide path to a webpack configuration file e.g. ./webpack.config.js.", }, { - name: 'config-name', + name: "config-name", configs: [ { - type: 'string', + type: "string", }, ], multiple: true, - description: 'Name of the configuration to use.', + description: "Name of the configuration to use.", }, { - name: 'merge', - alias: 'm', + name: "merge", + alias: "m", configs: [ { - type: 'enum', + type: "enum", values: [true], }, ], @@ -365,10 +390,10 @@ class WebpackCLI { }, // Complex configs { - name: 'env', + name: "env", type: (value, previous = {}) => { // for https://github.com/webpack/webpack-cli/issues/2642 - if (value.endsWith('=')) { + if (value.endsWith("=")) { value.concat('""'); } @@ -383,12 +408,12 @@ class WebpackCLI { prevRef[someKey] = {}; } - if (typeof prevRef[someKey] === 'string') { + if (typeof prevRef[someKey] === "string") { prevRef[someKey] = {}; } if (index === splitKeys.length - 1) { - if (typeof val === 'string') { + if (typeof val === "string") { prevRef[someKey] = val; } else { prevRef[someKey] = true; @@ -401,187 +426,188 @@ class WebpackCLI { return previous; }, multiple: true, - description: 'Environment passed to the configuration when it is a function.', + description: "Environment passed to the configuration when it is a function.", }, { - name: 'node-env', + name: "node-env", configs: [ { - type: 'string', + type: "string", }, ], multiple: false, - description: 'Sets process.env.NODE_ENV to the specified value.', + description: "Sets process.env.NODE_ENV to the specified value.", }, // Adding more plugins { - name: 'hot', - alias: 'h', + name: "hot", + alias: "h", configs: [ { - type: 'string', + type: "string", }, { - type: 'boolean', + type: "boolean", }, ], negative: true, - description: 'Enables Hot Module Replacement', - negatedDescription: 'Disables Hot Module Replacement.', + description: "Enables Hot Module Replacement", + negatedDescription: "Disables Hot Module Replacement.", }, { - name: 'analyze', + name: "analyze", configs: [ { - type: 'enum', + type: "enum", values: [true], }, ], multiple: false, - description: 'It invokes webpack-bundle-analyzer plugin to get bundle information.', + description: "It invokes webpack-bundle-analyzer plugin to get bundle information.", }, { - name: 'progress', + name: "progress", configs: [ { - type: 'string', + type: "string", }, { - type: 'enum', + type: "enum", values: [true], }, ], - description: 'Print compilation progress during build.', + description: "Print compilation progress during build.", }, { - name: 'prefetch', + name: "prefetch", configs: [ { - type: 'string', + type: "string", }, ], - description: 'Prefetch this request.', + description: "Prefetch this request.", }, // Output options { - name: 'json', + name: "json", configs: [ { - type: 'string', + type: "string", }, { - type: 'enum', + type: "enum", values: [true], }, ], - alias: 'j', - description: 'Prints result as JSON or store it in a file.', + alias: "j", + description: "Prints result as JSON or store it in a file.", }, // For webpack@4 { - name: 'entry', + name: "entry", configs: [ { - type: 'string', + type: "string", }, ], multiple: true, - description: 'The entry point(s) of your application e.g. ./src/main.js.', + description: "The entry point(s) of your application e.g. ./src/main.js.", }, { - name: 'output-path', - alias: 'o', + name: "output-path", + alias: "o", configs: [ { - type: 'string', + type: "string", }, ], - description: 'Output location of the file generated by webpack e.g. ./dist/.', + description: "Output location of the file generated by webpack e.g. ./dist/.", }, { - name: 'target', - alias: 't', + name: "target", + alias: "t", configs: [ { - type: 'string', + type: "string", }, ], multiple: this.webpack.cli !== undefined, - description: 'Sets the build target e.g. node.', + description: "Sets the build target e.g. node.", }, { - name: 'devtool', + name: "devtool", configs: [ { - type: 'string', + type: "string", }, { - type: 'enum', + type: "enum", values: [false], }, ], negative: true, - alias: 'd', - description: 'Determine source maps to use.', - negatedDescription: 'Do not generate source maps.', + alias: "d", + description: "Determine source maps to use.", + negatedDescription: "Do not generate source maps.", }, { - name: 'mode', + name: "mode", configs: [ { - type: 'string', + type: "string", }, ], - description: 'Defines the mode to pass to webpack.', + description: "Defines the mode to pass to webpack.", }, { - name: 'name', + name: "name", configs: [ { - type: 'string', + type: "string", }, ], - description: 'Name of the configuration. Used when loading multiple configurations.', + description: + "Name of the configuration. Used when loading multiple configurations.", }, { - name: 'stats', + name: "stats", configs: [ { - type: 'string', + type: "string", }, { - type: 'boolean', + type: "boolean", }, ], negative: true, - description: 'It instructs webpack on how to treat the stats e.g. verbose.', - negatedDescription: 'Disable stats output.', + description: "It instructs webpack on how to treat the stats e.g. verbose.", + negatedDescription: "Disable stats output.", }, { - name: 'watch', + name: "watch", configs: [ { - type: 'boolean', + type: "boolean", }, ], negative: true, - alias: 'w', - description: 'Watch for files changes.', - negatedDescription: 'Do not watch for file changes.', + alias: "w", + description: "Watch for files changes.", + negatedDescription: "Do not watch for file changes.", }, { - name: 'watch-options-stdin', + name: "watch-options-stdin", configs: [ { - type: 'boolean', + type: "boolean", }, ], negative: true, - description: 'Stop watching when stdin stream has ended.', - negatedDescription: 'Do not stop watching when stdin stream has ended.', + description: "Stop watching when stdin stream has ended.", + negatedDescription: "Do not stop watching when stdin stream has ended.", }, ]; @@ -592,18 +618,29 @@ class WebpackCLI { const inBuiltIn = builtInFlags.find((builtInFlag) => builtInFlag.name === flag); if (inBuiltIn) { - return { ...meta, name: flag, group: 'core', ...inBuiltIn, configs: meta.configs || [] }; + return { + ...meta, + name: flag, + group: "core", + ...inBuiltIn, + configs: meta.configs || [], + }; } - return { ...meta, name: flag, group: 'core' }; + return { ...meta, name: flag, group: "core" }; }) : []; const options = [] - .concat(builtInFlags.filter((builtInFlag) => !coreFlags.find((coreFlag) => builtInFlag.name === coreFlag.name))) + .concat( + builtInFlags.filter( + (builtInFlag) => + !coreFlags.find((coreFlag) => builtInFlag.name === coreFlag.name), + ), + ) .concat(coreFlags) .map((option) => { - option.helpLevel = minimumHelpFlags.includes(option.name) ? 'minimum' : 'verbose'; + option.helpLevel = minimumHelpFlags.includes(option.name) ? "minimum" : "verbose"; return option; }); @@ -614,7 +651,7 @@ class WebpackCLI { } applyNodeEnv(options) { - if (typeof options.nodeEnv === 'string') { + if (typeof options.nodeEnv === "string") { process.env.NODE_ENV = options.nodeEnv; } } @@ -622,63 +659,64 @@ class WebpackCLI { async run(args, parseOptions) { // Built-in internal commands const buildCommandOptions = { - name: 'build [entries...]', - alias: ['bundle', 'b'], - description: 'Run webpack (default command, can be omitted).', - usage: '[entries...] [options]', + name: "build [entries...]", + alias: ["bundle", "b"], + description: "Run webpack (default command, can be omitted).", + usage: "[entries...] [options]", }; const watchCommandOptions = { - name: 'watch [entries...]', - alias: 'w', - description: 'Run webpack and watch for files changes.', - usage: '[entries...] [options]', + name: "watch [entries...]", + alias: "w", + description: "Run webpack and watch for files changes.", + usage: "[entries...] [options]", }; const versionCommandOptions = { - name: 'version [commands...]', - alias: 'v', - description: "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", + name: "version [commands...]", + alias: "v", + description: + "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", }; const helpCommandOptions = { - name: 'help [command] [option]', - alias: 'h', - description: 'Display help for commands and options.', + name: "help [command] [option]", + alias: "h", + description: "Display help for commands and options.", }; // Built-in external commands const externalBuiltInCommandsInfo = [ { - name: 'serve [entries...]', - alias: ['server', 's'], - pkg: '@webpack-cli/serve', + name: "serve [entries...]", + alias: ["server", "s"], + pkg: "@webpack-cli/serve", }, { - name: 'info', - alias: 'i', - pkg: '@webpack-cli/info', + name: "info", + alias: "i", + pkg: "@webpack-cli/info", }, { - name: 'init', - alias: ['create', 'new', 'c', 'n'], - pkg: '@webpack-cli/generators', + name: "init", + alias: ["create", "new", "c", "n"], + pkg: "@webpack-cli/generators", }, { - name: 'loader', - alias: 'l', - pkg: '@webpack-cli/generators', + name: "loader", + alias: "l", + pkg: "@webpack-cli/generators", }, { - name: 'plugin', - alias: 'p', - pkg: '@webpack-cli/generators', + name: "plugin", + alias: "p", + pkg: "@webpack-cli/generators", }, { - name: 'migrate', - alias: 'm', - pkg: '@webpack-cli/migrate', + name: "migrate", + alias: "m", + pkg: "@webpack-cli/migrate", }, { - name: 'configtest [config-path]', - alias: 't', - pkg: '@webpack-cli/configtest', + name: "configtest [config-path]", + alias: "t", + pkg: "@webpack-cli/configtest", }, ]; @@ -689,12 +727,14 @@ class WebpackCLI { helpCommandOptions, ...externalBuiltInCommandsInfo, ]; - const getCommandName = (name) => name.split(' ')[0]; + const getCommandName = (name) => name.split(" ")[0]; const isKnownCommand = (name) => knownCommands.find( (command) => getCommandName(command.name) === name || - (Array.isArray(command.alias) ? command.alias.includes(name) : command.alias === name), + (Array.isArray(command.alias) + ? command.alias.includes(name) + : command.alias === name), ); const isCommand = (input, commandOptions) => { const longName = getCommandName(commandOptions.name); @@ -714,15 +754,17 @@ class WebpackCLI { return false; }; const findCommandByName = (name) => - this.program.commands.find((command) => name === command.name() || command.aliases().includes(name)); - const isOption = (value) => value.startsWith('-'); + this.program.commands.find( + (command) => name === command.name() || command.aliases().includes(name), + ); + const isOption = (value) => value.startsWith("-"); const isGlobalOption = (value) => - value === '--color' || - value === '--no-color' || - value === '-v' || - value === '--version' || - value === '-h' || - value === '--help'; + value === "--color" || + value === "--no-color" || + value === "-v" || + value === "--version" || + value === "-h" || + value === "--help"; const loadCommandByName = async (commandName, allowToInstall = false) => { const isBuildCommandUsed = isCommand(commandName, buildCommandOptions); @@ -733,7 +775,9 @@ class WebpackCLI { await this.makeCommand( isBuildCommandUsed ? buildCommandOptions : watchCommandOptions, - isWatchCommandUsed ? options.filter((option) => option.name !== 'watch') : options, + isWatchCommandUsed + ? options.filter((option) => option.name !== "watch") + : options, async (entries, options) => { if (entries.length > 0) { options.entry = [...entries, ...(options.entry || [])]; @@ -765,7 +809,7 @@ class WebpackCLI { pkg = commandName; } - if (pkg !== 'webpack-cli' && !this.utils.packageExists(pkg)) { + if (pkg !== "webpack-cli" && !this.utils.packageExists(pkg)) { if (!allowToInstall) { return; } @@ -773,7 +817,11 @@ class WebpackCLI { const { promptInstallation, colors } = this.utils; pkg = await promptInstallation(pkg, () => { - this.logger.error(`For using this command you need to install: '${colors.green(pkg)}' package`); + this.logger.error( + `For using this command you need to install: '${colors.green( + pkg, + )}' package`, + ); }); } @@ -811,38 +859,46 @@ class WebpackCLI { process.exit(0); } - if (error.code === 'executeSubCommandAsync') { + if (error.code === "executeSubCommandAsync") { process.exit(2); } - if (error.code === 'commander.help') { + if (error.code === "commander.help") { process.exit(0); } - if (error.code === 'commander.unknownOption') { + if (error.code === "commander.unknownOption") { let name = error.message.match(/'(.+)'/); if (name) { name = name[1].substr(2); - if (name.includes('=')) { - name = name.split('=')[0]; + if (name.includes("=")) { + name = name.split("=")[0]; } const { operands } = this.program.parseOptions(this.program.args); - const operand = typeof operands[0] !== 'undefined' ? operands[0] : getCommandName(buildCommandOptions.name); + const operand = + typeof operands[0] !== "undefined" + ? operands[0] + : getCommandName(buildCommandOptions.name); if (operand) { const command = findCommandByName(operand); if (!command) { this.logger.error(`Can't find and load command '${operand}'`); - this.logger.error("Run 'webpack --help' to see available commands and options"); + this.logger.error( + "Run 'webpack --help' to see available commands and options", + ); process.exit(2); } command.options.forEach((option) => { - if (!option.hidden && this.utils.levenshtein.distance(name, option.long.slice(2)) < 3) { + if ( + !option.hidden && + this.utils.levenshtein.distance(name, option.long.slice(2)) < 3 + ) { this.logger.error(`Did you mean '--${option.name()}'?`); } }); @@ -862,15 +918,15 @@ class WebpackCLI { // Default `--color` and `--no-color` options const cli = this; - this.program.option('--color', 'Enable colors on console.'); - this.program.on('option:color', function () { + this.program.option("--color", "Enable colors on console."); + this.program.on("option:color", function () { const { color } = this.opts(); cli.utils.colors.options.changed = true; cli.utils.colors.options.enabled = color; }); - this.program.option('--no-color', 'Disable colors on console.'); - this.program.on('option:no-color', function () { + this.program.option("--no-color", "Disable colors on console."); + this.program.on("option:no-color", function () { const { color } = this.opts(); cli.utils.colors.options.changed = true; @@ -900,14 +956,20 @@ class WebpackCLI { }); if (possibleCommandNames.length > 0) { - await Promise.all(possibleCommandNames.map((possibleCommand) => loadCommandByName(possibleCommand))); + await Promise.all( + possibleCommandNames.map((possibleCommand) => + loadCommandByName(possibleCommand), + ), + ); for (const possibleCommandName of possibleCommandNames) { const foundCommand = findCommandByName(possibleCommandName); if (!foundCommand) { this.logger.error(`Unknown command '${possibleCommandName}'`); - this.logger.error("Run 'webpack --help' to see available commands and options"); + this.logger.error( + "Run 'webpack --help' to see available commands and options", + ); process.exit(2); } @@ -916,20 +978,22 @@ class WebpackCLI { this.logger.raw(`${name} ${version}`); } catch (e) { - this.logger.error(`Error: External package '${foundCommand.pkg}' not found`); + this.logger.error( + `Error: External package '${foundCommand.pkg}' not found`, + ); process.exit(2); } } } - const pkgJSON = require('../package.json'); + const pkgJSON = require("../package.json"); this.logger.raw(`webpack ${this.webpack.version}`); this.logger.raw(`webpack-cli ${pkgJSON.version}`); - if (this.utils.packageExists('webpack-dev-server')) { + if (this.utils.packageExists("webpack-dev-server")) { // eslint-disable-next-line - const { version } = require('webpack-dev-server/package.json'); + const { version } = require("webpack-dev-server/package.json"); this.logger.raw(`webpack-dev-server ${version}`); } @@ -937,7 +1001,7 @@ class WebpackCLI { process.exit(0); }; this.program.option( - '-v, --version', + "-v, --version", "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", ); @@ -945,8 +1009,10 @@ class WebpackCLI { const { bold } = this.utils.colors; const outputIncorrectUsageOfHelp = () => { - this.logger.error('Incorrect use of help'); - this.logger.error("Please use: 'webpack help [command] [option]' | 'webpack [command] --help'"); + this.logger.error("Incorrect use of help"); + this.logger.error( + "Please use: 'webpack help [command] [option]' | 'webpack [command] --help'", + ); this.logger.error("Run 'webpack --help' to see available commands and options"); process.exit(2); }; @@ -959,32 +1025,43 @@ class WebpackCLI { sortSubcommands: true, // Support multiple aliases commandUsage: (command) => { - let parentCmdNames = ''; + let parentCmdNames = ""; - for (let parentCmd = command.parent; parentCmd; parentCmd = parentCmd.parent) { + for ( + let parentCmd = command.parent; + parentCmd; + parentCmd = parentCmd.parent + ) { parentCmdNames = `${parentCmd.name()} ${parentCmdNames}`; } if (isGlobalHelp) { return `${parentCmdNames}${command.usage()}\n${this.utils.colors.bold( - 'Alternative usage to run commands:', + "Alternative usage to run commands:", )} ${parentCmdNames}[command] [options]`; } - return `${parentCmdNames}${command.name()}|${command.aliases().join('|')} ${command.usage()}`; + return `${parentCmdNames}${command.name()}|${command + .aliases() + .join("|")} ${command.usage()}`; }, // Support multiple aliases subcommandTerm: (command) => { const humanReadableArgumentName = (argument) => { - const nameOutput = argument.name + (argument.variadic === true ? '...' : ''); + const nameOutput = + argument.name + (argument.variadic === true ? "..." : ""); - return argument.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']'; + return argument.required + ? "<" + nameOutput + ">" + : "[" + nameOutput + "]"; }; - const args = command._args.map((arg) => humanReadableArgumentName(arg)).join(' '); + const args = command._args + .map((arg) => humanReadableArgumentName(arg)) + .join(" "); - return `${command.name()}|${command.aliases().join('|')}${args ? ` ${args}` : ''}${ - command.options.length > 0 ? ' [options]' : '' - }`; + return `${command.name()}|${command.aliases().join("|")}${ + args ? ` ${args}` : "" + }${command.options.length > 0 ? " [options]" : ""}`; }, visibleOptions: function visibleOptions(command) { return command.options.filter((option) => { @@ -993,9 +1070,9 @@ class WebpackCLI { } switch (option.helpLevel) { - case 'verbose': + case "verbose": return isVerbose; - case 'minimum': + case "minimum": default: return true; } @@ -1007,37 +1084,48 @@ class WebpackCLI { helper.longestOptionTermLength(command, helper), // For global options helper.longestOptionTermLength(program, helper), - helper.longestSubcommandTermLength(isGlobalHelp ? program : command, helper), + helper.longestSubcommandTermLength( + isGlobalHelp ? program : command, + helper, + ), ); }, formatHelp: (command, helper) => { const termWidth = helper.padWidth(command, helper); - const helpWidth = helper.helpWidth || process.env.WEBPACK_CLI_HELP_WIDTH || 80; + const helpWidth = + helper.helpWidth || process.env.WEBPACK_CLI_HELP_WIDTH || 80; const itemIndentWidth = 2; const itemSeparatorWidth = 2; // between term and description const formatItem = (term, description) => { if (description) { - const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`; - - return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth); + const fullText = `${term.padEnd( + termWidth + itemSeparatorWidth, + )}${description}`; + + return helper.wrap( + fullText, + helpWidth - itemIndentWidth, + termWidth + itemSeparatorWidth, + ); } return term; }; - const formatList = (textArray) => textArray.join('\n').replace(/^/gm, ' '.repeat(itemIndentWidth)); + const formatList = (textArray) => + textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth)); // Usage - let output = [`${bold('Usage:')} ${helper.commandUsage(command)}`, '']; + let output = [`${bold("Usage:")} ${helper.commandUsage(command)}`, ""]; // Description const commandDescription = isGlobalHelp - ? 'The build tool for modern web applications.' + ? "The build tool for modern web applications." : helper.commandDescription(command); if (commandDescription.length > 0) { - output = output.concat([commandDescription, '']); + output = output.concat([commandDescription, ""]); } // Arguments @@ -1046,16 +1134,25 @@ class WebpackCLI { .map((argument) => formatItem(argument.term, argument.description)); if (argumentList.length > 0) { - output = output.concat([bold('Arguments:'), formatList(argumentList), '']); + output = output.concat([ + bold("Arguments:"), + formatList(argumentList), + "", + ]); } // Options const optionList = helper .visibleOptions(command) - .map((option) => formatItem(helper.optionTerm(option), helper.optionDescription(option))); + .map((option) => + formatItem( + helper.optionTerm(option), + helper.optionDescription(option), + ), + ); if (optionList.length > 0) { - output = output.concat([bold('Options:'), formatList(optionList), '']); + output = output.concat([bold("Options:"), formatList(optionList), ""]); } // Global options @@ -1064,19 +1161,32 @@ class WebpackCLI { ); if (globalOptionList.length > 0) { - output = output.concat([bold('Global options:'), formatList(globalOptionList), '']); + output = output.concat([ + bold("Global options:"), + formatList(globalOptionList), + "", + ]); } // Commands const commandList = helper .visibleCommands(isGlobalHelp ? program : command) - .map((command) => formatItem(helper.subcommandTerm(command), helper.subcommandDescription(command))); + .map((command) => + formatItem( + helper.subcommandTerm(command), + helper.subcommandDescription(command), + ), + ); if (commandList.length > 0) { - output = output.concat([bold('Commands:'), formatList(commandList), '']); + output = output.concat([ + bold("Commands:"), + formatList(commandList), + "", + ]); } - return output.join('\n'); + return output.join("\n"); }, }); @@ -1087,7 +1197,9 @@ class WebpackCLI { }), ); - const buildCommand = findCommandByName(getCommandName(buildCommandOptions.name)); + const buildCommand = findCommandByName( + getCommandName(buildCommandOptions.name), + ); this.logger.raw(buildCommand.helpInformation()); } else { @@ -1101,11 +1213,15 @@ class WebpackCLI { const builtInCommandUsed = externalBuiltInCommandsInfo.find( (command) => command.name.includes(name) || name === command.alias, ); - if (typeof builtInCommandUsed !== 'undefined') { - this.logger.error(`For using '${name}' command you need to install '${builtInCommandUsed.pkg}' package`); + if (typeof builtInCommandUsed !== "undefined") { + this.logger.error( + `For using '${name}' command you need to install '${builtInCommandUsed.pkg}' package`, + ); } else { this.logger.error(`Can't find and load command '${name}'`); - this.logger.error("Run 'webpack --help' to see available commands and options"); + this.logger.error( + "Run 'webpack --help' to see available commands and options", + ); } process.exit(2); } @@ -1133,7 +1249,9 @@ class WebpackCLI { await loadCommandByName(commandName); - const command = isGlobalOption(optionName) ? program : findCommandByName(commandName); + const command = isGlobalOption(optionName) + ? program + : findCommandByName(commandName); if (!command) { this.logger.error(`Can't find and load command '${commandName}'`); @@ -1141,7 +1259,9 @@ class WebpackCLI { process.exit(2); } - const option = command.options.find((option) => option.short === optionName || option.long === optionName); + const option = command.options.find( + (option) => option.short === optionName || option.long === optionName, + ); if (!option) { this.logger.error(`Unknown option '${optionName}'`); @@ -1150,30 +1270,39 @@ class WebpackCLI { } const nameOutput = - option.flags.replace(/^.+[[<]/, '').replace(/(\.\.\.)?[\]>].*$/, '') + (option.variadic === true ? '...' : ''); - const value = option.required ? '<' + nameOutput + '>' : option.optional ? '[' + nameOutput + ']' : ''; + option.flags.replace(/^.+[[<]/, "").replace(/(\.\.\.)?[\]>].*$/, "") + + (option.variadic === true ? "..." : ""); + const value = option.required + ? "<" + nameOutput + ">" + : option.optional + ? "[" + nameOutput + "]" + : ""; this.logger.raw( - `${bold('Usage')}: webpack${isCommandSpecified ? ` ${commandName}` : ''} ${option.long}${value ? ` ${value}` : ''}`, + `${bold("Usage")}: webpack${isCommandSpecified ? ` ${commandName}` : ""} ${ + option.long + }${value ? ` ${value}` : ""}`, ); if (option.short) { this.logger.raw( - `${bold('Short:')} webpack${isCommandSpecified ? ` ${commandName}` : ''} ${option.short}${ - value ? ` ${value}` : '' - }`, + `${bold("Short:")} webpack${isCommandSpecified ? ` ${commandName}` : ""} ${ + option.short + }${value ? ` ${value}` : ""}`, ); } if (option.description) { - this.logger.raw(`${bold('Description:')} ${option.description}`); + this.logger.raw(`${bold("Description:")} ${option.description}`); } if (!option.negate && options.defaultValue) { - this.logger.raw(`${bold('Default value:')} ${JSON.stringify(option.defaultValue)}`); + this.logger.raw( + `${bold("Default value:")} ${JSON.stringify(option.defaultValue)}`, + ); } - this.logger.raw(''); + this.logger.raw(""); // TODO implement this after refactor cli arguments // logger.raw('Possible values: foo | bar'); @@ -1182,44 +1311,48 @@ class WebpackCLI { outputIncorrectUsageOfHelp(); } - this.logger.raw("To see list of all supported commands and options run 'webpack --help=verbose'.\n"); - this.logger.raw(`${bold('Webpack documentation:')} https://webpack.js.org/.`); - this.logger.raw(`${bold('CLI documentation:')} https://webpack.js.org/api/cli/.`); - this.logger.raw(`${bold('Made with ♥ by the webpack team')}.`); + this.logger.raw( + "To see list of all supported commands and options run 'webpack --help=verbose'.\n", + ); + this.logger.raw(`${bold("Webpack documentation:")} https://webpack.js.org/.`); + this.logger.raw(`${bold("CLI documentation:")} https://webpack.js.org/api/cli/.`); + this.logger.raw(`${bold("Made with ♥ by the webpack team")}.`); process.exit(0); }; this.program.helpOption(false); this.program.addHelpCommand(false); - this.program.option('-h, --help [verbose]', 'Display help for commands and options.'); + this.program.option("-h, --help [verbose]", "Display help for commands and options."); let isInternalActionCalled = false; // Default action - this.program.usage('[options]'); + this.program.usage("[options]"); this.program.allowUnknownOption(true); this.program.action(async (options, program) => { if (!isInternalActionCalled) { isInternalActionCalled = true; } else { - this.logger.error('No commands found to run'); + this.logger.error("No commands found to run"); process.exit(2); } // Command and options const { operands, unknown } = this.program.parseOptions(program.args); const defaultCommandToRun = getCommandName(buildCommandOptions.name); - const hasOperand = typeof operands[0] !== 'undefined'; + const hasOperand = typeof operands[0] !== "undefined"; const operand = hasOperand ? operands[0] : defaultCommandToRun; - const isHelpOption = typeof options.help !== 'undefined'; + const isHelpOption = typeof options.help !== "undefined"; const isHelpCommandSyntax = isCommand(operand, helpCommandOptions); if (isHelpOption || isHelpCommandSyntax) { let isVerbose = false; if (isHelpOption) { - if (typeof options.help === 'string') { - if (options.help !== 'verbose') { - this.logger.error("Unknown value for '--help' option, please use '--help=verbose'"); + if (typeof options.help === "string") { + if (options.help !== "verbose") { + this.logger.error( + "Unknown value for '--help' option, please use '--help=verbose'", + ); process.exit(2); } @@ -1235,13 +1368,21 @@ class WebpackCLI { .concat(operands.slice(1)) // Syntax `webpack help [option]` .concat(unknown) - .concat(isHelpCommandSyntax && typeof options.color !== 'undefined' ? [options.color ? '--color' : '--no-color'] : []) - .concat(isHelpCommandSyntax && typeof options.version !== 'undefined' ? ['--version'] : []); + .concat( + isHelpCommandSyntax && typeof options.color !== "undefined" + ? [options.color ? "--color" : "--no-color"] + : [], + ) + .concat( + isHelpCommandSyntax && typeof options.version !== "undefined" + ? ["--version"] + : [], + ); await outputHelp(optionsForHelp, isVerbose, isHelpCommandSyntax, program); } - const isVersionOption = typeof options.version !== 'undefined'; + const isVersionOption = typeof options.version !== "undefined"; const isVersionCommandSyntax = isCommand(operand, versionCommandOptions); if (isVersionOption || isVersionCommandSyntax) { @@ -1270,13 +1411,17 @@ class WebpackCLI { this.logger.error(`Unknown command or entry '${operand}'`); const found = knownCommands.find( - (commandOptions) => this.utils.levenshtein.distance(operand, getCommandName(commandOptions.name)) < 3, + (commandOptions) => + this.utils.levenshtein.distance( + operand, + getCommandName(commandOptions.name), + ) < 3, ); if (found) { this.logger.error( `Did you mean '${getCommandName(found.name)}' (alias '${ - Array.isArray(found.alias) ? found.alias.join(', ') : found.alias + Array.isArray(found.alias) ? found.alias.join(", ") : found.alias }')?`, ); } @@ -1286,7 +1431,9 @@ class WebpackCLI { } } - await this.program.parseAsync([commandToRun, ...commandOperands, ...unknown], { from: 'user' }); + await this.program.parseAsync([commandToRun, ...commandOperands, ...unknown], { + from: "user", + }); }); await this.program.parseAsync(args, parseOptions); @@ -1296,7 +1443,9 @@ class WebpackCLI { const loadConfig = async (configPath) => { const { interpret } = this.utils; const ext = path.extname(configPath); - const interpreted = Object.keys(interpret.jsVariants).find((variant) => variant === ext); + const interpreted = Object.keys(interpret.jsVariants).find( + (variant) => variant === ext, + ); if (interpreted) { const { rechoir } = this.utils; @@ -1311,7 +1460,7 @@ class WebpackCLI { error.failures.forEach((failure) => { this.logger.error(failure.error.message); }); - this.logger.error('Please install one of them'); + this.logger.error("Please install one of them"); process.exit(2); } @@ -1342,7 +1491,8 @@ class WebpackCLI { } if ( - (error.code === 'ERR_REQUIRE_ESM' || process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) && + (error.code === "ERR_REQUIRE_ESM" || + process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) && pathToFileURL && dynamicImportLoader ) { @@ -1381,12 +1531,12 @@ class WebpackCLI { let evaluatedConfig = await Promise.all( config.map(async (rawConfig) => { - if (typeof rawConfig.then === 'function') { + if (typeof rawConfig.then === "function") { rawConfig = await rawConfig; } // `Promise` may return `Function` - if (typeof rawConfig === 'function') { + if (typeof rawConfig === "function") { // when config is a function, pass the env from args to the config function rawConfig = await rawConfig(argv.env, argv); } @@ -1397,7 +1547,7 @@ class WebpackCLI { loadedConfig.options = isMultiCompiler ? evaluatedConfig : evaluatedConfig[0]; - const isObject = (value) => typeof value === 'object' && value !== null; + const isObject = (value) => typeof value === "object" && value !== null; if (!isObject(loadedConfig.options) && !Array.isArray(loadedConfig.options)) { this.logger.error(`Invalid configuration in '${loadedConfig.path}'`); @@ -1411,7 +1561,9 @@ class WebpackCLI { if (options.config && options.config.length > 0) { const evaluatedConfigs = await Promise.all( - options.config.map(async (value) => evaluateConfig(await loadConfig(path.resolve(value)), options.argv || {})), + options.config.map(async (value) => + evaluateConfig(await loadConfig(path.resolve(value)), options.argv || {}), + ), ); config.options = []; @@ -1433,10 +1585,14 @@ class WebpackCLI { const { interpret } = this.utils; // Order defines the priority, in decreasing order - const defaultConfigFiles = ['webpack.config', '.webpack/webpack.config', '.webpack/webpackfile'] + const defaultConfigFiles = [ + "webpack.config", + ".webpack/webpack.config", + ".webpack/webpackfile", + ] .map((filename) => // Since .cjs is not available on interpret side add it manually to default config extension list - [...Object.keys(interpret.extensions), '.cjs'].map((ext) => ({ + [...Object.keys(interpret.extensions), ".cjs"].map((ext) => ({ path: path.resolve(filename + ext), ext: ext, module: interpret.extensions[ext], @@ -1492,20 +1648,25 @@ class WebpackCLI { if (notfoundConfigNames.length > 0) { this.logger.error( - notfoundConfigNames.map((configName) => `Configuration with the name "${configName}" was not found.`).join(' '), + notfoundConfigNames + .map( + (configName) => + `Configuration with the name "${configName}" was not found.`, + ) + .join(" "), ); process.exit(2); } } if (options.merge) { - const { merge } = require('webpack-merge'); + const { merge } = require("webpack-merge"); // we can only merge when there are multiple configurations // either by passing multiple configs by flags or passing a // single config exporting an array if (!Array.isArray(config.options) || config.options.length <= 1) { - this.logger.error('At least two configurations are required for merge.'); + this.logger.error("At least two configurations are required for merge."); process.exit(2); } @@ -1528,24 +1689,34 @@ class WebpackCLI { // TODO refactor async applyOptions(config, options) { if (options.analyze) { - if (!this.utils.packageExists('webpack-bundle-analyzer')) { + if (!this.utils.packageExists("webpack-bundle-analyzer")) { const { promptInstallation, colors } = this.utils; - await promptInstallation('webpack-bundle-analyzer', () => { - this.logger.error(`It looks like ${colors.yellow('webpack-bundle-analyzer')} is not installed.`); + await promptInstallation("webpack-bundle-analyzer", () => { + this.logger.error( + `It looks like ${colors.yellow( + "webpack-bundle-analyzer", + )} is not installed.`, + ); }); - this.logger.success(`${colors.yellow('webpack-bundle-analyzer')} was installed successfully.`); + this.logger.success( + `${colors.yellow("webpack-bundle-analyzer")} was installed successfully.`, + ); } } - if (typeof options.progress === 'string' && options.progress !== 'profile') { - this.logger.error(`'${options.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`); + if (typeof options.progress === "string" && options.progress !== "profile") { + this.logger.error( + `'${options.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`, + ); process.exit(2); } - if (typeof options.hot === 'string' && options.hot !== 'only') { - this.logger.error(`'${options.hot}' is an invalid value for the --hot option. Use 'only' instead.`); + if (typeof options.hot === "string" && options.hot !== "only") { + this.logger.error( + `'${options.hot}' is an invalid value for the --hot option. Use 'only' instead.`, + ); process.exit(2); } @@ -1554,15 +1725,15 @@ class WebpackCLI { configOptions.watch && options.argv && options.argv.env && - (options.argv.env['WEBPACK_WATCH'] || options.argv.env['WEBPACK_SERVE']) + (options.argv.env["WEBPACK_WATCH"] || options.argv.env["WEBPACK_SERVE"]) ) { this.logger.warn( `No need to use the '${ - options.argv.env['WEBPACK_WATCH'] ? 'watch' : 'serve' + options.argv.env["WEBPACK_WATCH"] ? "watch" : "serve" }' command together with '{ watch: true }' configuration, it does not make sense.`, ); - if (options.argv.env['WEBPACK_SERVE']) { + if (options.argv.env["WEBPACK_SERVE"]) { configOptions.watch = false; } } @@ -1577,7 +1748,7 @@ class WebpackCLI { if (this.webpack.cli) { const processArguments = (configOptions) => { const args = this.getBuiltInOptions() - .filter((flag) => flag.group === 'core') + .filter((flag) => flag.group === "core") .reduce((accumulator, flag) => { accumulator[flag.name] = flag; @@ -1585,7 +1756,7 @@ class WebpackCLI { }, {}); const values = Object.keys(options).reduce((accumulator, name) => { - if (name === 'argv') { + if (name === "argv") { return accumulator; } @@ -1608,16 +1779,18 @@ class WebpackCLI { return rv; }, {}); }; - const problemsByPath = groupBy(problems, 'path'); + const problemsByPath = groupBy(problems, "path"); for (const path in problemsByPath) { const problems = problemsByPath[path]; problems.forEach((problem) => { this.logger.error( - `${this.utils.capitalizeFirstLetter(problem.type.replace(/-/g, ' '))}${ - problem.value ? ` '${problem.value}'` : '' - } for the '--${problem.argument}' option${problem.index ? ` by index '${problem.index}'` : ''}`, + `${this.utils.capitalizeFirstLetter( + problem.type.replace(/-/g, " "), + )}${problem.value ? ` '${problem.value}'` : ""} for the '--${ + problem.argument + }' option${problem.index ? ` by index '${problem.index}'` : ""}`, ); if (problem.expected) { @@ -1638,7 +1811,7 @@ class WebpackCLI { const setupDefaultOptions = (configOptions) => { // No need to run for webpack@4 - if (configOptions.cache && configOptions.cache.type === 'filesystem') { + if (configOptions.cache && configOptions.cache.type === "filesystem") { const configPath = config.path.get(configOptions); if (configPath) { @@ -1686,7 +1859,7 @@ class WebpackCLI { configOptions.target = options.target; } - if (typeof options.devtool !== 'undefined') { + if (typeof options.devtool !== "undefined") { configOptions.devtool = options.devtool; } @@ -1696,7 +1869,9 @@ class WebpackCLI { !configOptions.mode && process.env && process.env.NODE_ENV && - (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'none') + (process.env.NODE_ENV === "development" || + process.env.NODE_ENV === "production" || + process.env.NODE_ENV === "none") ) { configOptions.mode = process.env.NODE_ENV; } @@ -1705,15 +1880,15 @@ class WebpackCLI { configOptions.name = options.name; } - if (typeof options.stats !== 'undefined') { + if (typeof options.stats !== "undefined") { configOptions.stats = options.stats; } - if (typeof options.watch !== 'undefined') { + if (typeof options.watch !== "undefined") { configOptions.watch = options.watch; } - if (typeof options.watchOptionsStdin !== 'undefined') { + if (typeof options.watchOptionsStdin !== "undefined") { configOptions.watchOptions = { ...configOptions.watchOptions, ...{ stdin: options.watchOptionsStdin }, @@ -1733,17 +1908,20 @@ class WebpackCLI { const statsForWebpack4 = this.webpack.Stats && this.webpack.Stats.presetToOptions; if (statsForWebpack4) { - if (typeof configOptions.stats === 'undefined') { + if (typeof configOptions.stats === "undefined") { configOptions.stats = {}; - } else if (typeof configOptions.stats === 'boolean' || typeof configOptions.stats === 'string') { + } else if ( + typeof configOptions.stats === "boolean" || + typeof configOptions.stats === "string" + ) { if ( - typeof configOptions.stats === 'string' && - configOptions.stats !== 'none' && - configOptions.stats !== 'verbose' && - configOptions.stats !== 'detailed' && - configOptions.stats !== 'minimal' && - configOptions.stats !== 'errors-only' && - configOptions.stats !== 'errors-warnings' + typeof configOptions.stats === "string" && + configOptions.stats !== "none" && + configOptions.stats !== "verbose" && + configOptions.stats !== "detailed" && + configOptions.stats !== "minimal" && + configOptions.stats !== "errors-only" && + configOptions.stats !== "errors-warnings" ) { return configOptions; } @@ -1751,11 +1929,13 @@ class WebpackCLI { configOptions.stats = this.webpack.Stats.presetToOptions(configOptions.stats); } } else { - if (typeof configOptions.stats === 'undefined') { - configOptions.stats = { preset: 'normal' }; - } else if (typeof configOptions.stats === 'boolean') { - configOptions.stats = configOptions.stats ? { preset: 'normal' } : { preset: 'none' }; - } else if (typeof configOptions.stats === 'string') { + if (typeof configOptions.stats === "undefined") { + configOptions.stats = { preset: "normal" }; + } else if (typeof configOptions.stats === "boolean") { + configOptions.stats = configOptions.stats + ? { preset: "normal" } + : { preset: "none" }; + } else if (typeof configOptions.stats === "string") { configOptions.stats = { preset: configOptions.stats }; } } @@ -1763,11 +1943,11 @@ class WebpackCLI { let colors; // From arguments - if (typeof this.utils.colors.options.changed !== 'undefined') { + if (typeof this.utils.colors.options.changed !== "undefined") { colors = Boolean(this.utils.colors.options.enabled); } // From stats - else if (typeof configOptions.stats.colors !== 'undefined') { + else if (typeof configOptions.stats.colors !== "undefined") { colors = configOptions.stats.colors; } // Default @@ -1793,7 +1973,7 @@ class WebpackCLI { configOptions.plugins = []; } - const CLIPlugin = require('./plugins/CLIPlugin'); + const CLIPlugin = require("./plugins/CLIPlugin"); configOptions.plugins.unshift( new CLIPlugin({ @@ -1817,7 +1997,9 @@ class WebpackCLI { needWatchStdin(compiler) { if (compiler.compilers) { - return compiler.compilers.some((compiler) => compiler.options.watchOptions && compiler.options.watchOptions.stdin); + return compiler.compilers.some( + (compiler) => compiler.options.watchOptions && compiler.options.watchOptions.stdin, + ); } return compiler.options.watchOptions && compiler.options.watchOptions.stdin; @@ -1826,9 +2008,10 @@ class WebpackCLI { isValidationError(error) { // https://github.com/webpack/webpack/blob/master/lib/index.js#L267 // https://github.com/webpack/webpack/blob/v4.44.2/lib/webpack.js#L90 - const ValidationError = this.webpack.ValidationError || this.webpack.WebpackOptionsValidationError; + const ValidationError = + this.webpack.ValidationError || this.webpack.WebpackOptionsValidationError; - return error instanceof ValidationError || error.name === 'ValidationError'; + return error instanceof ValidationError || error.name === "ValidationError"; } async createCompiler(options, callback) { @@ -1891,7 +2074,11 @@ class WebpackCLI { } const statsOptions = compiler.compilers - ? { children: compiler.compilers.map((compiler) => (compiler.options ? compiler.options.stats : undefined)) } + ? { + children: compiler.compilers.map((compiler) => + compiler.options ? compiler.options.stats : undefined, + ), + } : compiler.options ? compiler.options.stats : undefined; @@ -1904,7 +2091,9 @@ class WebpackCLI { } if (options.json) { - const { stringifyStream: createJsonStringifyStream } = require('@discoveryjs/json-ext'); + const { + stringifyStream: createJsonStringifyStream, + } = require("@discoveryjs/json-ext"); const handleWriteError = (error) => { this.logger.error(error); process.exit(2); @@ -1912,19 +2101,21 @@ class WebpackCLI { if (options.json === true) { createJsonStringifyStream(stats.toJson(statsOptions)) - .on('error', handleWriteError) + .on("error", handleWriteError) .pipe(process.stdout) - .on('error', handleWriteError) - .on('close', () => process.stdout.write('\n')); + .on("error", handleWriteError) + .on("close", () => process.stdout.write("\n")); } else { createJsonStringifyStream(stats.toJson(statsOptions)) - .on('error', handleWriteError) + .on("error", handleWriteError) .pipe(fs.createWriteStream(options.json)) - .on('error', handleWriteError) + .on("error", handleWriteError) // Use stderr to logging - .on('close', () => + .on("close", () => process.stderr.write( - `[webpack-cli] ${this.utils.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`, + `[webpack-cli] ${this.utils.colors.green( + `stats are successfully stored as json to ${options.json}`, + )}\n`, ), ); } @@ -1956,10 +2147,12 @@ class WebpackCLI { } const isWatch = (compiler) => - compiler.compilers ? compiler.compilers.some((compiler) => compiler.options.watch) : compiler.options.watch; + compiler.compilers + ? compiler.compilers.some((compiler) => compiler.options.watch) + : compiler.options.watch; if (isWatch(compiler) && this.needWatchStdin(compiler)) { - process.stdin.on('end', () => { + process.stdin.on("end", () => { process.exit(0); }); process.stdin.resume(); diff --git a/prettier.config.js b/prettier.config.js index 89d4592e472..a3ca7933373 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,5 +1,4 @@ module.exports = { - singleQuote: true, - trailingComma: 'all', - printWidth: 140, + printWidth: 100, + trailingComma: "all", }; diff --git a/scripts/cleanupTest.js b/scripts/cleanupTest.js index 0f1638df0cf..9be7a8effdb 100644 --- a/scripts/cleanupTest.js +++ b/scripts/cleanupTest.js @@ -1,19 +1,19 @@ // eslint-disable-next-line node/no-unpublished-require -const rimraf = require('rimraf'); -const { join } = require('path'); -const collectTestFolders = require('./utils'); +const rimraf = require("rimraf"); +const { join } = require("path"); +const collectTestFolders = require("./utils"); const outputDirectories = [ - 'bin', - 'binary', - 'dist', - 'test', - 'test-assets', - 'test-plugin', - 'test-loader', - 'test-cache-path', - 'test-locate-cache', - 'stats.json', + "bin", + "binary", + "dist", + "test", + "test-assets", + "test-plugin", + "test-loader", + "test-cache-path", + "test-locate-cache", + "stats.json", ]; const folderStrategy = (stats, file) => { diff --git a/scripts/globalSetup.js b/scripts/globalSetup.js index d043a5903d0..c38c758c60d 100644 --- a/scripts/globalSetup.js +++ b/scripts/globalSetup.js @@ -1,3 +1,3 @@ -const { version } = require('webpack'); +const { version } = require("webpack"); module.exports = () => console.log(`\n Running tests for webpack @${version} \n`); diff --git a/scripts/prepareSuite.js b/scripts/prepareSuite.js index caa5106c371..6ffb4b59562 100644 --- a/scripts/prepareSuite.js +++ b/scripts/prepareSuite.js @@ -1,10 +1,10 @@ // eslint-disable-next-line node/no-unpublished-require -const execa = require('execa'); +const execa = require("execa"); // eslint-disable-next-line node/no-unpublished-require -const { red, green } = require('colorette'); -const collectTestFolders = require('./utils'); +const { red, green } = require("colorette"); +const collectTestFolders = require("./utils"); -const PACKAGE = 'package.json'; +const PACKAGE = "package.json"; const getFoldersWithPackage = (stats, file) => { return stats.isFile() && file === PACKAGE; @@ -14,14 +14,14 @@ const getFoldersWithPackage = (stats, file) => { try { const folders = collectTestFolders(getFoldersWithPackage); for (const folder of folders) { - await execa('yarn', { + await execa("yarn", { cwd: folder, - stdio: 'inherit', + stdio: "inherit", }); } - console.log(green(' Successfully prepared the test suite ')); + console.log(green(" Successfully prepared the test suite ")); } catch (e) { - console.error(red(' Unable to prepare the test suite ')); + console.error(red(" Unable to prepare the test suite ")); console.error(e.stack); process.exitCode = 1; } diff --git a/scripts/setupBuild.js b/scripts/setupBuild.js index 47baf48f865..1daf7485f1b 100644 --- a/scripts/setupBuild.js +++ b/scripts/setupBuild.js @@ -1,7 +1,7 @@ -const { writeFileSync, readFileSync } = require('fs'); -const { resolve } = require('path'); +const { writeFileSync, readFileSync } = require("fs"); +const { resolve } = require("path"); -const tsConfigPath = resolve(__dirname, '../tsconfig.json'); +const tsConfigPath = resolve(__dirname, "../tsconfig.json"); const tsConfigRaw = readFileSync(tsConfigPath); const tsConfig = JSON.parse(tsConfigRaw); diff --git a/scripts/snapshotResolver.js b/scripts/snapshotResolver.js index 5c8ab291240..0683c4e30b9 100644 --- a/scripts/snapshotResolver.js +++ b/scripts/snapshotResolver.js @@ -1,24 +1,33 @@ -const path = require('path'); +const path = require("path"); -const webpack = require('webpack'); +const webpack = require("webpack"); //eslint-disable-next-line node/no-unpublished-require -const [devServerVersion] = require('webpack-dev-server/package.json').version; +const [devServerVersion] = require("webpack-dev-server/package.json").version; const [webpackVersion] = webpack.version; const snapshotExtension = `.snap.webpack${webpackVersion}`; const snapshotExtensionForServe = `.snap.devServer${devServerVersion}.webpack${webpackVersion}`; -const helpCommandTestDir = path.resolve(__dirname, '../test/help'); -const serveCommandTestDir = path.resolve(__dirname, '../test/serve'); +const helpCommandTestDir = path.resolve(__dirname, "../test/help"); +const serveCommandTestDir = path.resolve(__dirname, "../test/serve"); module.exports = { resolveSnapshotPath: (testPath) => { if (testPath.startsWith(helpCommandTestDir) || testPath.startsWith(serveCommandTestDir)) { - return path.join(path.dirname(testPath), '__snapshots__', `${path.basename(testPath)}${snapshotExtensionForServe}`); + return path.join( + path.dirname(testPath), + "__snapshots__", + `${path.basename(testPath)}${snapshotExtensionForServe}`, + ); } - return path.join(path.dirname(testPath), '__snapshots__', `${path.basename(testPath)}${snapshotExtension}`); + return path.join( + path.dirname(testPath), + "__snapshots__", + `${path.basename(testPath)}${snapshotExtension}`, + ); }, - resolveTestPath: (snapshotPath) => snapshotPath.replace(`${path.sep}__snapshots__`, '').slice(0, -snapshotExtension.length), - testPathForConsistencyCheck: path.join('consistency_check', '__tests__', 'example.test.js'), + resolveTestPath: (snapshotPath) => + snapshotPath.replace(`${path.sep}__snapshots__`, "").slice(0, -snapshotExtension.length), + testPathForConsistencyCheck: path.join("consistency_check", "__tests__", "example.test.js"), }; diff --git a/scripts/updateDocs.js b/scripts/updateDocs.js index 753863af2ba..6193903a675 100644 --- a/scripts/updateDocs.js +++ b/scripts/updateDocs.js @@ -1,31 +1,39 @@ //eslint-disable-next-line node/no-unpublished-require -const { sync } = require('execa'); -const { resolve } = require('path'); -const { writeFileSync } = require('fs'); +const { sync } = require("execa"); +const { resolve } = require("path"); +const { writeFileSync } = require("fs"); try { - const { stdout: cliOptions } = sync(resolve(__dirname, '../packages/webpack-cli/bin/cli.js'), ['--help=verbose'], { - cwd: __dirname, - reject: false, - }); + const { stdout: cliOptions } = sync( + resolve(__dirname, "../packages/webpack-cli/bin/cli.js"), + ["--help=verbose"], + { + cwd: __dirname, + reject: false, + }, + ); // format output for markdown - const mdContent = ['```\n', cliOptions, '\n```'].join(''); + const mdContent = ["```\n", cliOptions, "\n```"].join(""); // create OPTIONS.md - writeFileSync('OPTIONS.md', mdContent); + writeFileSync("OPTIONS.md", mdContent); // serve options - const { stdout: serveOptions } = sync(resolve(__dirname, '../packages/webpack-cli/bin/cli.js'), ['serve', '--help'], { - cwd: __dirname, - reject: false, - }); + const { stdout: serveOptions } = sync( + resolve(__dirname, "../packages/webpack-cli/bin/cli.js"), + ["serve", "--help"], + { + cwd: __dirname, + reject: false, + }, + ); // format output for markdown - const serveContent = ['```\n', serveOptions, '\n```'].join(''); + const serveContent = ["```\n", serveOptions, "\n```"].join(""); // create SERVE.md - writeFileSync('SERVE-OPTIONS.md', serveContent); + writeFileSync("SERVE-OPTIONS.md", serveContent); console.log('Successfully updated "OPTIONS.md" and "SERVE-OPTIONS.md"'); } catch (err) { diff --git a/scripts/utils.js b/scripts/utils.js index 966ce05f90d..dcc8770c13b 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -1,7 +1,7 @@ -const fs = require('fs'); -const path = require('path'); +const fs = require("fs"); +const path = require("path"); -const BASE_DIR = 'test/'; +const BASE_DIR = "test/"; function collectTestFolders(strategy) { const testFolder = path.resolve(path.join(process.cwd(), BASE_DIR)); @@ -30,7 +30,7 @@ function extractFolder(folderToRead, folders = [], folderStrategy) { folders.push(folderToRead); } - if (stats.isDirectory() && file !== 'node_modules') { + if (stats.isDirectory() && file !== "node_modules") { extractFolder(filePath, folders, folderStrategy); } }); diff --git a/setupTest.js b/setupTest.js index 6234cd7fd26..b48278a7291 100644 --- a/setupTest.js +++ b/setupTest.js @@ -2,6 +2,6 @@ jest.setTimeout(240000); -if (!jasmine.testPath.includes('colors.test.js')) { +if (!jasmine.testPath.includes("colors.test.js")) { process.env.NO_COLOR = true; } diff --git a/smoketests/helpers.js b/smoketests/helpers.js index d25c1bcdcbd..eac6e1f9100 100644 --- a/smoketests/helpers.js +++ b/smoketests/helpers.js @@ -1,11 +1,13 @@ /* eslint-disable node/no-unpublished-require */ -const fs = require('fs'); -const path = require('path'); -const execa = require('execa'); -const stripAnsi = require('strip-ansi'); +const fs = require("fs"); +const path = require("path"); +const execa = require("execa"); +const stripAnsi = require("strip-ansi"); -const ROOT_PATH = process.env.GITHUB_WORKSPACE ? process.env.GITHUB_WORKSPACE : path.resolve(__dirname, '..'); +const ROOT_PATH = process.env.GITHUB_WORKSPACE + ? process.env.GITHUB_WORKSPACE + : path.resolve(__dirname, ".."); const getPkgPath = (pkg, isSubPackage) => { const pkgPath = isSubPackage ? `./node_modules/@webpack-cli/${pkg}` : `./node_modules/${pkg}`; @@ -14,12 +16,12 @@ const getPkgPath = (pkg, isSubPackage) => { const swapPkgName = (current, isSubPackage = false) => { // info -> .info and vice-versa - const next = current.startsWith('.') ? current.substr(1) : `.${current}`; + const next = current.startsWith(".") ? current.substr(1) : `.${current}`; console.log(` swapping ${current} with ${next}`); fs.renameSync(getPkgPath(current, isSubPackage), getPkgPath(next, isSubPackage)); }; -const CLI_ENTRY_PATH = path.resolve(ROOT_PATH, './packages/webpack-cli/bin/cli.js'); +const CLI_ENTRY_PATH = path.resolve(ROOT_PATH, "./packages/webpack-cli/bin/cli.js"); const runTest = (package, cliArgs = [], logMessage, isSubPackage = false) => { // Simulate package missing @@ -29,24 +31,24 @@ const runTest = (package, cliArgs = [], logMessage, isSubPackage = false) => { cwd: __dirname, }); - proc.stdin.setDefaultEncoding('utf-8'); + proc.stdin.setDefaultEncoding("utf-8"); - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { console.log(` stdout: ${chunk.toString()}`); }); return new Promise((resolve) => { const timeout = setTimeout(() => { - console.log(' timeout: killing process'); + console.log(" timeout: killing process"); proc.kill(); }, 30000); - const prompt = 'Would you like to install'; + const prompt = "Would you like to install"; let hasLogMessage = false, hasPrompt = false, hasPassed = false; - proc.stderr.on('data', (chunk) => { + proc.stderr.on("data", (chunk) => { let data = stripAnsi(chunk.toString()); console.log(` stderr: ${data}`); @@ -64,13 +66,13 @@ const runTest = (package, cliArgs = [], logMessage, isSubPackage = false) => { } }); - proc.on('exit', () => { + proc.on("exit", () => { swapPkgName(`.${package}`, isSubPackage); clearTimeout(timeout); resolve(hasPassed); }); - proc.on('error', () => { + proc.on("error", () => { swapPkgName(`.${package}`, isSubPackage); clearTimeout(timeout); resolve(false); @@ -86,17 +88,17 @@ const runTestStdout = ({ packageName, cliArgs, logMessage, isSubPackage } = {}) cwd: __dirname, }); - proc.stdin.setDefaultEncoding('utf-8'); + proc.stdin.setDefaultEncoding("utf-8"); return new Promise((resolve) => { const timeout = setTimeout(() => { - console.log(' timeout: killing process'); + console.log(" timeout: killing process"); proc.kill(); }, 30000); let hasPassed = false; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { let data = stripAnsi(chunk.toString()); console.log(` stdout: ${data}`); @@ -106,18 +108,18 @@ const runTestStdout = ({ packageName, cliArgs, logMessage, isSubPackage } = {}) } }); - proc.stderr.on('data', (chunk) => { + proc.stderr.on("data", (chunk) => { let data = stripAnsi(chunk.toString()); console.log(` stderr: ${data}`); }); - proc.on('exit', () => { + proc.on("exit", () => { swapPkgName(`.${packageName}`, isSubPackage); clearTimeout(timeout); resolve(hasPassed); }); - proc.on('error', () => { + proc.on("error", () => { swapPkgName(`.${packageName}`, isSubPackage); clearTimeout(timeout); resolve(false); @@ -125,7 +127,13 @@ const runTestStdout = ({ packageName, cliArgs, logMessage, isSubPackage } = {}) }); }; -const runTestStdoutWithInput = ({ packageName, cliArgs, inputs, logMessage, isSubPackage } = {}) => { +const runTestStdoutWithInput = ({ + packageName, + cliArgs, + inputs, + logMessage, + isSubPackage, +} = {}) => { // Simulate package missing swapPkgName(packageName, isSubPackage); @@ -133,17 +141,17 @@ const runTestStdoutWithInput = ({ packageName, cliArgs, inputs, logMessage, isSu cwd: __dirname, }); - proc.stdin.setDefaultEncoding('utf-8'); + proc.stdin.setDefaultEncoding("utf-8"); return new Promise((resolve) => { const timeout = setTimeout(() => { - console.log(' timeout: killing process'); + console.log(" timeout: killing process"); proc.kill(); }, 300000); let hasPassed = false; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { let data = stripAnsi(chunk.toString()); console.log(` stdout: ${data}`); @@ -159,18 +167,18 @@ const runTestStdoutWithInput = ({ packageName, cliArgs, inputs, logMessage, isSu }); }); - proc.stderr.on('data', (chunk) => { + proc.stderr.on("data", (chunk) => { let data = stripAnsi(chunk.toString()); console.log(` stderr: ${data}`); }); - proc.on('exit', () => { + proc.on("exit", () => { swapPkgName(`.${packageName}`, isSubPackage); clearTimeout(timeout); resolve(hasPassed); }); - proc.on('error', () => { + proc.on("error", () => { swapPkgName(`.${packageName}`, isSubPackage); clearTimeout(timeout); resolve(false); @@ -186,15 +194,15 @@ const runTestWithHelp = (package, cliArgs = [], logMessage, isSubPackage = false cwd: __dirname, }); - proc.stdin.setDefaultEncoding('utf-8'); + proc.stdin.setDefaultEncoding("utf-8"); - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { console.log(` stdout: ${chunk.toString()}`); }); return new Promise((resolve) => { const timeout = setTimeout(() => { - console.log(' timeout: killing process'); + console.log(" timeout: killing process"); proc.kill(); }, 30000); @@ -204,7 +212,7 @@ const runTestWithHelp = (package, cliArgs = [], logMessage, isSubPackage = false hasUndefinedLogMessage = false, hasPassed = false; - proc.stderr.on('data', (chunk) => { + proc.stderr.on("data", (chunk) => { let data = stripAnsi(chunk.toString()); console.log(` stderr: ${data}`); @@ -222,13 +230,13 @@ const runTestWithHelp = (package, cliArgs = [], logMessage, isSubPackage = false } }); - proc.on('exit', () => { + proc.on("exit", () => { swapPkgName(`.${package}`, isSubPackage); clearTimeout(timeout); resolve(hasPassed); }); - proc.on('error', () => { + proc.on("error", () => { swapPkgName(`.${package}`, isSubPackage); clearTimeout(timeout); resolve(false); diff --git a/smoketests/index.js b/smoketests/index.js index b63f898e2ea..c734be20948 100644 --- a/smoketests/index.js +++ b/smoketests/index.js @@ -1,12 +1,12 @@ const tests = [ - require('./missing-packages/webpack-dev-server.test.js'), - require('./missing-packages/webpack.test.js'), - require('./missing-packages/webpack-bundle-analyzer.test.js'), - require('./missing-command-packages/generator.test.js'), - require('./missing-command-packages/serve.test.js'), - require('./missing-command-packages/info.test.js'), - require('./missing-command-packages/configtest.test.js'), - require('./missing-packages/prettier.test.js'), + require("./missing-packages/webpack-dev-server.test.js"), + require("./missing-packages/webpack.test.js"), + require("./missing-packages/webpack-bundle-analyzer.test.js"), + require("./missing-command-packages/generator.test.js"), + require("./missing-command-packages/serve.test.js"), + require("./missing-command-packages/info.test.js"), + require("./missing-command-packages/configtest.test.js"), + require("./missing-packages/prettier.test.js"), ]; (async () => { diff --git a/smoketests/missing-command-packages/configtest.test.js b/smoketests/missing-command-packages/configtest.test.js index 0154864f646..66683b4d53f 100644 --- a/smoketests/missing-command-packages/configtest.test.js +++ b/smoketests/missing-command-packages/configtest.test.js @@ -1,23 +1,25 @@ -'use strict'; +"use strict"; -const { runTest, runTestWithHelp } = require('../helpers'); +const { runTest, runTestWithHelp } = require("../helpers"); -const packageName = 'configtest'; +const packageName = "configtest"; const isSubPackage = true; const configTest = () => { - const args = ['configtest']; - const logMessage = "For using this command you need to install: '@webpack-cli/configtest' package"; + const args = ["configtest"]; + const logMessage = + "For using this command you need to install: '@webpack-cli/configtest' package"; return runTest(packageName, args, logMessage, isSubPackage); }; const configTestWithHelp = () => { - const args = ['help', 'configtest']; - const logMessage = "For using 'configtest' command you need to install '@webpack-cli/configtest' package"; + const args = ["help", "configtest"]; + const logMessage = + "For using 'configtest' command you need to install '@webpack-cli/configtest' package"; return runTestWithHelp(packageName, args, logMessage, isSubPackage); }; module.exports.run = [configTest, configTestWithHelp]; -module.exports.name = 'Missing @webpack-cli/configtest'; +module.exports.name = "Missing @webpack-cli/configtest"; diff --git a/smoketests/missing-command-packages/generator.test.js b/smoketests/missing-command-packages/generator.test.js index 8afd7495f6e..c0c95b8a8e9 100644 --- a/smoketests/missing-command-packages/generator.test.js +++ b/smoketests/missing-command-packages/generator.test.js @@ -1,23 +1,25 @@ -'use strict'; +"use strict"; -const { runTest, runTestWithHelp } = require('../helpers'); +const { runTest, runTestWithHelp } = require("../helpers"); -const packageName = 'generators'; +const packageName = "generators"; const isSubPackage = true; const initTest = () => { - const args = ['init']; - const logMessage = "For using this command you need to install: '@webpack-cli/generators' package"; + const args = ["init"]; + const logMessage = + "For using this command you need to install: '@webpack-cli/generators' package"; return runTest(packageName, args, logMessage, isSubPackage); }; const initTestWithHelp = () => { - const args = ['help', 'init']; - const logMessage = "For using 'init' command you need to install '@webpack-cli/generators' package"; + const args = ["help", "init"]; + const logMessage = + "For using 'init' command you need to install '@webpack-cli/generators' package"; return runTestWithHelp(packageName, args, logMessage, isSubPackage); }; module.exports.run = [initTest, initTestWithHelp]; -module.exports.name = 'Missing @webpack-cli/generators'; +module.exports.name = "Missing @webpack-cli/generators"; diff --git a/smoketests/missing-command-packages/info.test.js b/smoketests/missing-command-packages/info.test.js index 17a843422f6..3bdbe8b17ab 100644 --- a/smoketests/missing-command-packages/info.test.js +++ b/smoketests/missing-command-packages/info.test.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; -const { runTest, runTestWithHelp } = require('../helpers'); +const { runTest, runTestWithHelp } = require("../helpers"); -const packageName = 'info'; +const packageName = "info"; const isSubPackage = true; const infoTest = () => { - const args = ['info']; + const args = ["info"]; const logMessage = "For using this command you need to install: '@webpack-cli/info' package"; return runTest(packageName, args, logMessage, isSubPackage); }; const infoTestWithHelp = () => { - const args = ['help', 'info']; + const args = ["help", "info"]; const logMessage = "For using 'info' command you need to install '@webpack-cli/info' package"; return runTestWithHelp(packageName, args, logMessage, isSubPackage); }; module.exports.run = [infoTest, infoTestWithHelp]; -module.exports.name = 'Missing @webpack-cli/info'; +module.exports.name = "Missing @webpack-cli/info"; diff --git a/smoketests/missing-command-packages/serve.test.js b/smoketests/missing-command-packages/serve.test.js index 7aa2a24c801..f0621b9c613 100644 --- a/smoketests/missing-command-packages/serve.test.js +++ b/smoketests/missing-command-packages/serve.test.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; -const { runTest, runTestWithHelp } = require('../helpers'); +const { runTest, runTestWithHelp } = require("../helpers"); -const packageName = 'serve'; +const packageName = "serve"; const isSubPackage = true; const serveTest = () => { - const args = ['serve']; + const args = ["serve"]; const logMessage = "For using this command you need to install: '@webpack-cli/serve' package"; return runTest(packageName, args, logMessage, isSubPackage); }; const serveTestWithHelp = () => { - const args = ['help', 'serve']; + const args = ["help", "serve"]; const logMessage = "For using 'serve' command you need to install '@webpack-cli/serve' package"; return runTestWithHelp(packageName, args, logMessage, isSubPackage); }; module.exports.run = [serveTest, serveTestWithHelp]; -module.exports.name = 'Missing @webpack-cli/serve'; +module.exports.name = "Missing @webpack-cli/serve"; diff --git a/smoketests/missing-packages/prettier.test.js b/smoketests/missing-packages/prettier.test.js index 52cfe96ab4a..a11677ab865 100644 --- a/smoketests/missing-packages/prettier.test.js +++ b/smoketests/missing-packages/prettier.test.js @@ -1,32 +1,38 @@ -'use strict'; +"use strict"; -const { runTestStdout, runTestStdoutWithInput } = require('../helpers'); +const { runTestStdout, runTestStdoutWithInput } = require("../helpers"); // eslint-disable-next-line node/no-unpublished-require -const rimraf = require('rimraf'); -const { resolve } = require('path'); +const rimraf = require("rimraf"); +const { resolve } = require("path"); const prettierTest = async () => { - const packageName = 'prettier'; - const rootPath = resolve(__dirname, './test-assets'); - const cliArgs = ['init', rootPath, '--force']; - const logMessage = 'Do you like to install prettier to format generated configuration?'; + const packageName = "prettier"; + const rootPath = resolve(__dirname, "./test-assets"); + const cliArgs = ["init", rootPath, "--force"]; + const logMessage = "Do you like to install prettier to format generated configuration?"; const status = await runTestStdout({ packageName, cliArgs, logMessage }); rimraf.sync(rootPath); return status; }; const prettierTestWithNoAnswer = async () => { - const packageName = 'prettier'; - const rootPath = resolve(__dirname, './test-assets'); - const cliArgs = ['init', rootPath, '--force']; + const packageName = "prettier"; + const rootPath = resolve(__dirname, "./test-assets"); + const cliArgs = ["init", rootPath, "--force"]; const inputs = { - 'Do you like to install prettier to format generated configuration?': 'n\n', + "Do you like to install prettier to format generated configuration?": "n\n", }; - const logMessage = 'Generated configuration may not be properly formatted as prettier is not installed'; - const status = await runTestStdoutWithInput({ packageName, cliArgs, inputs, logMessage }); + const logMessage = + "Generated configuration may not be properly formatted as prettier is not installed"; + const status = await runTestStdoutWithInput({ + packageName, + cliArgs, + inputs, + logMessage, + }); rimraf.sync(rootPath); return status; }; module.exports.run = [prettierTest, prettierTestWithNoAnswer]; -module.exports.name = 'Missing prettier'; +module.exports.name = "Missing prettier"; diff --git a/smoketests/missing-packages/webpack-bundle-analyzer.test.js b/smoketests/missing-packages/webpack-bundle-analyzer.test.js index 29e5c74e9b8..6033e5fbfc2 100644 --- a/smoketests/missing-packages/webpack-bundle-analyzer.test.js +++ b/smoketests/missing-packages/webpack-bundle-analyzer.test.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const { runTest } = require('../helpers'); +const { runTest } = require("../helpers"); const webpackBundleAnalyzerTest = () => { - const packageName = 'webpack-bundle-analyzer'; - const args = ['--analyze']; - const logMessage = 'It looks like webpack-bundle-analyzer is not installed.'; + const packageName = "webpack-bundle-analyzer"; + const args = ["--analyze"]; + const logMessage = "It looks like webpack-bundle-analyzer is not installed."; return runTest(packageName, args, logMessage); }; module.exports.run = [webpackBundleAnalyzerTest]; -module.exports.name = 'Missing webpack-bundle-analyzer'; +module.exports.name = "Missing webpack-bundle-analyzer"; diff --git a/smoketests/missing-packages/webpack-dev-server.test.js b/smoketests/missing-packages/webpack-dev-server.test.js index d4596cad1b9..e053a970a1d 100644 --- a/smoketests/missing-packages/webpack-dev-server.test.js +++ b/smoketests/missing-packages/webpack-dev-server.test.js @@ -1,22 +1,23 @@ -'use strict'; +"use strict"; -const { runTest, runTestStdout } = require('../helpers'); +const { runTest, runTestStdout } = require("../helpers"); const webpackDevServerTest = () => { - const packageName = 'webpack-dev-server'; - const args = ['serve']; - const logMessage = "For using 'serve' command you need to install: 'webpack-dev-server' package"; + const packageName = "webpack-dev-server"; + const args = ["serve"]; + const logMessage = + "For using 'serve' command you need to install: 'webpack-dev-server' package"; return runTest(packageName, args, logMessage); }; const webpackDevServerWithHelpTest = () => { - const packageName = 'webpack-dev-server'; - const cliArgs = ['help', 'serve']; + const packageName = "webpack-dev-server"; + const cliArgs = ["help", "serve"]; const logMessage = "To see all available options you need to install 'webpack-dev-server'"; return runTestStdout({ packageName, cliArgs, logMessage }); }; module.exports.run = [webpackDevServerTest, webpackDevServerWithHelpTest]; -module.exports.name = 'Missing webpack-dev-server'; +module.exports.name = "Missing webpack-dev-server"; diff --git a/smoketests/missing-packages/webpack.test.js b/smoketests/missing-packages/webpack.test.js index eda004c0972..3c8f0ecfaed 100644 --- a/smoketests/missing-packages/webpack.test.js +++ b/smoketests/missing-packages/webpack.test.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const { runTest } = require('../helpers'); +const { runTest } = require("../helpers"); const webpackTest = () => { - const packageName = 'webpack'; + const packageName = "webpack"; const args = []; - const logMessage = 'It looks like webpack is not installed.'; + const logMessage = "It looks like webpack is not installed."; return runTest(packageName, args, logMessage); }; module.exports.run = [webpackTest]; -module.exports.name = 'Missing webpack'; +module.exports.name = "Missing webpack"; diff --git a/test/api/CLI.test.js b/test/api/CLI.test.js index 7c480374b84..738e6d2aa2a 100644 --- a/test/api/CLI.test.js +++ b/test/api/CLI.test.js @@ -1,36 +1,36 @@ -const CLI = require('../../packages/webpack-cli/lib/webpack-cli'); +const CLI = require("../../packages/webpack-cli/lib/webpack-cli"); -describe('CLI API', () => { +describe("CLI API", () => { let cli; beforeEach(() => { cli = new CLI(); }); - describe('makeCommand', () => { - it('should make command', async (done) => { + describe("makeCommand", () => { + it("should make command", async (done) => { cli.program.commands = []; - const command = await cli.makeCommand({ name: 'command' }, [], (options) => { + const command = await cli.makeCommand({ name: "command" }, [], (options) => { expect(options).toEqual({}); done(); }); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with Boolean option by default', async (done) => { + it("should make command with Boolean option by default", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean', - description: 'description', + name: "boolean", + description: "description", }, ], (options) => { @@ -40,21 +40,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean'], { from: 'user' }); + command.parseAsync(["--boolean"], { from: "user" }); }); - it('should make command with Boolean option', async (done) => { + it("should make command with Boolean option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean', + name: "boolean", type: Boolean, - description: 'description', + description: "description", }, ], (options) => { @@ -64,21 +64,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean'], { from: 'user' }); + command.parseAsync(["--boolean"], { from: "user" }); }); - it('should make command with Boolean option and negative value', async (done) => { + it("should make command with Boolean option and negative value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean', + name: "boolean", type: Boolean, - description: 'description', + description: "description", negative: true, }, ], @@ -89,25 +89,25 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--no-boolean'], { from: 'user' }); + command.parseAsync(["--no-boolean"], { from: "user" }); }); - it('should make command with configs boolean option', async (done) => { + it("should make command with configs boolean option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'configs-boolean', + name: "configs-boolean", configs: [ { - type: 'boolean', + type: "boolean", }, ], - description: 'description', + description: "description", }, ], (options) => { @@ -117,25 +117,25 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--no-configs-boolean'], { from: 'user' }); + command.parseAsync(["--no-configs-boolean"], { from: "user" }); }); - it('should make command with configs number option', async (done) => { + it("should make command with configs number option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'configs-number', + name: "configs-number", configs: [ { - type: 'number', + type: "number", }, ], - description: 'description', + description: "description", }, ], (options) => { @@ -145,139 +145,141 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--configs-number', '42'], { from: 'user' }); + command.parseAsync(["--configs-number", "42"], { from: "user" }); }); - it('should make command with configs string option', async (done) => { + it("should make command with configs string option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'configs-string', + name: "configs-string", configs: [ { - type: 'string', + type: "string", }, ], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ configsString: 'foo' }); + expect(options).toEqual({ configsString: "foo" }); done(); }, ); - command.parseAsync(['--configs-string', 'foo'], { from: 'user' }); + command.parseAsync(["--configs-string", "foo"], { from: "user" }); }); - it('should make command with configs path option', async (done) => { + it("should make command with configs path option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'configs-path', + name: "configs-path", configs: [ { - type: 'path', + type: "path", }, ], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ configsPath: '/root/foo' }); + expect(options).toEqual({ configsPath: "/root/foo" }); done(); }, ); - command.parseAsync(['--configs-path', '/root/foo'], { from: 'user' }); + command.parseAsync(["--configs-path", "/root/foo"], { + from: "user", + }); }); - it('should make command with configs RegExp option', async (done) => { + it("should make command with configs RegExp option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'configs-regexp', + name: "configs-regexp", configs: [ { - type: 'RegExp', + type: "RegExp", }, ], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ configsRegexp: '\\w+' }); + expect(options).toEqual({ configsRegexp: "\\w+" }); done(); }, ); - command.parseAsync(['--configs-regexp', '\\w+'], { from: 'user' }); + command.parseAsync(["--configs-regexp", "\\w+"], { from: "user" }); }); - it('should make command with configs enum/string option', async (done) => { + it("should make command with configs enum/string option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'enum-string', + name: "enum-string", configs: [ { - type: 'enum', - values: ['foo'], + type: "enum", + values: ["foo"], }, ], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ enumString: 'foo' }); + expect(options).toEqual({ enumString: "foo" }); done(); }, ); - command.parseAsync(['--enum-string', 'foo'], { from: 'user' }); + command.parseAsync(["--enum-string", "foo"], { from: "user" }); }); - it('should make command with configs enum/number option', async (done) => { + it("should make command with configs enum/number option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'enum-number', + name: "enum-number", configs: [ { - type: 'enum', + type: "enum", values: [42], }, ], - description: 'description', + description: "description", }, ], (options) => { @@ -287,26 +289,26 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--enum-number', '42'], { from: 'user' }); + command.parseAsync(["--enum-number", "42"], { from: "user" }); }); - it('should make command with configs enum/boolean option', async (done) => { + it("should make command with configs enum/boolean option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'enum-boolean', + name: "enum-boolean", configs: [ { - type: 'boolean', + type: "boolean", values: [false], }, ], - description: 'description', + description: "description", }, ], (options) => { @@ -316,21 +318,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--no-enum-boolean'], { from: 'user' }); + command.parseAsync(["--no-enum-boolean"], { from: "user" }); }); - it('should make command with Boolean option and negative value #2', async (done) => { + it("should make command with Boolean option and negative value #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean', + name: "boolean", type: Boolean, - description: 'description', + description: "description", negative: true, }, ], @@ -341,21 +343,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean', '--no-boolean'], { from: 'user' }); + command.parseAsync(["--boolean", "--no-boolean"], { from: "user" }); }); - it('should make command with Boolean option and negative value #3', async (done) => { + it("should make command with Boolean option and negative value #3", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean', + name: "boolean", type: Boolean, - description: 'description', + description: "description", negative: true, }, ], @@ -366,21 +368,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--no-boolean', '--boolean'], { from: 'user' }); + command.parseAsync(["--no-boolean", "--boolean"], { from: "user" }); }); - it('should make command with Boolean option with default value', async (done) => { + it("should make command with Boolean option with default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean', + name: "boolean", type: Boolean, - description: 'description', + description: "description", defaultValue: false, }, ], @@ -391,106 +393,106 @@ describe('CLI API', () => { }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with String option', async (done) => { + it("should make command with String option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", type: String, - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ string: 'bar' }); + expect(options).toEqual({ string: "bar" }); done(); }, ); - command.parseAsync(['--string', 'bar'], { from: 'user' }); + command.parseAsync(["--string", "bar"], { from: "user" }); }); - it('should make command with String option with alias', async (done) => { + it("should make command with String option with alias", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', - alias: 's', + name: "string", + alias: "s", type: String, - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ string: 'foo' }); + expect(options).toEqual({ string: "foo" }); done(); }, ); - command.parseAsync(['-s', 'foo'], { from: 'user' }); + command.parseAsync(["-s", "foo"], { from: "user" }); }); - it('should make command with String option with default value', async (done) => { + it("should make command with String option with default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", type: String, - description: 'description', - defaultValue: 'default-value', + description: "description", + defaultValue: "default-value", }, ], (options) => { - expect(options).toEqual({ string: 'default-value' }); + expect(options).toEqual({ string: "default-value" }); done(); }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with String option with default value #2', async (done) => { + it("should make command with String option with default value #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", type: String, - description: 'description', - defaultValue: 'default-value', + description: "description", + defaultValue: "default-value", }, ], (options) => { - expect(options).toEqual({ string: 'foo' }); + expect(options).toEqual({ string: "foo" }); done(); }, ); - command.parseAsync(['--string', 'foo'], { from: 'user' }); + command.parseAsync(["--string", "foo"], { from: "user" }); }); it('should make command with String option using "=" syntax', async (done) => { @@ -498,139 +500,143 @@ describe('CLI API', () => { const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", type: String, - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ string: 'bar' }); + expect(options).toEqual({ string: "bar" }); done(); }, ); - command.parseAsync(['--string=bar'], { from: 'user' }); + command.parseAsync(["--string=bar"], { from: "user" }); }); - it('should make command with multiple String option', async (done) => { + it("should make command with multiple String option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", multiple: true, type: String, - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ string: ['foo', 'bar'] }); + expect(options).toEqual({ string: ["foo", "bar"] }); done(); }, ); - command.parseAsync(['--string', 'foo', 'bar'], { from: 'user' }); + command.parseAsync(["--string", "foo", "bar"], { from: "user" }); }); - it('should make command with multiple String option with default value', async (done) => { + it("should make command with multiple String option with default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", multiple: true, type: String, - description: 'description', - defaultValue: 'string', + description: "description", + defaultValue: "string", }, ], (options) => { - expect(options).toEqual({ string: 'string' }); + expect(options).toEqual({ string: "string" }); done(); }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with multiple String option with default value #2', async (done) => { + it("should make command with multiple String option with default value #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", multiple: true, type: String, - description: 'description', - defaultValue: 'string', + description: "description", + defaultValue: "string", }, ], (options) => { - expect(options).toEqual({ string: ['foo', 'bar'] }); + expect(options).toEqual({ string: ["foo", "bar"] }); done(); }, ); - command.parseAsync(['--string', 'foo', '--string', 'bar'], { from: 'user' }); + command.parseAsync(["--string", "foo", "--string", "bar"], { + from: "user", + }); }); - it('should make command with multiple String option #2', async (done) => { + it("should make command with multiple String option #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'string', + name: "string", multiple: true, type: String, - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ string: ['foo', 'bar'] }); + expect(options).toEqual({ string: ["foo", "bar"] }); done(); }, ); - command.parseAsync(['--string', 'foo', '--string', 'bar'], { from: 'user' }); + command.parseAsync(["--string", "foo", "--string", "bar"], { + from: "user", + }); }); - it('should make command with Number option', async (done) => { + it("should make command with Number option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'number', + name: "number", type: Number, - description: 'description', + description: "description", }, ], (options) => { @@ -640,21 +646,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--number', '12'], { from: 'user' }); + command.parseAsync(["--number", "12"], { from: "user" }); }); - it('should make command with Number option with default value', async (done) => { + it("should make command with Number option with default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'number', + name: "number", type: Number, - description: 'description', + description: "description", defaultValue: 20, }, ], @@ -665,22 +671,22 @@ describe('CLI API', () => { }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with multiple Number option', async (done) => { + it("should make command with multiple Number option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'number', + name: "number", multiple: true, type: Number, - description: 'description', + description: "description", }, ], (options) => { @@ -690,22 +696,24 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--number', '1', '--number', '2'], { from: 'user' }); + command.parseAsync(["--number", "1", "--number", "2"], { + from: "user", + }); }); - it('should make command with multiple Number option and default value', async (done) => { + it("should make command with multiple Number option and default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'number', + name: "number", multiple: true, type: Number, - description: 'description', + description: "description", defaultValue: 50, }, ], @@ -716,22 +724,24 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--number', '1', '--number', '2'], { from: 'user' }); + command.parseAsync(["--number", "1", "--number", "2"], { + from: "user", + }); }); - it('should make command with multiple Number option and default value', async (done) => { + it("should make command with multiple Number option and default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'number', + name: "number", multiple: true, type: Number, - description: 'description', + description: "description", defaultValue: 50, }, ], @@ -742,103 +752,105 @@ describe('CLI API', () => { }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with custom function type', async (done) => { + it("should make command with custom function type", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'custom', + name: "custom", type: () => { - return 'function'; + return "function"; }, - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ custom: 'function' }); + expect(options).toEqual({ custom: "function" }); done(); }, ); - command.parseAsync(['--custom', 'value'], { from: 'user' }); + command.parseAsync(["--custom", "value"], { from: "user" }); }); - it('should make command with custom function type and default value', async (done) => { + it("should make command with custom function type and default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'custom', + name: "custom", type: () => { - return 'function'; + return "function"; }, - description: 'description', - defaultValue: 'default', + description: "description", + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ custom: 'default' }); + expect(options).toEqual({ custom: "default" }); done(); }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with multiple custom function type', async (done) => { + it("should make command with multiple custom function type", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'custom', + name: "custom", type: (value, previous = []) => { return previous.concat([value]); }, - description: 'description', + description: "description", multiple: true, }, ], (options) => { - expect(options).toEqual({ custom: ['value', 'other'] }); + expect(options).toEqual({ custom: ["value", "other"] }); done(); }, ); - command.parseAsync(['--custom', 'value', '--custom', 'other'], { from: 'user' }); + command.parseAsync(["--custom", "value", "--custom", "other"], { + from: "user", + }); }); - it('should make command with multiple custom function type and default value', async (done) => { + it("should make command with multiple custom function type and default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'custom', + name: "custom", type: (value, previous = []) => { return previous.concat([value]); }, - description: 'description', + description: "description", multiple: true, defaultValue: 50, }, @@ -850,21 +862,21 @@ describe('CLI API', () => { }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with multiple custom function type and default value #2', async (done) => { + it("should make command with multiple custom function type and default value #2", async (done) => { cli.program.commands = []; let skipDefault = true; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'custom', + name: "custom", type: (value, previous = []) => { if (skipDefault) { previous = []; @@ -873,33 +885,33 @@ describe('CLI API', () => { return [].concat(previous).concat([value]); }, - description: 'description', + description: "description", multiple: true, defaultValue: 50, }, ], (options) => { - expect(options).toEqual({ custom: ['foo'] }); + expect(options).toEqual({ custom: ["foo"] }); done(); }, ); - command.parseAsync(['--custom', 'foo'], { from: 'user' }); + command.parseAsync(["--custom", "foo"], { from: "user" }); }); - it('should make command with Boolean and String option', async (done) => { + it("should make command with Boolean and String option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-string', + name: "boolean-and-string", type: [Boolean, String], - description: 'description', + description: "description", }, ], (options) => { @@ -909,45 +921,47 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean-and-string'], { from: 'user' }); + command.parseAsync(["--boolean-and-string"], { from: "user" }); }); - it('should make command with Boolean and String option #2', async (done) => { + it("should make command with Boolean and String option #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-string', + name: "boolean-and-string", type: [Boolean, String], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ booleanAndString: 'value' }); + expect(options).toEqual({ booleanAndString: "value" }); done(); }, ); - command.parseAsync(['--boolean-and-string', 'value'], { from: 'user' }); + command.parseAsync(["--boolean-and-string", "value"], { + from: "user", + }); }); - it('should make command with multiple Boolean and String option', async (done) => { + it("should make command with multiple Boolean and String option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-string', + name: "boolean-and-string", type: [Boolean, String], - description: 'description', + description: "description", multiple: true, }, ], @@ -958,46 +972,50 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean-and-string'], { from: 'user' }); + command.parseAsync(["--boolean-and-string"], { from: "user" }); }); - it('should make command with multiple Boolean and String option #2', async (done) => { + it("should make command with multiple Boolean and String option #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-string', + name: "boolean-and-string", type: [Boolean, String], - description: 'description', + description: "description", multiple: true, }, ], (options) => { - expect(options).toEqual({ booleanAndString: ['bar', 'baz'] }); + expect(options).toEqual({ + booleanAndString: ["bar", "baz"], + }); done(); }, ); - command.parseAsync(['--boolean-and-string', 'bar', '--boolean-and-string', 'baz'], { from: 'user' }); + command.parseAsync(["--boolean-and-string", "bar", "--boolean-and-string", "baz"], { + from: "user", + }); }); - it('should make command with Boolean and String option and negative', async (done) => { + it("should make command with Boolean and String option and negative", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-string', + name: "boolean-and-string", type: [Boolean, String], - description: 'description', + description: "description", negative: true, }, ], @@ -1008,46 +1026,48 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean-and-string'], { from: 'user' }); + command.parseAsync(["--boolean-and-string"], { from: "user" }); }); - it('should make command with Boolean and String option and negative #2', async (done) => { + it("should make command with Boolean and String option and negative #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-string', + name: "boolean-and-string", type: [Boolean, String], - description: 'description', + description: "description", negative: true, }, ], (options) => { - expect(options).toEqual({ booleanAndString: 'foo' }); + expect(options).toEqual({ booleanAndString: "foo" }); done(); }, ); - command.parseAsync(['--boolean-and-string', 'foo'], { from: 'user' }); + command.parseAsync(["--boolean-and-string", "foo"], { + from: "user", + }); }); - it('should make command with Boolean and String option and negative #3', async (done) => { + it("should make command with Boolean and String option and negative #3", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-string', + name: "boolean-and-string", type: [Boolean, String], - description: 'description', + description: "description", negative: true, }, ], @@ -1058,21 +1078,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--no-boolean-and-string'], { from: 'user' }); + command.parseAsync(["--no-boolean-and-string"], { from: "user" }); }); - it('should make command with Boolean and Number option', async (done) => { + it("should make command with Boolean and Number option", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number', + name: "boolean-and-number", type: [Boolean, Number], - description: 'description', + description: "description", }, ], (options) => { @@ -1082,21 +1102,21 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean-and-number'], { from: 'user' }); + command.parseAsync(["--boolean-and-number"], { from: "user" }); }); - it('should make command with Boolean and Number option #2', async (done) => { + it("should make command with Boolean and Number option #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number', + name: "boolean-and-number", type: [Boolean, Number], - description: 'description', + description: "description", }, ], (options) => { @@ -1106,21 +1126,23 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean-and-number', '12'], { from: 'user' }); + command.parseAsync(["--boolean-and-number", "12"], { + from: "user", + }); }); - it('should make command with array Boolean type', async (done) => { + it("should make command with array Boolean type", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean', + name: "boolean", type: [Boolean], - description: 'description', + description: "description", }, ], (options) => { @@ -1130,45 +1152,49 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean'], { from: 'user' }); + command.parseAsync(["--boolean"], { from: "user" }); }); - it('should make command with Boolean and Number and String type', async (done) => { + it("should make command with Boolean and Number and String type", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: true }); + expect(options).toEqual({ + booleanAndNumberAndString: true, + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string"], { + from: "user", + }); }); - it('should make command with Boolean and Number and String type #2', async (done) => { + it("should make command with Boolean and Number and String type #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", }, ], (options) => { @@ -1178,96 +1204,108 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean-and-number-and-string', '12'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "12"], { + from: "user", + }); }); - it('should make command with Boolean and Number and String type #3', async (done) => { + it("should make command with Boolean and Number and String type #3", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: 'bar' }); + expect(options).toEqual({ + booleanAndNumberAndString: "bar", + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', 'bar'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "bar"], { + from: "user", + }); }); - it('should make command with Boolean and Number and String type and default value', async (done) => { + it("should make command with Boolean and Number and String type and default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', - defaultValue: 'default', + description: "description", + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: 'default' }); + expect(options).toEqual({ + booleanAndNumberAndString: "default", + }); done(); }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with Boolean and Number and String type and default value #2', async (done) => { + it("should make command with Boolean and Number and String type and default value #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', - defaultValue: 'default', + description: "description", + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: 'foo' }); + expect(options).toEqual({ + booleanAndNumberAndString: "foo", + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', 'foo'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "foo"], { + from: "user", + }); }); - it('should make command with Boolean and Number and String type and default value #3', async (done) => { + it("should make command with Boolean and Number and String type and default value #3", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', - defaultValue: 'default', + description: "description", + defaultValue: "default", }, ], (options) => { @@ -1277,285 +1315,333 @@ describe('CLI API', () => { }, ); - command.parseAsync(['--boolean-and-number-and-string', '12'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "12"], { + from: "user", + }); }); - it('should make command with Boolean and Number and String type and default value #4', async (done) => { + it("should make command with Boolean and Number and String type and default value #4", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', - defaultValue: 'default', + description: "description", + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: 'default' }); + expect(options).toEqual({ + booleanAndNumberAndString: "default", + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string"], { + from: "user", + }); }); - it('should make command with multiple Boolean and Number and String type', async (done) => { + it("should make command with multiple Boolean and Number and String type", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: true }); + expect(options).toEqual({ + booleanAndNumberAndString: true, + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string"], { + from: "user", + }); }); - it('should make command with multiple Boolean and Number and String type #2', async (done) => { + it("should make command with multiple Boolean and Number and String type #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: ['foo'] }); + expect(options).toEqual({ + booleanAndNumberAndString: ["foo"], + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', 'foo'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "foo"], { + from: "user", + }); }); - it('should make command with multiple Boolean and Number and String type #3', async (done) => { + it("should make command with multiple Boolean and Number and String type #3", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: [12] }); + expect(options).toEqual({ + booleanAndNumberAndString: [12], + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', '12'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "12"], { + from: "user", + }); }); - it('should make command with multiple Boolean and Number and String type #4', async (done) => { + it("should make command with multiple Boolean and Number and String type #4", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: ['foo', 'bar'] }); + expect(options).toEqual({ + booleanAndNumberAndString: ["foo", "bar"], + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', 'foo', '--boolean-and-number-and-string', 'bar'], { from: 'user' }); + command.parseAsync( + [ + "--boolean-and-number-and-string", + "foo", + "--boolean-and-number-and-string", + "bar", + ], + { from: "user" }, + ); }); - it('should make command with multiple Boolean and Number and String type #5', async (done) => { + it("should make command with multiple Boolean and Number and String type #5", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: ['foo', 12] }); + expect(options).toEqual({ + booleanAndNumberAndString: ["foo", 12], + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', 'foo', '--boolean-and-number-and-string', '12'], { from: 'user' }); + command.parseAsync( + ["--boolean-and-number-and-string", "foo", "--boolean-and-number-and-string", "12"], + { from: "user" }, + ); }); - it('should make command with multiple Boolean and Number and String and default value', async (done) => { + it("should make command with multiple Boolean and Number and String and default value", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, - defaultValue: 'default', + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: 'default' }); + expect(options).toEqual({ + booleanAndNumberAndString: "default", + }); done(); }, ); - command.parseAsync([], { from: 'user' }); + command.parseAsync([], { from: "user" }); }); - it('should make command with multiple Boolean and Number and String and default value #2', async (done) => { + it("should make command with multiple Boolean and Number and String and default value #2", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, - defaultValue: 'default', + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: ['foo'] }); + expect(options).toEqual({ + booleanAndNumberAndString: ["foo"], + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', 'foo'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "foo"], { + from: "user", + }); }); - it('should make command with multiple Boolean and Number and String and default value #3', async (done) => { + it("should make command with multiple Boolean and Number and String and default value #3", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, - defaultValue: 'default', + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: [12] }); + expect(options).toEqual({ + booleanAndNumberAndString: [12], + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', '12'], { from: 'user' }); + command.parseAsync(["--boolean-and-number-and-string", "12"], { + from: "user", + }); }); - it('should make command with multiple Boolean and Number and String and default value #4', async (done) => { + it("should make command with multiple Boolean and Number and String and default value #4", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'boolean-and-number-and-string', + name: "boolean-and-number-and-string", type: [Boolean, Number, String], - description: 'description', + description: "description", multiple: true, - defaultValue: 'default', + defaultValue: "default", }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: ['foo', 12] }); + expect(options).toEqual({ + booleanAndNumberAndString: ["foo", 12], + }); done(); }, ); - command.parseAsync(['--boolean-and-number-and-string', 'foo', '--boolean-and-number-and-string', '12'], { from: 'user' }); + command.parseAsync( + ["--boolean-and-number-and-string", "foo", "--boolean-and-number-and-string", "12"], + { from: "user" }, + ); }); - it('should make command with array of unknown types', async (done) => { + it("should make command with array of unknown types", async (done) => { cli.program.commands = []; const command = await cli.makeCommand( { - name: 'command', + name: "command", }, [ { - name: 'unknown', + name: "unknown", type: [Boolean, Symbol], - description: 'description', + description: "description", }, ], (options) => { - expect(options).toEqual({ unknown: 'foo' }); + expect(options).toEqual({ unknown: "foo" }); done(); }, ); - command.parseAsync(['--unknown', 'foo'], { from: 'user' }); + command.parseAsync(["--unknown", "foo"], { from: "user" }); }); }); }); diff --git a/test/api/capitalizeFirstLetter.test.js b/test/api/capitalizeFirstLetter.test.js index 13bb7f2137b..bff15eeb923 100755 --- a/test/api/capitalizeFirstLetter.test.js +++ b/test/api/capitalizeFirstLetter.test.js @@ -1,11 +1,11 @@ -const capitalizeFirstLetter = require('../../packages/webpack-cli/lib/utils/capitalize-first-letter'); +const capitalizeFirstLetter = require("../../packages/webpack-cli/lib/utils/capitalize-first-letter"); -describe('capitalizeFirstLetter', () => { - it('should capitalize first letter', () => { - expect(capitalizeFirstLetter('webpack')).toEqual('Webpack'); +describe("capitalizeFirstLetter", () => { + it("should capitalize first letter", () => { + expect(capitalizeFirstLetter("webpack")).toEqual("Webpack"); }); - it('should return an empty string on passing a non-string value', () => { - expect(capitalizeFirstLetter(true)).toEqual(''); + it("should return an empty string on passing a non-string value", () => { + expect(capitalizeFirstLetter(true)).toEqual(""); }); }); diff --git a/test/api/get-package-manager.test.js b/test/api/get-package-manager.test.js index 1c3d03af5ed..d790ec0fc57 100644 --- a/test/api/get-package-manager.test.js +++ b/test/api/get-package-manager.test.js @@ -1,34 +1,34 @@ -const fs = require('fs'); -const path = require('path'); +const fs = require("fs"); +const path = require("path"); const syncMock = jest.fn(() => { return { - stdout: '1.0.0', + stdout: "1.0.0", }; }); -jest.setMock('execa', { +jest.setMock("execa", { sync: syncMock, }); -const utilsDirectory = path.resolve(__dirname, '../../packages/webpack-cli/lib/utils/'); -const getPackageManager = require(path.resolve(utilsDirectory, './get-package-manager')); +const utilsDirectory = path.resolve(__dirname, "../../packages/webpack-cli/lib/utils/"); +const getPackageManager = require(path.resolve(utilsDirectory, "./get-package-manager")); -jest.mock(path.resolve(utilsDirectory, './get-package-manager'), () => jest.fn()); -const globalModulesNpmValue = 'test-npm'; -jest.setMock('global-modules', globalModulesNpmValue); -jest.setMock(path.resolve(utilsDirectory, './prompt'), jest.fn()); +jest.mock(path.resolve(utilsDirectory, "./get-package-manager"), () => jest.fn()); +const globalModulesNpmValue = "test-npm"; +jest.setMock("global-modules", globalModulesNpmValue); +jest.setMock(path.resolve(utilsDirectory, "./prompt"), jest.fn()); -describe('packageUtils', () => { - describe('getPackageManager', () => { - const testYarnLockPath = path.resolve(__dirname, 'test-yarn-lock'); - const testNpmLockPath = path.resolve(__dirname, 'test-npm-lock'); - const testPnpmLockPath = path.resolve(__dirname, 'test-pnpm-lock'); - const testNpmAndPnpmPath = path.resolve(__dirname, 'test-npm-and-pnpm'); - const testNpmAndYarnPath = path.resolve(__dirname, 'test-npm-and-yarn'); - const testYarnAndPnpmPath = path.resolve(__dirname, 'test-yarn-and-pnpm'); - const testAllPath = path.resolve(__dirname, 'test-all-lock'); - const noLockPath = path.resolve(__dirname, 'no-lock-files'); +describe("packageUtils", () => { + describe("getPackageManager", () => { + const testYarnLockPath = path.resolve(__dirname, "test-yarn-lock"); + const testNpmLockPath = path.resolve(__dirname, "test-npm-lock"); + const testPnpmLockPath = path.resolve(__dirname, "test-pnpm-lock"); + const testNpmAndPnpmPath = path.resolve(__dirname, "test-npm-and-pnpm"); + const testNpmAndYarnPath = path.resolve(__dirname, "test-npm-and-yarn"); + const testYarnAndPnpmPath = path.resolve(__dirname, "test-yarn-and-pnpm"); + const testAllPath = path.resolve(__dirname, "test-all-lock"); + const noLockPath = path.resolve(__dirname, "no-lock-files"); - const cwdSpy = jest.spyOn(process, 'cwd'); + const cwdSpy = jest.spyOn(process, "cwd"); beforeAll(() => { // package-lock.json is ignored by .gitignore, so we simply @@ -36,71 +36,71 @@ describe('packageUtils', () => { if (!fs.existsSync(testNpmLockPath)) { fs.mkdirSync(testNpmLockPath); } - fs.writeFileSync(path.resolve(testNpmLockPath, 'package-lock.json'), ''); - fs.writeFileSync(path.resolve(testNpmAndPnpmPath, 'package-lock.json'), ''); - fs.writeFileSync(path.resolve(testNpmAndYarnPath, 'package-lock.json'), ''); - fs.writeFileSync(path.resolve(testAllPath, 'package-lock.json'), ''); + fs.writeFileSync(path.resolve(testNpmLockPath, "package-lock.json"), ""); + fs.writeFileSync(path.resolve(testNpmAndPnpmPath, "package-lock.json"), ""); + fs.writeFileSync(path.resolve(testNpmAndYarnPath, "package-lock.json"), ""); + fs.writeFileSync(path.resolve(testAllPath, "package-lock.json"), ""); }); beforeEach(() => { syncMock.mockClear(); }); - it('should find yarn.lock', () => { + it("should find yarn.lock", () => { cwdSpy.mockReturnValue(testYarnLockPath); - expect(getPackageManager()).toEqual('yarn'); + expect(getPackageManager()).toEqual("yarn"); expect(syncMock.mock.calls.length).toEqual(0); }); - it('should find package-lock.json', () => { + it("should find package-lock.json", () => { cwdSpy.mockReturnValue(testNpmLockPath); - expect(getPackageManager()).toEqual('npm'); + expect(getPackageManager()).toEqual("npm"); expect(syncMock.mock.calls.length).toEqual(0); }); - it('should find pnpm-lock.yaml', () => { + it("should find pnpm-lock.yaml", () => { cwdSpy.mockReturnValue(testPnpmLockPath); - expect(getPackageManager()).toEqual('pnpm'); + expect(getPackageManager()).toEqual("pnpm"); expect(syncMock.mock.calls.length).toEqual(0); }); - it('should prioritize npm over pnpm', () => { + it("should prioritize npm over pnpm", () => { cwdSpy.mockReturnValue(testNpmAndPnpmPath); - expect(getPackageManager()).toEqual('npm'); + expect(getPackageManager()).toEqual("npm"); expect(syncMock.mock.calls.length).toEqual(0); }); - it('should prioritize npm over yarn', () => { + it("should prioritize npm over yarn", () => { cwdSpy.mockReturnValue(testNpmAndYarnPath); - expect(getPackageManager()).toEqual('npm'); + expect(getPackageManager()).toEqual("npm"); expect(syncMock.mock.calls.length).toEqual(0); }); - it('should prioritize yarn over pnpm', () => { + it("should prioritize yarn over pnpm", () => { cwdSpy.mockReturnValue(testYarnAndPnpmPath); - expect(getPackageManager()).toEqual('yarn'); + expect(getPackageManager()).toEqual("yarn"); expect(syncMock.mock.calls.length).toEqual(0); }); - it('should prioritize npm with many lock files', () => { + it("should prioritize npm with many lock files", () => { cwdSpy.mockReturnValue(testAllPath); - expect(getPackageManager()).toEqual('npm'); + expect(getPackageManager()).toEqual("npm"); expect(syncMock.mock.calls.length).toEqual(0); }); - it('should prioritize global npm over other package managers', () => { + it("should prioritize global npm over other package managers", () => { cwdSpy.mockReturnValue(noLockPath); - expect(getPackageManager()).toEqual('npm'); + expect(getPackageManager()).toEqual("npm"); expect(syncMock.mock.calls.length).toEqual(1); }); - it('should throw error if no package manager is found', () => { + it("should throw error if no package manager is found", () => { syncMock.mockImplementation(() => { throw new Error(); }); - const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {}); + const mockExit = jest.spyOn(process, "exit").mockImplementation(() => {}); // Do not print warning in CI - const consoleMock = jest.spyOn(console, 'error').mockImplementation(() => {}); + const consoleMock = jest.spyOn(console, "error").mockImplementation(() => {}); expect(getPackageManager()).toBeFalsy(); expect(mockExit).toBeCalledWith(2); expect(consoleMock).toHaveBeenCalledTimes(1); diff --git a/test/api/prompt-installation.test.js b/test/api/prompt-installation.test.js index 666b218fc0f..691b8b123b8 100644 --- a/test/api/prompt-installation.test.js +++ b/test/api/prompt-installation.test.js @@ -1,25 +1,25 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const stripAnsi = require('strip-ansi'); -const globalModulesNpmValue = 'test-npm'; -const utilsDirectory = path.resolve(__dirname, '../../packages/webpack-cli/lib/utils/'); - -jest.setMock('global-modules', globalModulesNpmValue); -jest.setMock(path.resolve(utilsDirectory, './prompt'), jest.fn()); -jest.setMock(path.resolve(utilsDirectory, './run-command'), jest.fn()); -jest.setMock(path.resolve(utilsDirectory, './package-exists'), jest.fn()); -jest.setMock(path.resolve(utilsDirectory, './get-package-manager'), jest.fn()); - -const getPackageManager = require(path.resolve(utilsDirectory, './get-package-manager')); -const packageExists = require(path.resolve(utilsDirectory, './package-exists')); -const promptInstallation = require(path.resolve(utilsDirectory, './prompt-installation')); -const runCommand = require(path.resolve(utilsDirectory, './run-command')); -const prompt = require(path.resolve(utilsDirectory, './prompt')); - -describe('promptInstallation', () => { +const stripAnsi = require("strip-ansi"); +const globalModulesNpmValue = "test-npm"; +const utilsDirectory = path.resolve(__dirname, "../../packages/webpack-cli/lib/utils/"); + +jest.setMock("global-modules", globalModulesNpmValue); +jest.setMock(path.resolve(utilsDirectory, "./prompt"), jest.fn()); +jest.setMock(path.resolve(utilsDirectory, "./run-command"), jest.fn()); +jest.setMock(path.resolve(utilsDirectory, "./package-exists"), jest.fn()); +jest.setMock(path.resolve(utilsDirectory, "./get-package-manager"), jest.fn()); + +const getPackageManager = require(path.resolve(utilsDirectory, "./get-package-manager")); +const packageExists = require(path.resolve(utilsDirectory, "./package-exists")); +const promptInstallation = require(path.resolve(utilsDirectory, "./prompt-installation")); +const runCommand = require(path.resolve(utilsDirectory, "./run-command")); +const prompt = require(path.resolve(utilsDirectory, "./prompt")); + +describe("promptInstallation", () => { beforeAll(() => { packageExists.mockReturnValue(true); }); @@ -28,13 +28,13 @@ describe('promptInstallation', () => { prompt.mockClear(); }); - it('should prompt to install using npm if npm is package manager', async () => { + it("should prompt to install using npm if npm is package manager", async () => { prompt.mockReturnValue(true); - getPackageManager.mockReturnValue('npm'); + getPackageManager.mockReturnValue("npm"); const preMessage = jest.fn(); - const promptResult = await promptInstallation('test-package', preMessage); + const promptResult = await promptInstallation("test-package", preMessage); expect(promptResult).toBeTruthy(); expect(preMessage.mock.calls.length).toEqual(1); @@ -45,15 +45,15 @@ describe('promptInstallation', () => { ); // install the package using npm - expect(runCommand.mock.calls[0][0]).toEqual('npm install -D test-package'); + expect(runCommand.mock.calls[0][0]).toEqual("npm install -D test-package"); }); - it('should prompt to install using yarn if yarn is package manager', async () => { + it("should prompt to install using yarn if yarn is package manager", async () => { prompt.mockReturnValue({ installConfirm: true }); - getPackageManager.mockReturnValue('yarn'); + getPackageManager.mockReturnValue("yarn"); - const promptResult = await promptInstallation('test-package'); + const promptResult = await promptInstallation("test-package"); expect(promptResult).toBeTruthy(); expect(prompt.mock.calls.length).toEqual(1); @@ -63,15 +63,15 @@ describe('promptInstallation', () => { ); // install the package using yarn - expect(runCommand.mock.calls[0][0]).toEqual('yarn add -D test-package'); + expect(runCommand.mock.calls[0][0]).toEqual("yarn add -D test-package"); }); - it('should prompt to install using pnpm if pnpm is package manager', async () => { + it("should prompt to install using pnpm if pnpm is package manager", async () => { prompt.mockReturnValue({ installConfirm: true }); - getPackageManager.mockReturnValue('pnpm'); + getPackageManager.mockReturnValue("pnpm"); - const promptResult = await promptInstallation('test-package'); + const promptResult = await promptInstallation("test-package"); expect(promptResult).toBeTruthy(); expect(prompt.mock.calls.length).toEqual(1); @@ -81,16 +81,16 @@ describe('promptInstallation', () => { ); // install the package using npm - expect(runCommand.mock.calls[0][0]).toEqual('pnpm install -D test-package'); + expect(runCommand.mock.calls[0][0]).toEqual("pnpm install -D test-package"); }); - it('should support pre message', async () => { + it("should support pre message", async () => { prompt.mockReturnValue({ installConfirm: true }); - getPackageManager.mockReturnValue('npm'); + getPackageManager.mockReturnValue("npm"); const preMessage = jest.fn(); - const promptResult = await promptInstallation('test-package', preMessage); + const promptResult = await promptInstallation("test-package", preMessage); expect(promptResult).toBeTruthy(); expect(preMessage.mock.calls.length).toEqual(1); @@ -101,14 +101,14 @@ describe('promptInstallation', () => { ); // install the package using npm - expect(runCommand.mock.calls[0][0]).toEqual('npm install -D test-package'); + expect(runCommand.mock.calls[0][0]).toEqual("npm install -D test-package"); }); - it('should not install if install is not confirmed', async () => { + it("should not install if install is not confirmed", async () => { prompt.mockReturnValue(false); - const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {}); - const promptResult = await promptInstallation('test-package'); + const mockExit = jest.spyOn(process, "exit").mockImplementation(() => {}); + const promptResult = await promptInstallation("test-package"); expect(promptResult).toBeUndefined(); expect(prompt.mock.calls.length).toEqual(1); diff --git a/test/api/prompt.test.js b/test/api/prompt.test.js index 2ebf672b306..752f2aafb49 100755 --- a/test/api/prompt.test.js +++ b/test/api/prompt.test.js @@ -1,7 +1,7 @@ -const prompt = require('../../packages/webpack-cli/lib/utils/prompt'); -const { Writable } = require('stream'); +const prompt = require("../../packages/webpack-cli/lib/utils/prompt"); +const { Writable } = require("stream"); -describe('prompt', () => { +describe("prompt", () => { class MyWritable extends Writable { constructor(answer) { super(); @@ -13,18 +13,18 @@ describe('prompt', () => { } } - it('should work with default response', async () => { - const myWritable = new MyWritable('\r'); + it("should work with default response", async () => { + const myWritable = new MyWritable("\r"); const resultSuccess = await prompt({ - message: 'message', - defaultResponse: 'yes', + message: "message", + defaultResponse: "yes", stream: myWritable, }); const resultFail = await prompt({ - message: 'message', - defaultResponse: 'no', + message: "message", + defaultResponse: "no", stream: myWritable, }); @@ -33,18 +33,18 @@ describe('prompt', () => { }); it('should work with "yes" && "y" response', async () => { - const myWritable1 = new MyWritable('yes\r'); - const myWritable2 = new MyWritable('y\r'); + const myWritable1 = new MyWritable("yes\r"); + const myWritable2 = new MyWritable("y\r"); const resultSuccess1 = await prompt({ - message: 'message', - defaultResponse: 'no', + message: "message", + defaultResponse: "no", stream: myWritable1, }); const resultSuccess2 = await prompt({ - message: 'message', - defaultResponse: 'no', + message: "message", + defaultResponse: "no", stream: myWritable2, }); @@ -52,12 +52,12 @@ describe('prompt', () => { expect(resultSuccess2).toBe(true); }); - it('should work with unknown response', async () => { - const myWritable = new MyWritable('unknown\r'); + it("should work with unknown response", async () => { + const myWritable = new MyWritable("unknown\r"); const result = await prompt({ - message: 'message', - defaultResponse: 'yes', + message: "message", + defaultResponse: "yes", stream: myWritable, }); diff --git a/test/api/resolveConfig/env.webpack.config.cjs b/test/api/resolveConfig/env.webpack.config.cjs index d835806ac3c..ef09161948b 100644 --- a/test/api/resolveConfig/env.webpack.config.cjs +++ b/test/api/resolveConfig/env.webpack.config.cjs @@ -2,6 +2,6 @@ module.exports = function (env) { const configName = env.name; return { name: configName, - mode: env.test ? 'staging' : 'production', + mode: env.test ? "staging" : "production", }; }; diff --git a/test/api/resolveConfig/resolveConfig.test.js b/test/api/resolveConfig/resolveConfig.test.js index cff857beb18..83450146495 100644 --- a/test/api/resolveConfig/resolveConfig.test.js +++ b/test/api/resolveConfig/resolveConfig.test.js @@ -1,56 +1,69 @@ -const { resolve } = require('path'); -const WebpackCLI = require('../../../packages/webpack-cli/lib/webpack-cli'); -const config1 = require('./webpack.config1.cjs'); -const config2 = require('./webpack.config2.cjs'); -const arrayConfig = require('./webpack.config.cjs'); -const promiseConfig = require('./webpack.promise.config.cjs'); +const { resolve } = require("path"); +const WebpackCLI = require("../../../packages/webpack-cli/lib/webpack-cli"); +const config1 = require("./webpack.config1.cjs"); +const config2 = require("./webpack.config2.cjs"); +const arrayConfig = require("./webpack.config.cjs"); +const promiseConfig = require("./webpack.promise.config.cjs"); const cli = new WebpackCLI(); -describe('resolveConfig', function () { - it('should handle merge properly', async () => { +describe("resolveConfig", function () { + it("should handle merge properly", async () => { const result = await cli.resolveConfig({ merge: true, - config: [resolve(__dirname, './webpack.config.cjs')], + config: [resolve(__dirname, "./webpack.config.cjs")], }); const expectedOptions = { - output: { filename: './dist-commonjs.js', libraryTarget: 'commonjs' }, - entry: './a.js', - name: 'amd', - mode: 'production', - devtool: 'eval-cheap-module-source-map', - target: 'node', + output: { + filename: "./dist-commonjs.js", + libraryTarget: "commonjs", + }, + entry: "./a.js", + name: "amd", + mode: "production", + devtool: "eval-cheap-module-source-map", + target: "node", }; expect(result.options).toEqual(expectedOptions); }); - it('should return array for multiple config', async () => { + it("should return array for multiple config", async () => { const result = await cli.resolveConfig({ - config: [resolve(__dirname, './webpack.config1.cjs'), resolve(__dirname, './webpack.config2.cjs')], + config: [ + resolve(__dirname, "./webpack.config1.cjs"), + resolve(__dirname, "./webpack.config2.cjs"), + ], }); const expectedOptions = [config1, config2]; expect(result.options).toEqual(expectedOptions); }); - it('should return config object for single config', async () => { - const result = await cli.resolveConfig({ config: [resolve(__dirname, './webpack.config1.cjs')] }); + it("should return config object for single config", async () => { + const result = await cli.resolveConfig({ + config: [resolve(__dirname, "./webpack.config1.cjs")], + }); expect(result.options).toEqual(config1); }); - it('should return resolved config object for promise config', async () => { - const result = await cli.resolveConfig({ config: [resolve(__dirname, './webpack.promise.config.cjs')] }); + it("should return resolved config object for promise config", async () => { + const result = await cli.resolveConfig({ + config: [resolve(__dirname, "./webpack.promise.config.cjs")], + }); const expectedOptions = await promiseConfig(); expect(result.options).toEqual(expectedOptions); }); - it('should handle configs returning different types', async () => { + it("should handle configs returning different types", async () => { const result = await cli.resolveConfig({ - config: [resolve(__dirname, './webpack.promise.config.cjs'), resolve(__dirname, './webpack.config.cjs')], + config: [ + resolve(__dirname, "./webpack.promise.config.cjs"), + resolve(__dirname, "./webpack.config.cjs"), + ], }); const resolvedPromiseConfig = await promiseConfig(); const expectedOptions = [resolvedPromiseConfig, ...arrayConfig]; @@ -58,12 +71,12 @@ describe('resolveConfig', function () { expect(result.options).toEqual(expectedOptions); }); - it('should handle different env formats', async () => { + it("should handle different env formats", async () => { const result = await cli.resolveConfig({ - argv: { env: { test: true, name: 'Hisoka' } }, - config: [resolve(__dirname, './env.webpack.config.cjs')], + argv: { env: { test: true, name: "Hisoka" } }, + config: [resolve(__dirname, "./env.webpack.config.cjs")], }); - const expectedOptions = { mode: 'staging', name: 'Hisoka' }; + const expectedOptions = { mode: "staging", name: "Hisoka" }; expect(result.options).toEqual(expectedOptions); }); diff --git a/test/api/resolveConfig/webpack.config.cjs b/test/api/resolveConfig/webpack.config.cjs index be8b318c4ae..790bfaea913 100644 --- a/test/api/resolveConfig/webpack.config.cjs +++ b/test/api/resolveConfig/webpack.config.cjs @@ -1,21 +1,21 @@ module.exports = [ { output: { - filename: './dist-amd.js', - libraryTarget: 'amd', + filename: "./dist-amd.js", + libraryTarget: "amd", }, - entry: './a.js', - name: 'amd', - mode: 'development', - devtool: 'eval-cheap-module-source-map', + entry: "./a.js", + name: "amd", + mode: "development", + devtool: "eval-cheap-module-source-map", }, { output: { - filename: './dist-commonjs.js', - libraryTarget: 'commonjs', + filename: "./dist-commonjs.js", + libraryTarget: "commonjs", }, - entry: './a.js', - mode: 'production', - target: 'node', + entry: "./a.js", + mode: "production", + target: "node", }, ]; diff --git a/test/api/resolveConfig/webpack.config1.cjs b/test/api/resolveConfig/webpack.config1.cjs index 574e45209ff..9c66f25c9aa 100644 --- a/test/api/resolveConfig/webpack.config1.cjs +++ b/test/api/resolveConfig/webpack.config1.cjs @@ -1,7 +1,7 @@ module.exports = { output: { - libraryTarget: 'amd', + libraryTarget: "amd", }, - entry: './a.js', - name: 'amd', + entry: "./a.js", + name: "amd", }; diff --git a/test/api/resolveConfig/webpack.config2.cjs b/test/api/resolveConfig/webpack.config2.cjs index 551eb311c26..f835b84a40f 100644 --- a/test/api/resolveConfig/webpack.config2.cjs +++ b/test/api/resolveConfig/webpack.config2.cjs @@ -1,8 +1,8 @@ module.exports = { output: { - libraryTarget: 'commonjs', + libraryTarget: "commonjs", }, - entry: './a.js', - mode: 'production', - target: 'node', + entry: "./a.js", + mode: "production", + target: "node", }; diff --git a/test/api/resolveConfig/webpack.promise.config.cjs b/test/api/resolveConfig/webpack.promise.config.cjs index f657e66b809..97380066bba 100644 --- a/test/api/resolveConfig/webpack.promise.config.cjs +++ b/test/api/resolveConfig/webpack.promise.config.cjs @@ -2,10 +2,10 @@ module.exports = () => { return new Promise((resolve) => { setTimeout(() => { resolve({ - entry: './a', + entry: "./a", output: { - path: __dirname + '/binary', - filename: 'promise.js', + path: __dirname + "/binary", + filename: "promise.js", }, }); }, 500); diff --git a/test/api/scaffold-utils.test.js b/test/api/scaffold-utils.test.js index bea825029f4..06cdc64bfcb 100755 --- a/test/api/scaffold-utils.test.js +++ b/test/api/scaffold-utils.test.js @@ -1,7 +1,12 @@ -// eslint-disable-next-line node/no-missing-require -const { Confirm, List, InputValidate, Input } = require('../../packages/generators/src/utils/scaffold-utils'); +const { + Confirm, + List, + InputValidate, + Input, + // eslint-disable-next-line node/no-missing-require +} = require("../../packages/generators/src/utils/scaffold-utils"); -describe('utils', () => { +describe("utils", () => { let mockSelf; beforeEach(() => { @@ -11,64 +16,79 @@ describe('utils', () => { }, }; }); - describe('Inquirer', () => { - it('should emulate a prompt for List', () => { - expect(List(mockSelf, 'entry', 'does it work?', ['Yes', 'Maybe'], 'Yes')).toEqual({ - choices: ['Yes', 'Maybe'], - type: 'list', - name: 'entry', - message: 'does it work?', - default: 'Yes', + describe("Inquirer", () => { + it("should emulate a prompt for List", () => { + expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes")).toEqual({ + choices: ["Yes", "Maybe"], + type: "list", + name: "entry", + message: "does it work?", + default: "Yes", }); }); - it('should make default value for a List', () => { - expect(List(mockSelf, 'entry', 'does it work?', ['Yes', 'Maybe'], 'Yes', true)).toEqual({ - entry: 'Yes', - }); + it("should make default value for a List", () => { + expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes", true)).toEqual( + { + entry: "Yes", + }, + ); }); - it('should emulate a prompt for list input', () => { - expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'openJSF')).toEqual({ - type: 'input', - name: 'plugins', - message: 'what is your plugin?', - default: 'openJSF', + it("should emulate a prompt for list input", () => { + expect(Input(mockSelf, "plugins", "what is your plugin?", "openJSF")).toEqual({ + type: "input", + name: "plugins", + message: "what is your plugin?", + default: "openJSF", }); }); - it('should return a default Input object value', () => { - expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'my-plugin', true)).toEqual({ - plugins: 'my-plugin', + it("should return a default Input object value", () => { + expect(Input(mockSelf, "plugins", "what is your plugin?", "my-plugin", true)).toEqual({ + plugins: "my-plugin", }); }); - it('should emulate a prompt for confirm', () => { - expect(Confirm(mockSelf, 'context', 'what is your context?')).toEqual({ - name: 'context', + it("should emulate a prompt for confirm", () => { + expect(Confirm(mockSelf, "context", "what is your context?")).toEqual({ + name: "context", default: true, - message: 'what is your context?', - type: 'confirm', + message: "what is your context?", + type: "confirm", }); }); - it('should make a Confirm object with yes as default', () => { - expect(Confirm(mockSelf, 'context', 'what is your context?', true, true)).toEqual({ + it("should make a Confirm object with yes as default", () => { + expect(Confirm(mockSelf, "context", "what is your context?", true, true)).toEqual({ context: true, }); }); - it('should make an Input object with validation', () => { - expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true)).toMatchSnapshot(); + it("should make an Input object with validation", () => { + expect( + InputValidate(mockSelf, "plugins", "what is your plugin?", () => true), + ).toMatchSnapshot(); }); - it('should make an Input object with validation and default value', () => { - expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin')).toMatchSnapshot(); + it("should make an Input object with validation and default value", () => { + expect( + InputValidate(mockSelf, "plugins", "what is your plugin?", () => true, "my-plugin"), + ).toMatchSnapshot(); }); - it('should return a default Input object with validation and default value', () => { - expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin', true)).toEqual({ - plugins: 'my-plugin', + it("should return a default Input object with validation and default value", () => { + expect( + InputValidate( + mockSelf, + "plugins", + "what is your plugin?", + () => true, + "my-plugin", + true, + ), + ).toEqual({ + plugins: "my-plugin", }); }); }); diff --git a/test/build/analyze/analyze-flag.test.js b/test/build/analyze/analyze-flag.test.js index 6807d6c6e3c..1b45e71a53d 100644 --- a/test/build/analyze/analyze-flag.test.js +++ b/test/build/analyze/analyze-flag.test.js @@ -1,14 +1,20 @@ -'use strict'; +"use strict"; -const { run, normalizeStdout } = require('../../utils/test-utils'); +const { run, normalizeStdout } = require("../../utils/test-utils"); describe('"analyze" option', () => { - it('should not load webpack-bundle-analyzer plugin twice with --analyze flag and plugin', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './analyze.config.js', '--analyze']); + it("should not load webpack-bundle-analyzer plugin twice with --analyze flag and plugin", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./analyze.config.js", + "--analyze", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(normalizeStdout(stdout)).toContain('Webpack Bundle Analyzer saved report to'); - expect(normalizeStdout(stdout).match(/Webpack Bundle Analyzer saved report to/g)).toHaveLength(1); + expect(normalizeStdout(stdout)).toContain("Webpack Bundle Analyzer saved report to"); + expect( + normalizeStdout(stdout).match(/Webpack Bundle Analyzer saved report to/g), + ).toHaveLength(1); }); }); diff --git a/test/build/analyze/analyze.config.js b/test/build/analyze/analyze.config.js index 71329e267b0..a1671a29911 100644 --- a/test/build/analyze/analyze.config.js +++ b/test/build/analyze/analyze.config.js @@ -1,7 +1,12 @@ // eslint-disable-next-line node/no-unpublished-require -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); +const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); module.exports = { - mode: 'development', - plugins: [new BundleAnalyzerPlugin({ analyzerMode: 'static', openAnalyzer: false })], + mode: "development", + plugins: [ + new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + }), + ], }; diff --git a/test/build/analyze/webpack.config.js b/test/build/analyze/webpack.config.js index 1bd7a2cee42..bbb2b37c677 100644 --- a/test/build/analyze/webpack.config.js +++ b/test/build/analyze/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { - mode: 'development', + mode: "development", plugins: [], }; diff --git a/test/build/bail/bail-and-watch-webpack.config.js b/test/build/bail/bail-and-watch-webpack.config.js index 85d95542909..e29774ed94d 100644 --- a/test/build/bail/bail-and-watch-webpack.config.js +++ b/test/build/bail/bail-and-watch-webpack.config.js @@ -1,7 +1,7 @@ module.exports = { - entry: './src/first.js', + entry: "./src/first.js", devtool: false, - mode: 'development', + mode: "development", bail: true, watch: true, }; diff --git a/test/build/bail/bail-multi-webpack.config.js b/test/build/bail/bail-multi-webpack.config.js index d36a8ba9fe3..c2890ba9fff 100644 --- a/test/build/bail/bail-multi-webpack.config.js +++ b/test/build/bail/bail-multi-webpack.config.js @@ -2,20 +2,20 @@ module.exports = [ { devtool: false, output: { - filename: './dist-first.js', + filename: "./dist-first.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', + name: "first", + entry: "./src/first.js", + mode: "development", bail: true, }, { devtool: false, output: { - filename: './dist-second.js', + filename: "./dist-second.js", }, - name: 'second', - entry: './src/second.js', - mode: 'development', + name: "second", + entry: "./src/second.js", + mode: "development", }, ]; diff --git a/test/build/bail/bail-webpack.config.js b/test/build/bail/bail-webpack.config.js index d3f445c8782..67c7bb44a8f 100644 --- a/test/build/bail/bail-webpack.config.js +++ b/test/build/bail/bail-webpack.config.js @@ -1,6 +1,6 @@ module.exports = { devtool: false, - entry: './src/first.js', - mode: 'development', + entry: "./src/first.js", + mode: "development", bail: true, }; diff --git a/test/build/bail/bail.test.js b/test/build/bail/bail.test.js index 1fc876c43b7..9e246571648 100644 --- a/test/build/bail/bail.test.js +++ b/test/build/bail/bail.test.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('bail and watch warning', () => { - it('should not log warning in not watch mode', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'bail-webpack.config.js']); +describe("bail and watch warning", () => { + it("should not log warning in not watch mode", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "bail-webpack.config.js"]); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); @@ -12,7 +12,10 @@ describe('bail and watch warning', () => { }); it('should not log warning in not watch mode without the "bail" option', async () => { - const { exitCode, stderr, stdout } = 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).toBeFalsy(); diff --git a/test/build/bail/multi-webpack.config.js b/test/build/bail/multi-webpack.config.js index b36638f118f..9fe0cb532f1 100644 --- a/test/build/bail/multi-webpack.config.js +++ b/test/build/bail/multi-webpack.config.js @@ -2,21 +2,21 @@ module.exports = [ { devtool: false, output: { - filename: './dist-first.js', + filename: "./dist-first.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', + name: "first", + entry: "./src/first.js", + mode: "development", bail: true, watch: true, }, { devtool: false, output: { - filename: './dist-second.js', + filename: "./dist-second.js", }, - name: 'second', - entry: './src/second.js', - mode: 'development', + name: "second", + entry: "./src/second.js", + mode: "development", }, ]; diff --git a/test/build/bail/no-bail-webpack.config.js b/test/build/bail/no-bail-webpack.config.js index 8cf031757bd..b55c39fc397 100644 --- a/test/build/bail/no-bail-webpack.config.js +++ b/test/build/bail/no-bail-webpack.config.js @@ -1,5 +1,5 @@ module.exports = { devtool: false, - entry: './src/first.js', - mode: 'development', + entry: "./src/first.js", + mode: "development", }; diff --git a/test/build/bail/src/first.js b/test/build/bail/src/first.js index fb7e56835c4..6566b640f0b 100644 --- a/test/build/bail/src/first.js +++ b/test/build/bail/src/first.js @@ -1 +1 @@ -console.log('bail and watch warning test first'); +console.log("bail and watch warning test first"); diff --git a/test/build/bail/src/second.js b/test/build/bail/src/second.js index 5b277372189..aebac93b7f8 100644 --- a/test/build/bail/src/second.js +++ b/test/build/bail/src/second.js @@ -1 +1 @@ -console.log('bail and watch warning test second'); +console.log("bail and watch warning test second"); diff --git a/test/build/bail/watch-webpack.config.js b/test/build/bail/watch-webpack.config.js index fa93f3f225b..bf6be48c2c7 100644 --- a/test/build/bail/watch-webpack.config.js +++ b/test/build/bail/watch-webpack.config.js @@ -1,6 +1,6 @@ module.exports = { devtool: false, - entry: './src/first.js', - mode: 'development', + entry: "./src/first.js", + mode: "development", watch: true, }; diff --git a/test/build/basic/basic.test.js b/test/build/basic/basic.test.js index a21fcb50af2..a6a089e062e 100644 --- a/test/build/basic/basic.test.js +++ b/test/build/basic/basic.test.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run } = require('../../utils/test-utils'); +const { resolve } = require("path"); +const { run } = require("../../utils/test-utils"); -describe('bundle command', () => { - it('should work without command (default command)', async () => { +describe("bundle command", () => { + it("should work without command (default command)", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); @@ -12,48 +12,71 @@ describe('bundle command', () => { expect(stdout).toBeTruthy(); }); - it('should work without command and options (default command)', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development']); + it("should work without command and options (default command)", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "development"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should work with multiple entries syntax without command (default command)', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js']); + it("should work with multiple entries syntax without command (default command)", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should work with multiple entries syntax without command with options (default command)', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--mode', 'development']); + it("should work with multiple entries syntax without command with options (default command)", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + "--mode", + "development", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should work with multiple entries syntax without command with options #2 (default command)', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development', './src/index.js', './src/other.js']); + it("should work with multiple entries syntax without command with options #2 (default command)", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "development", + "./src/index.js", + "./src/other.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should work with multiple entries syntax without command with options #3 (default command)', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--entry', './src/again.js']); + it("should work with multiple entries syntax without command with options #3 (default command)", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + "--entry", + "./src/again.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should work with and override entries from the configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--config', './entry.config.js']); + it("should work with and override entries from the configuration", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + "--config", + "./entry.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -61,7 +84,7 @@ describe('bundle command', () => { }); it('should work with the "build" alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['build']); + const { exitCode, stderr, stdout } = await run(__dirname, ["build"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -69,7 +92,7 @@ describe('bundle command', () => { }); it('should work with "bundle" alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle']); + const { exitCode, stderr, stdout } = await run(__dirname, ["bundle"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -77,7 +100,7 @@ describe('bundle command', () => { }); it('should work with the "b" alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['b']); + const { exitCode, stderr, stdout } = await run(__dirname, ["b"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -85,7 +108,7 @@ describe('bundle command', () => { }); it('should work with entries syntax using the "build" alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js']); + const { exitCode, stderr, stdout } = await run(__dirname, ["build", "./src/index.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -93,7 +116,7 @@ describe('bundle command', () => { }); it('should work with entries syntax using the "bundle" alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', './src/index.js']); + const { exitCode, stderr, stdout } = await run(__dirname, ["bundle", "./src/index.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -101,7 +124,7 @@ describe('bundle command', () => { }); it('should work with entries syntax using the "b" alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['b', './src/index.js']); + const { exitCode, stderr, stdout } = await run(__dirname, ["b", "./src/index.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -109,7 +132,11 @@ describe('bundle command', () => { }); it('should work with multiple entries syntax using the "build" alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js', './src/other.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "build", + "./src/index.js", + "./src/other.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -117,7 +144,13 @@ describe('bundle command', () => { }); it('should work with multiple entries syntax using the "build" alias and options', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js', './src/other.js', '--mode', 'development']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "build", + "./src/index.js", + "./src/other.js", + "--mode", + "development", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -125,7 +158,13 @@ describe('bundle command', () => { }); it('should work with multiple entries syntax using the "build" alias and options', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['build', '--mode', 'development', './src/index.js', './src/other.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "build", + "--mode", + "development", + "./src/index.js", + "./src/other.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -133,7 +172,7 @@ describe('bundle command', () => { }); it('should log error and suggest right name on the "buil" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['buil']); + const { exitCode, stderr, stdout } = await run(__dirname, ["buil"]); expect(exitCode).toBe(2); expect(stderr).toContain("Unknown command or entry 'buil'"); @@ -142,14 +181,14 @@ describe('bundle command', () => { expect(stdout).toBeFalsy(); }); - it('should log supplied config when logging level is log', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './log.config.js']); - const configPath = resolve(__dirname, './log.config.js'); + it("should log supplied config when logging level is log", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--config", "./log.config.js"]); + const configPath = resolve(__dirname, "./log.config.js"); expect(exitCode).toBe(0); - expect(stderr).toContain('Compiler starting...'); + expect(stderr).toContain("Compiler starting..."); expect(stderr).toContain(`Compiler is using config: '${configPath}'`); - expect(stderr).toContain('Compiler finished'); + expect(stderr).toContain("Compiler finished"); expect(stdout).toBeTruthy(); }); }); diff --git a/test/build/basic/entry.config.js b/test/build/basic/entry.config.js index 431945f5225..f562d8db416 100644 --- a/test/build/basic/entry.config.js +++ b/test/build/basic/entry.config.js @@ -1,4 +1,4 @@ module.exports = { - mode: 'development', - entry: './src/entry.js', + mode: "development", + entry: "./src/entry.js", }; diff --git a/test/build/basic/log.config.js b/test/build/basic/log.config.js index 70619a29563..5906a9bce94 100644 --- a/test/build/basic/log.config.js +++ b/test/build/basic/log.config.js @@ -1,6 +1,6 @@ module.exports = { - mode: 'development', + mode: "development", infrastructureLogging: { - level: 'log', + level: "log", }, }; diff --git a/test/build/basic/src/again.js b/test/build/basic/src/again.js index eec159b09dc..f15e7f3d482 100644 --- a/test/build/basic/src/again.js +++ b/test/build/basic/src/again.js @@ -1 +1 @@ -console.log('again'); +console.log("again"); diff --git a/test/build/basic/src/entry.js b/test/build/basic/src/entry.js index 6daf0ddddd1..83ca8caa477 100644 --- a/test/build/basic/src/entry.js +++ b/test/build/basic/src/entry.js @@ -1 +1 @@ -console.log('CONFIG'); +console.log("CONFIG"); diff --git a/test/build/basic/src/other.js b/test/build/basic/src/other.js index 6be02374db1..6b2b3db0f65 100644 --- a/test/build/basic/src/other.js +++ b/test/build/basic/src/other.js @@ -1 +1 @@ -console.log('hello world'); +console.log("hello world"); diff --git a/test/build/build-errors/errors.test.js b/test/build/build-errors/errors.test.js index 68d91e234b3..874552f6a0d 100644 --- a/test/build/build-errors/errors.test.js +++ b/test/build/build-errors/errors.test.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -const { run, readFile } = require('../../utils/test-utils'); -const { resolve } = require('path'); +const { run, readFile } = require("../../utils/test-utils"); +const { resolve } = require("path"); -describe('errors', () => { - it('should output by default', async () => { +describe("errors", () => { + it("should output by default", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(1); @@ -14,7 +14,7 @@ describe('errors', () => { }); it('should output JSON with the "json" flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--json"]); expect(exitCode).toBe(1); expect(stderr).toBeFalsy(); @@ -22,23 +22,25 @@ describe('errors', () => { const json = JSON.parse(stdout); - expect(json['hash']).toBeDefined(); - expect(json['errors']).toHaveLength(1); + expect(json["hash"]).toBeDefined(); + expect(json["errors"]).toHaveLength(1); // `message` for `webpack@5` - expect(json['errors'][0].message ? json['errors'][0].message : json['errors'][0]).toMatch(/Can't resolve/); + expect(json["errors"][0].message ? json["errors"][0].message : json["errors"][0]).toMatch( + /Can't resolve/, + ); }); - it('should store json to a file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', 'stats.json']); + it("should store json to a file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--json", "stats.json"]); expect(exitCode).toBe(1); - expect(stderr).toContain('stats are successfully stored as json to stats.json'); + expect(stderr).toContain("stats are successfully stored as json to stats.json"); expect(stdout).toBeFalsy(); let data; try { - data = await readFile(resolve(__dirname, 'stats.json'), 'utf-8'); + data = await readFile(resolve(__dirname, "stats.json"), "utf-8"); } catch (error) { expect(error).toBe(null); } @@ -47,9 +49,11 @@ describe('errors', () => { const json = JSON.parse(data); - expect(json['hash']).toBeDefined(); - expect(json['errors']).toHaveLength(1); + expect(json["hash"]).toBeDefined(); + expect(json["errors"]).toHaveLength(1); // `message` for `webpack@5` - expect(json['errors'][0].message ? json['errors'][0].message : json['errors'][0]).toMatch(/Can't resolve/); + expect(json["errors"][0].message ? json["errors"][0].message : json["errors"][0]).toMatch( + /Can't resolve/, + ); }); }); diff --git a/test/build/build-variable/build-variable.test.js b/test/build/build-variable/build-variable.test.js index 8810b29bb40..f7f8c1d2266 100644 --- a/test/build/build-variable/build-variable.test.js +++ b/test/build/build-variable/build-variable.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('bundle variable', () => { - it('compiles without flags and export variable', async () => { +describe("bundle variable", () => { + it("compiles without flags and export variable", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('PASS'); + expect(stdout).toContain("PASS"); }); }); diff --git a/test/build/build-variable/webpack.config.js b/test/build/build-variable/webpack.config.js index a0ed78dbfb5..ab0814d6de8 100644 --- a/test/build/build-variable/webpack.config.js +++ b/test/build/build-variable/webpack.config.js @@ -5,11 +5,11 @@ class CustomTestPlugin { this.isInEnvironment = isInEnvironment; } apply(compiler) { - compiler.hooks.done.tap('testPlugin', () => { + compiler.hooks.done.tap("testPlugin", () => { if (!isInProcess && this.isInEnvironment) { - console.log('PASS'); + console.log("PASS"); } else { - console.log('FAIL'); + console.log("FAIL"); } }); } @@ -17,7 +17,7 @@ class CustomTestPlugin { module.exports = (env) => { return { - mode: 'development', + mode: "development", devtool: false, plugins: [new CustomTestPlugin(env.WEBPACK_BUILD)], }; diff --git a/test/build/build-warnings/warnings.test.js b/test/build/build-warnings/warnings.test.js index d4cf196b324..2af5019f048 100644 --- a/test/build/build-warnings/warnings.test.js +++ b/test/build/build-warnings/warnings.test.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const { run, readFile } = require('../../utils/test-utils'); -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { run, readFile } = require("../../utils/test-utils"); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -describe('warnings', () => { - it('should output by default', async () => { +describe("warnings", () => { + it("should output by default", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(0); @@ -15,7 +15,7 @@ describe('warnings', () => { }); it('should output JSON with the "json" flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--json"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -24,24 +24,26 @@ describe('warnings', () => { const json = JSON.parse(stdout); - expect(json['hash']).toBeDefined(); - expect(json['warnings']).toHaveLength(2); + expect(json["hash"]).toBeDefined(); + expect(json["warnings"]).toHaveLength(2); // `message` for `webpack@5` - expect(json['warnings'][0].message ? json['warnings'][0].message : json['warnings'][0]).toMatch(/Can't resolve/); + expect( + json["warnings"][0].message ? json["warnings"][0].message : json["warnings"][0], + ).toMatch(/Can't resolve/); }); - it('should store json to a file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', 'stats.json']); + it("should store json to a file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--json", "stats.json"]); expect(exitCode).toBe(0); - expect(stderr).toContain('stats are successfully stored as json to stats.json'); + expect(stderr).toContain("stats are successfully stored as json to stats.json"); expect(stdout).toBeFalsy(); - expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./stats.json"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, 'stats.json'), 'utf-8'); + data = await readFile(resolve(__dirname, "stats.json"), "utf-8"); } catch (error) { expect(error).toBe(null); } @@ -50,9 +52,11 @@ describe('warnings', () => { const json = JSON.parse(data); - expect(json['hash']).toBeDefined(); - expect(json['warnings']).toHaveLength(2); + expect(json["hash"]).toBeDefined(); + expect(json["warnings"]).toHaveLength(2); // `message` for `webpack@5` - expect(json['warnings'][0].message ? json['warnings'][0].message : json['warnings'][0]).toMatch(/Can't resolve/); + expect( + json["warnings"][0].message ? json["warnings"][0].message : json["warnings"][0], + ).toMatch(/Can't resolve/); }); }); diff --git a/test/build/bundle-variable/bundle-variable.test.js b/test/build/bundle-variable/bundle-variable.test.js index 8810b29bb40..f7f8c1d2266 100644 --- a/test/build/bundle-variable/bundle-variable.test.js +++ b/test/build/bundle-variable/bundle-variable.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('bundle variable', () => { - it('compiles without flags and export variable', async () => { +describe("bundle variable", () => { + it("compiles without flags and export variable", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('PASS'); + expect(stdout).toContain("PASS"); }); }); diff --git a/test/build/bundle-variable/webpack.config.js b/test/build/bundle-variable/webpack.config.js index 574cefc527c..b8e6919b2db 100644 --- a/test/build/bundle-variable/webpack.config.js +++ b/test/build/bundle-variable/webpack.config.js @@ -5,11 +5,11 @@ class CustomTestPlugin { this.isInEnvironment = isInEnvironment; } apply(compiler) { - compiler.hooks.done.tap('testPlugin', () => { + compiler.hooks.done.tap("testPlugin", () => { if (!isInProcess && this.isInEnvironment) { - console.log('PASS'); + console.log("PASS"); } else { - console.log('FAIL'); + console.log("FAIL"); } }); } @@ -17,7 +17,7 @@ class CustomTestPlugin { module.exports = (env) => { return { - mode: 'development', + mode: "development", devtool: false, plugins: [new CustomTestPlugin(env.WEBPACK_BUNDLE)], }; diff --git a/test/build/cache/cache.test.js b/test/build/cache/cache.test.js index 409652657fd..496e7c7a04e 100644 --- a/test/build/cache/cache.test.js +++ b/test/build/cache/cache.test.js @@ -1,15 +1,20 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const rimraf = require('rimraf'); -const { run, isWebpack5 } = require('../../utils/test-utils'); +const rimraf = require("rimraf"); +const { run, isWebpack5 } = require("../../utils/test-utils"); -describe('cache', () => { - it('should work', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-test-default-development')); +describe("cache", () => { + it("should work", async () => { + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-default-development", + ), + ); - let { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js']); + let { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); expect(exitCode).toEqual(0); @@ -20,7 +25,7 @@ describe('cache', () => { expect(stdout).toBeTruthy(); } - ({ exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js'])); + ({ exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"])); expect(exitCode).toEqual(0); @@ -33,11 +38,21 @@ describe('cache', () => { } }); - it('should work in multi compiler mode', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-test-first-development')); - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-test-second-development')); - - let { exitCode, stderr, stdout } = await run(__dirname, ['-c', './multi.config.js']); + it("should work in multi compiler mode", async () => { + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-first-development", + ), + ); + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-second-development", + ), + ); + + let { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js"]); expect(exitCode).toEqual(0); @@ -48,7 +63,7 @@ describe('cache', () => { expect(stdout).toBeTruthy(); } - ({ exitCode, stderr, stdout } = await run(__dirname, ['-c', './multi.config.js'])); + ({ exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js"])); expect(exitCode).toEqual(0); @@ -61,16 +76,21 @@ describe('cache', () => { } }); - it('should work in multi compiler mode with the `--config-name` argument', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-test-third-development')); + it("should work in multi compiler mode with the `--config-name` argument", async () => { + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-third-development", + ), + ); let { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '--config-name', - 'cache-test-first', - '--name', - 'cache-test-third', + "-c", + "./multi.config.js", + "--config-name", + "cache-test-first", + "--name", + "cache-test-third", ]); expect(exitCode).toEqual(0); @@ -83,12 +103,12 @@ describe('cache', () => { } ({ exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '--config-name', - 'cache-test-first', - '--name', - 'cache-test-third', + "-c", + "./multi.config.js", + "--config-name", + "cache-test-first", + "--name", + "cache-test-third", ])); expect(exitCode).toEqual(0); @@ -102,17 +122,22 @@ describe('cache', () => { } }); - it('should work with the `--merge` argument', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-test-fourth-development')); + it("should work with the `--merge` argument", async () => { + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-fourth-development", + ), + ); let { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '-c', - './webpack.config.js', - '--merge', - '--name', - 'cache-test-fourth', + "-c", + "./multi.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--name", + "cache-test-fourth", ]); expect(exitCode).toEqual(0); @@ -125,13 +150,13 @@ describe('cache', () => { } ({ exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '-c', - './webpack.config.js', - '--merge', - '--name', - 'cache-test-fourth', + "-c", + "./multi.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--name", + "cache-test-fourth", ])); expect(exitCode).toEqual(0); @@ -145,21 +170,26 @@ describe('cache', () => { } }); - it('should work with the `--config-name` and `--merge` argument', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-test-fifth-development')); + it("should work with the `--config-name` and `--merge` argument", async () => { + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-fifth-development", + ), + ); let { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '-c', - './webpack.config.js', - '--merge', - '--config-name', - 'cache-test-first', - '--config-name', - 'cache-test-second', - '--name', - 'cache-test-fifth', + "-c", + "./multi.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--config-name", + "cache-test-first", + "--config-name", + "cache-test-second", + "--name", + "cache-test-fifth", ]); expect(exitCode).toEqual(0); @@ -172,17 +202,17 @@ describe('cache', () => { } ({ exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '-c', - './webpack.config.js', - '--merge', - '--config-name', - 'cache-test-first', - '--config-name', - 'cache-test-second', - '--name', - 'cache-test-fifth', + "-c", + "./multi.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--config-name", + "cache-test-first", + "--config-name", + "cache-test-second", + "--name", + "cache-test-fifth", ])); expect(exitCode).toEqual(0); @@ -196,10 +226,18 @@ describe('cache', () => { } }); - it('should work with autoloading configuration', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-test-autoloading-development')); + it("should work with autoloading configuration", async () => { + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-autoloading-development", + ), + ); - let { exitCode, stderr, stdout } = await run(__dirname, ['--name', 'cache-test-autoloading']); + let { exitCode, stderr, stdout } = await run(__dirname, [ + "--name", + "cache-test-autoloading", + ]); expect(exitCode).toEqual(0); @@ -210,7 +248,7 @@ describe('cache', () => { expect(stdout).toBeTruthy(); } - ({ exitCode, stderr, stdout } = await run(__dirname, ['--name', 'cache-test-autoloading'])); + ({ exitCode, stderr, stdout } = await run(__dirname, ["--name", "cache-test-autoloading"])); expect(exitCode).toEqual(0); diff --git a/test/build/cache/multi.config.js b/test/build/cache/multi.config.js index d0b6222af3c..3ea23f5ed96 100644 --- a/test/build/cache/multi.config.js +++ b/test/build/cache/multi.config.js @@ -1,11 +1,11 @@ -const path = require('path'); +const path = require("path"); module.exports = [ { - mode: 'development', - name: 'cache-test-first', + mode: "development", + name: "cache-test-first", cache: { - type: 'filesystem', + type: "filesystem", buildDependencies: { config: [__filename], }, @@ -14,20 +14,20 @@ module.exports = [ debug: /cache/, }, entry: { - app: './src/main.js', + app: "./src/main.js", }, output: { - filename: '[name].bundle.js', - chunkFilename: '[name].bundle.js', - path: path.resolve(__dirname, 'dist'), - publicPath: '/', + filename: "[name].bundle.js", + chunkFilename: "[name].bundle.js", + path: path.resolve(__dirname, "dist"), + publicPath: "/", }, }, { - mode: 'development', - name: 'cache-test-second', + mode: "development", + name: "cache-test-second", cache: { - type: 'filesystem', + type: "filesystem", buildDependencies: { config: [__filename], }, @@ -36,13 +36,13 @@ module.exports = [ debug: /cache/, }, entry: { - app: './src/main.js', + app: "./src/main.js", }, output: { - filename: '[name].bundle.js', - chunkFilename: '[name].bundle.js', - path: path.resolve(__dirname, 'dist'), - publicPath: '/', + filename: "[name].bundle.js", + chunkFilename: "[name].bundle.js", + path: path.resolve(__dirname, "dist"), + publicPath: "/", }, }, ]; diff --git a/test/build/cache/src/main.js b/test/build/cache/src/main.js index fec83457547..8828db169ef 100644 --- a/test/build/cache/src/main.js +++ b/test/build/cache/src/main.js @@ -1 +1 @@ -console.log('tehghgst cache'); +console.log("tehghgst cache"); diff --git a/test/build/cache/webpack.config.js b/test/build/cache/webpack.config.js index e089c3d4b53..5e46040979e 100644 --- a/test/build/cache/webpack.config.js +++ b/test/build/cache/webpack.config.js @@ -1,10 +1,10 @@ -const path = require('path'); +const path = require("path"); module.exports = { - mode: 'development', - name: 'cache-test-default', + mode: "development", + name: "cache-test-default", cache: { - type: 'filesystem', + type: "filesystem", buildDependencies: { config: [__filename], }, @@ -13,12 +13,12 @@ module.exports = { debug: /cache/, }, entry: { - app: './src/main.js', + app: "./src/main.js", }, output: { - filename: '[name].bundle.js', - chunkFilename: '[name].bundle.js', - path: path.resolve(__dirname, 'dist'), - publicPath: '/', + filename: "[name].bundle.js", + chunkFilename: "[name].bundle.js", + path: path.resolve(__dirname, "dist"), + publicPath: "/", }, }; diff --git a/test/build/colors/colors-false.webpack.config.js b/test/build/colors/colors-false.webpack.config.js index 048815fb07d..c313e8689e2 100644 --- a/test/build/colors/colors-false.webpack.config.js +++ b/test/build/colors/colors-false.webpack.config.js @@ -2,5 +2,5 @@ module.exports = { stats: { colors: false, }, - mode: 'development', + mode: "development", }; diff --git a/test/build/colors/colors-true.webpack.config.js b/test/build/colors/colors-true.webpack.config.js index 21995734c9e..cd8f114f043 100644 --- a/test/build/colors/colors-true.webpack.config.js +++ b/test/build/colors/colors-true.webpack.config.js @@ -2,5 +2,5 @@ module.exports = { stats: { colors: true, }, - mode: 'development', + mode: "development", }; diff --git a/test/build/colors/colors.test.js b/test/build/colors/colors.test.js index 0e92a35c0ac..9d332515c6d 100644 --- a/test/build/colors/colors.test.js +++ b/test/build/colors/colors.test.js @@ -1,143 +1,179 @@ -'use strict'; +"use strict"; -const { run, isWebpack5 } = require('../../utils/test-utils'); -const { resolve } = require('path'); +const { run, isWebpack5 } = require("../../utils/test-utils"); +const { resolve } = require("path"); -describe('colors', () => { - it('should output by default', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { env: { FORCE_COLOR: true } }); +describe("colors", () => { + it("should output by default", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option from flags', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats=verbose'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["--stats=verbose"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option from flags and from configuration', async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['--stats=verbose', `--config=${resolve(__dirname, './no-stats.webpack.config.js')}`], + ["--stats=verbose", `--config=${resolve(__dirname, "./no-stats.webpack.config.js")}`], { env: { FORCE_COLOR: true } }, ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option from flags and from configuration #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats=verbose', '--config=stats-string.webpack.config.js'], { - env: { FORCE_COLOR: true }, - }); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--stats=verbose", "--config=stats-string.webpack.config.js"], + { + env: { FORCE_COLOR: true }, + }, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option and --color flags', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats=verbose', '--color']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--stats=verbose", "--color"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); - it('should disable colored output with --no-color', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats=verbose', '--no-color']); + it("should disable colored output with --no-color", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--stats=verbose", + "--no-color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(stdout).toContain(output); }); it('should work with the "stats" option from the configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=stats-string.webpack.config.js'], { - env: { FORCE_COLOR: true }, - }); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config=stats-string.webpack.config.js"], + { + env: { FORCE_COLOR: true }, + }, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option from the configuration #1', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=stats-boolean.webpack.config.js'], { - env: { FORCE_COLOR: true }, - }); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config=stats-boolean.webpack.config.js"], + { + env: { FORCE_COLOR: true }, + }, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option from the configuration #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=no-stats.webpack.config.js'], { - env: { FORCE_COLOR: true }, - }); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config=no-stats.webpack.config.js"], + { + env: { FORCE_COLOR: true }, + }, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option from the configuration #3', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=colors-true.webpack.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=colors-true.webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); it('should work with the "stats" option from the configuration #4', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=colors-false.webpack.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=colors-false.webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(stdout).toContain(output); }); - it('should prioritize --color over colors in config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=colors-false.webpack.config.js', '--color']); + it("should prioritize --color over colors in config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=colors-false.webpack.config.js", + "--color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); }); - it('should prioritize --no-color over colors in config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=colors-true.webpack.config.js', '--no-color']); + it("should prioritize --no-color over colors in config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=colors-true.webpack.config.js", + "--no-color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - const output = isWebpack5 ? 'successfully' : 'main.js'; + const output = isWebpack5 ? "successfully" : "main.js"; expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`); expect(stdout).toContain(output); }); - it('should work in multi compiler mode', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config=multiple-configs.js', '--color']); + it("should work in multi compiler mode", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=multiple-configs.js", + "--color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/colors/multiple-configs.js b/test/build/colors/multiple-configs.js index 75a5ac19fd2..5ef28ccfd71 100644 --- a/test/build/colors/multiple-configs.js +++ b/test/build/colors/multiple-configs.js @@ -1,14 +1,14 @@ module.exports = [ { - name: 'first-config', - entry: './src/first.js', - stats: 'normal', - mode: 'development', + name: "first-config", + entry: "./src/first.js", + stats: "normal", + mode: "development", }, { - name: 'second-config', - entry: './src/second.js', - stats: 'normal', - mode: 'development', + name: "second-config", + entry: "./src/second.js", + stats: "normal", + mode: "development", }, ]; diff --git a/test/build/colors/no-stats.webpack.config.js b/test/build/colors/no-stats.webpack.config.js index 8b2d7eb877e..931bbe238fb 100644 --- a/test/build/colors/no-stats.webpack.config.js +++ b/test/build/colors/no-stats.webpack.config.js @@ -1,4 +1,4 @@ module.exports = { - name: 'test', - mode: 'development', + name: "test", + mode: "development", }; diff --git a/test/build/colors/src/first.js b/test/build/colors/src/first.js index e5ba023838e..8a9423b5c10 100644 --- a/test/build/colors/src/first.js +++ b/test/build/colors/src/first.js @@ -1 +1 @@ -console.log('first'); +console.log("first"); diff --git a/test/build/colors/src/second.js b/test/build/colors/src/second.js index e1595dffb00..5023a5896d0 100644 --- a/test/build/colors/src/second.js +++ b/test/build/colors/src/second.js @@ -1 +1 @@ -console.log('second'); +console.log("second"); diff --git a/test/build/colors/stats-boolean.webpack.config.js b/test/build/colors/stats-boolean.webpack.config.js index 4b5a5355c76..7abc3543a50 100644 --- a/test/build/colors/stats-boolean.webpack.config.js +++ b/test/build/colors/stats-boolean.webpack.config.js @@ -1,4 +1,4 @@ module.exports = { stats: true, - mode: 'development', + mode: "development", }; diff --git a/test/build/colors/stats-string.webpack.config.js b/test/build/colors/stats-string.webpack.config.js index f539326edb7..404fa404f68 100644 --- a/test/build/colors/stats-string.webpack.config.js +++ b/test/build/colors/stats-string.webpack.config.js @@ -1,4 +1,4 @@ module.exports = { - stats: 'verbose', - mode: 'development', + stats: "verbose", + mode: "development", }; diff --git a/test/build/colors/webpack.config.js b/test/build/colors/webpack.config.js index f2c3976d5d3..11623bb6280 100644 --- a/test/build/colors/webpack.config.js +++ b/test/build/colors/webpack.config.js @@ -1,3 +1,3 @@ module.exports = { - mode: 'development', + mode: "development", }; diff --git a/test/build/config-format/coffee/coffee.test.js b/test/build/config-format/coffee/coffee.test.js index 0ac85cd3956..c0aa525ac1f 100644 --- a/test/build/config-format/coffee/coffee.test.js +++ b/test/build/config-format/coffee/coffee.test.js @@ -1,15 +1,15 @@ -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('webpack cli', () => { - it('should support coffeescript file as flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.coffee']); +describe("webpack cli", () => { + it("should support coffeescript file as flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.coffee"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should load coffeescript file by default', async () => { + it("should load coffeescript file by default", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); diff --git a/test/build/config-format/coffee/main.js b/test/build/config-format/coffee/main.js index 5fb227c6c10..faf5b223895 100644 --- a/test/build/config-format/coffee/main.js +++ b/test/build/config-format/coffee/main.js @@ -1 +1 @@ -console.log('Sakusa Kiyoomi'); +console.log("Sakusa Kiyoomi"); diff --git a/test/build/config-format/commonjs-default/commonjs-default.test.js b/test/build/config-format/commonjs-default/commonjs-default.test.js index 1e663dbc2b4..d1dbfad3b2d 100644 --- a/test/build/config-format/commonjs-default/commonjs-default.test.js +++ b/test/build/config-format/commonjs-default/commonjs-default.test.js @@ -1,8 +1,8 @@ -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('webpack cli', () => { - it('should support CommonJS file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.cjs']); +describe("webpack cli", () => { + it("should support CommonJS file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.cjs"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config-format/commonjs-default/main.js b/test/build/config-format/commonjs-default/main.js index 8ed93e41fb2..bea4f658c4a 100644 --- a/test/build/config-format/commonjs-default/main.js +++ b/test/build/config-format/commonjs-default/main.js @@ -1 +1 @@ -console.log('Hoshiumi'); +console.log("Hoshiumi"); diff --git a/test/build/config-format/commonjs-default/webpack.config.cjs b/test/build/config-format/commonjs-default/webpack.config.cjs index 415d965a247..c8befd13af8 100644 --- a/test/build/config-format/commonjs-default/webpack.config.cjs +++ b/test/build/config-format/commonjs-default/webpack.config.cjs @@ -1,11 +1,11 @@ -const path = require('path'); +const path = require("path"); const config = { - mode: 'production', - entry: './main.js', + mode: "production", + entry: "./main.js", output: { - path: path.resolve(__dirname, 'dist'), - filename: 'foo.bundle.js', + path: path.resolve(__dirname, "dist"), + filename: "foo.bundle.js", }, }; diff --git a/test/build/config-format/commonjs/commonjs.test.js b/test/build/config-format/commonjs/commonjs.test.js index 1e663dbc2b4..d1dbfad3b2d 100644 --- a/test/build/config-format/commonjs/commonjs.test.js +++ b/test/build/config-format/commonjs/commonjs.test.js @@ -1,8 +1,8 @@ -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('webpack cli', () => { - it('should support CommonJS file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.cjs']); +describe("webpack cli", () => { + it("should support CommonJS file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.cjs"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config-format/commonjs/main.js b/test/build/config-format/commonjs/main.js index 8ed93e41fb2..bea4f658c4a 100644 --- a/test/build/config-format/commonjs/main.js +++ b/test/build/config-format/commonjs/main.js @@ -1 +1 @@ -console.log('Hoshiumi'); +console.log("Hoshiumi"); diff --git a/test/build/config-format/commonjs/webpack.config.cjs b/test/build/config-format/commonjs/webpack.config.cjs index 7bb5d185edf..7aee196b1d9 100644 --- a/test/build/config-format/commonjs/webpack.config.cjs +++ b/test/build/config-format/commonjs/webpack.config.cjs @@ -1,11 +1,11 @@ -const path = require('path'); +const path = require("path"); const config = { - mode: 'production', - entry: './main.js', + mode: "production", + entry: "./main.js", output: { - path: path.resolve(__dirname, 'dist'), - filename: 'foo.bundle.js', + path: path.resolve(__dirname, "dist"), + filename: "foo.bundle.js", }, }; diff --git a/test/build/config-format/failure/failure.test.js b/test/build/config-format/failure/failure.test.js index b102fef11f0..ffa5ad01270 100644 --- a/test/build/config-format/failure/failure.test.js +++ b/test/build/config-format/failure/failure.test.js @@ -1,17 +1,19 @@ -const path = require('path'); +const path = require("path"); -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('failure', () => { - it('should log error on not installed registers', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.iced']); +describe("failure", () => { + it("should log error on not installed registers", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.iced"]); expect(exitCode).toBe(2); - expect(stderr).toContain(`Unable load '${path.resolve(__dirname, './webpack.config.iced')}'`); + expect(stderr).toContain( + `Unable load '${path.resolve(__dirname, "./webpack.config.iced")}'`, + ); expect(stderr).toContain('Unable to use specified module loaders for ".iced".'); expect(stderr).toContain("Cannot find module 'iced-coffee-script/register'"); expect(stderr).toContain("Cannot find module 'iced-coffee-script'"); - expect(stderr).toContain('Please install one of them'); + expect(stderr).toContain("Please install one of them"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/config-format/mjs/main.js b/test/build/config-format/mjs/main.js index a00a3125ea3..ecbe8cd001a 100644 --- a/test/build/config-format/mjs/main.js +++ b/test/build/config-format/mjs/main.js @@ -1 +1 @@ -console.log('You know who'); +console.log("You know who"); diff --git a/test/build/config-format/mjs/mjs.test.js b/test/build/config-format/mjs/mjs.test.js index a8775c8193e..baf15f4f698 100644 --- a/test/build/config-format/mjs/mjs.test.js +++ b/test/build/config-format/mjs/mjs.test.js @@ -1,8 +1,8 @@ -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('webpack cli', () => { - it('should support mjs config format', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.mjs'], { +describe("webpack cli", () => { + it("should support mjs config format", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.mjs"], { env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, }); diff --git a/test/build/config-format/mjs/webpack.config.mjs b/test/build/config-format/mjs/webpack.config.mjs index 6717d84042e..987f3685e67 100644 --- a/test/build/config-format/mjs/webpack.config.mjs +++ b/test/build/config-format/mjs/webpack.config.mjs @@ -1,11 +1,11 @@ -import { fileURLToPath } from 'url'; -import path from 'path'; +import { fileURLToPath } from "url"; +import path from "path"; export default { - mode: 'production', - entry: './main.js', + mode: "production", + entry: "./main.js", output: { - path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'dist'), - filename: 'foo.bundle.js', + path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "dist"), + filename: "foo.bundle.js", }, }; diff --git a/test/build/config-format/typescript-esnext/main.ts b/test/build/config-format/typescript-esnext/main.ts index 6b4ec5de3a4..dc6a7ea6788 100644 --- a/test/build/config-format/typescript-esnext/main.ts +++ b/test/build/config-format/typescript-esnext/main.ts @@ -1 +1 @@ -console.log('Rimuru Tempest'); +console.log("Rimuru Tempest"); diff --git a/test/build/config-format/typescript-esnext/typescript.test.js b/test/build/config-format/typescript-esnext/typescript.test.js index 683640ffd58..ac916906038 100644 --- a/test/build/config-format/typescript-esnext/typescript.test.js +++ b/test/build/config-format/typescript-esnext/typescript.test.js @@ -1,11 +1,11 @@ // eslint-disable-next-line node/no-unpublished-require -const { run, isWebpack5 } = require('../../../utils/test-utils'); -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { run, isWebpack5 } = require("../../../utils/test-utils"); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -describe('webpack cli', () => { - it('should support typescript esnext file', async () => { - const isMacOS = process.platform === 'darwin'; +describe("webpack cli", () => { + it("should support typescript esnext file", async () => { + const isMacOS = process.platform === "darwin"; const majorNodeVersion = process.version.slice(1, 3); if (majorNodeVersion < 14) { expect(true).toBe(true); @@ -19,12 +19,12 @@ describe('webpack cli', () => { return; } - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.ts'], { - nodeOptions: ['--loader=ts-node/esm'], + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"], { + nodeOptions: ["--loader=ts-node/esm"], }); expect(stderr).not.toBeFalsy(); expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); - expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy(); }); }); diff --git a/test/build/config-format/typescript-esnext/webpack.config.ts b/test/build/config-format/typescript-esnext/webpack.config.ts index f382c1724f1..4790b3d8029 100644 --- a/test/build/config-format/typescript-esnext/webpack.config.ts +++ b/test/build/config-format/typescript-esnext/webpack.config.ts @@ -1,12 +1,12 @@ /* eslint-disable node/no-unsupported-features/es-syntax */ -import * as path from 'path'; +import * as path from "path"; const config = { - mode: 'production', - entry: './main.ts', + mode: "production", + entry: "./main.ts", output: { - path: path.resolve('dist'), - filename: 'foo.bundle.js', + path: path.resolve("dist"), + filename: "foo.bundle.js", }, }; diff --git a/test/build/config-format/typescript/main.ts b/test/build/config-format/typescript/main.ts index 5dbd072a4f6..41d13d1a9a1 100644 --- a/test/build/config-format/typescript/main.ts +++ b/test/build/config-format/typescript/main.ts @@ -1 +1 @@ -console.log('Main typescript file'); +console.log("Main typescript file"); diff --git a/test/build/config-format/typescript/typescript.test.js b/test/build/config-format/typescript/typescript.test.js index 50b8f555179..08f1a7e8b8d 100644 --- a/test/build/config-format/typescript/typescript.test.js +++ b/test/build/config-format/typescript/typescript.test.js @@ -1,14 +1,14 @@ -const { run } = require('../../../utils/test-utils'); -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { run } = require("../../../utils/test-utils"); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -describe('webpack cli', () => { - it('should support typescript file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.ts']); +describe("webpack cli", () => { + it("should support typescript file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"]); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); - expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy(); }); }); diff --git a/test/build/config-format/typescript/webpack.config.ts b/test/build/config-format/typescript/webpack.config.ts index bbc70963b3b..c46268523b5 100644 --- a/test/build/config-format/typescript/webpack.config.ts +++ b/test/build/config-format/typescript/webpack.config.ts @@ -1,13 +1,13 @@ /* eslint-disable node/no-unsupported-features/es-syntax */ /** eslint-disable **/ -import * as path from 'path'; +import * as path from "path"; const config = { - mode: 'production', - entry: './main.ts', + mode: "production", + entry: "./main.ts", output: { - path: path.resolve(__dirname, 'dist'), - filename: 'foo.bundle.js', + path: path.resolve(__dirname, "dist"), + filename: "foo.bundle.js", }, }; diff --git a/test/build/config-lookup/custom-name/a.js b/test/build/config-lookup/custom-name/a.js index 2651774ae60..e7134e7006d 100644 --- a/test/build/config-lookup/custom-name/a.js +++ b/test/build/config-lookup/custom-name/a.js @@ -1 +1 @@ -module.exports = 'foo'; +module.exports = "foo"; diff --git a/test/build/config-lookup/custom-name/config.webpack.js b/test/build/config-lookup/custom-name/config.webpack.js index 9b526a493e2..950e44a8b2a 100644 --- a/test/build/config-lookup/custom-name/config.webpack.js +++ b/test/build/config-lookup/custom-name/config.webpack.js @@ -1,9 +1,9 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: resolve('./a.js'), + entry: resolve("./a.js"), output: { - path: resolve(__dirname, 'binary'), - filename: 'a.bundle.js', + path: resolve(__dirname, "binary"), + filename: "a.bundle.js", }, }; diff --git a/test/build/config-lookup/custom-name/config.webpack.mjs b/test/build/config-lookup/custom-name/config.webpack.mjs index 272b905bc1c..3b0545deb81 100644 --- a/test/build/config-lookup/custom-name/config.webpack.mjs +++ b/test/build/config-lookup/custom-name/config.webpack.mjs @@ -1,10 +1,10 @@ -import { fileURLToPath } from 'url'; -import path from 'path'; +import { fileURLToPath } from "url"; +import path from "path"; export default { - entry: './a.js', + entry: "./a.js", output: { - path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'dist'), - filename: 'a.bundle.js', + path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "dist"), + filename: "a.bundle.js", }, }; diff --git a/test/build/config-lookup/custom-name/custom-name.test.js b/test/build/config-lookup/custom-name/custom-name.test.js index e03c561c5d3..ab211df7819 100644 --- a/test/build/config-lookup/custom-name/custom-name.test.js +++ b/test/build/config-lookup/custom-name/custom-name.test.js @@ -1,21 +1,28 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('custom config file', () => { - it('should work with cjs format', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', resolve(__dirname, 'config.webpack.js')]); +describe("custom config file", () => { + it("should work with cjs format", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + resolve(__dirname, "config.webpack.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should work with esm format', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', resolve(__dirname, 'config.webpack.mjs')], { - env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, - }); + it("should work with esm format", async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config", resolve(__dirname, "config.webpack.mjs")], + { + env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, + }, + ); if (/Error: Not supported/.test(stderr)) { expect(exitCode).toBe(2); diff --git a/test/build/config-lookup/dotfolder-array/a.js b/test/build/config-lookup/dotfolder-array/a.js index 8183079e838..96a83902deb 100644 --- a/test/build/config-lookup/dotfolder-array/a.js +++ b/test/build/config-lookup/dotfolder-array/a.js @@ -1 +1 @@ -module.exports = 'hay'; +module.exports = "hay"; diff --git a/test/build/config-lookup/dotfolder-array/dotfolder-array.test.js b/test/build/config-lookup/dotfolder-array/dotfolder-array.test.js index 81bc489fbfa..36d4cbff5d3 100644 --- a/test/build/config-lookup/dotfolder-array/dotfolder-array.test.js +++ b/test/build/config-lookup/dotfolder-array/dotfolder-array.test.js @@ -1,16 +1,16 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { existsSync } = 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', async () => { +describe("dotfolder array config lookup", () => { + it("should find a webpack array configuration in a dotfolder", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/dist-commonjs.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/dist-amd.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dist-commonjs.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dist-amd.js"))).toBeTruthy(); }); }); diff --git a/test/build/config-lookup/dotfolder-single/dotfolder-single.test.js b/test/build/config-lookup/dotfolder-single/dotfolder-single.test.js index ebcf68f4ff2..a71ab9b51f9 100644 --- a/test/build/config-lookup/dotfolder-single/dotfolder-single.test.js +++ b/test/build/config-lookup/dotfolder-single/dotfolder-single.test.js @@ -1,18 +1,18 @@ -'use strict'; +"use strict"; -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('dotfolder single config lookup', () => { - it('should find a webpack configuration in a dotfolder', async () => { +describe("dotfolder single config lookup", () => { + it("should find a webpack configuration in a dotfolder", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).not.toContain('Module not found'); + expect(stdout).not.toContain("Module not found"); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/main.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/main.js"))).toBeTruthy(); }); }); diff --git a/test/build/config-lookup/dotfolder-single/index_two.js b/test/build/config-lookup/dotfolder-single/index_two.js index 8183079e838..96a83902deb 100644 --- a/test/build/config-lookup/dotfolder-single/index_two.js +++ b/test/build/config-lookup/dotfolder-single/index_two.js @@ -1 +1 @@ -module.exports = 'hay'; +module.exports = "hay"; diff --git a/test/build/config-lookup/relative/a.js b/test/build/config-lookup/relative/a.js index 735d820f253..0e9a8dc5145 100644 --- a/test/build/config-lookup/relative/a.js +++ b/test/build/config-lookup/relative/a.js @@ -1 +1 @@ -module.exports = 'a.js'; +module.exports = "a.js"; diff --git a/test/build/config-lookup/relative/basic-config.test.js b/test/build/config-lookup/relative/basic-config.test.js index d75b77c935b..cb07beb1082 100644 --- a/test/build/config-lookup/relative/basic-config.test.js +++ b/test/build/config-lookup/relative/basic-config.test.js @@ -1,18 +1,28 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('relative path to config', () => { - it('should work', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.js', '--output-path', './binary/a']); +describe("relative path to config", () => { + it("should work", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "webpack.config.js", + "--output-path", + "./binary/a", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should work #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js', '--output-path', './binary/b']); + it("should work #2", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.config.js", + "--output-path", + "./binary/b", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config-lookup/relative/webpack.config.js b/test/build/config-lookup/relative/webpack.config.js index b58f8a91f0d..70a68756b2f 100644 --- a/test/build/config-lookup/relative/webpack.config.js +++ b/test/build/config-lookup/relative/webpack.config.js @@ -1,9 +1,9 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: './a.js', + entry: "./a.js", output: { - path: resolve(__dirname, 'binary'), - filename: 'a.bundle.js', + path: resolve(__dirname, "binary"), + filename: "a.bundle.js", }, }; diff --git a/test/build/config-name/config-name.test.js b/test/build/config-name/config-name.test.js index ed9f5da36b9..4dee9145219 100644 --- a/test/build/config-name/config-name.test.js +++ b/test/build/config-name/config-name.test.js @@ -1,63 +1,82 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--config-name flag', () => { - it('should select only the config whose name is passed with --config-name', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'first']); +describe("--config-name flag", () => { + it("should select only the config whose name is passed with --config-name", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--config-name", "first"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).not.toContain('third'); + expect(stdout).toContain("first"); + expect(stdout).not.toContain("second"); + expect(stdout).not.toContain("third"); }); - it('should work with multiple values for --config-name', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'first', '--config-name', 'third']); + it("should work with multiple values for --config-name", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config-name", + "first", + "--config-name", + "third", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).toContain('third'); + 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', async () => { + it("should work with multiple values for --config-name and multiple configurations", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['-c', './function-config.js', '-c', './single-other-config.js', '--config-name', 'first', '--config-name', 'four'], + [ + "-c", + "./function-config.js", + "-c", + "./single-other-config.js", + "--config-name", + "first", + "--config-name", + "four", + ], false, ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).not.toContain('third'); - expect(stdout).toContain('four'); + expect(stdout).toContain("first"); + expect(stdout).not.toContain("second"); + expect(stdout).not.toContain("third"); + expect(stdout).toContain("four"); }); - it('should log error if invalid config name is provided', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'test']); + it("should log error if invalid config name is provided", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--config-name", "test"]); expect(exitCode).toBe(2); expect(stderr).toContain('Configuration with the name "test" was not found.'); expect(stdout).toBeFalsy(); }); - it('should log error if multiple configurations are not found', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'test', '-c', 'single-config.js']); + it("should log error if multiple configurations are not found", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config-name", + "test", + "-c", + "single-config.js", + ]); expect(exitCode).toBe(2); expect(stderr).toContain('Configuration with the name "test" was not found.'); expect(stdout).toBeFalsy(); }); - it('should log error if multiple configurations are not found #1', async () => { + it("should log error if multiple configurations are not found #1", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['--config-name', 'test', '--config-name', 'bar', '-c', 'single-config.js'], + ["--config-name", "test", "--config-name", "bar", "-c", "single-config.js"], false, ); @@ -67,10 +86,10 @@ describe('--config-name flag', () => { expect(stdout).toBeFalsy(); }); - it('should log error if multiple configurations are not found #2', async () => { + it("should log error if multiple configurations are not found #2", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['--config-name', 'first', '--config-name', 'bar', '-c', 'single-config.js'], + ["--config-name", "first", "--config-name", "bar", "-c", "single-config.js"], false, ); @@ -79,32 +98,42 @@ describe('--config-name flag', () => { expect(stdout).toBeFalsy(); }); - it('should work with config as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', 'function-config.js', '--config-name', 'first']); + it("should work with config as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "function-config.js", + "--config-name", + "first", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).not.toContain('third'); + expect(stdout).toContain("first"); + expect(stdout).not.toContain("second"); + expect(stdout).not.toContain("third"); }); - it('should work with multiple values for --config-name when the config is a function', async () => { + it("should work with multiple values for --config-name when the config is a function", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['--config', 'function-config.js', '--config-name', 'first', '--config-name', 'third'], + ["--config", "function-config.js", "--config-name", "first", "--config-name", "third"], false, ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).not.toContain('second'); - expect(stdout).toContain('third'); + expect(stdout).toContain("first"); + expect(stdout).not.toContain("second"); + expect(stdout).toContain("third"); }); - it('should log error if invalid config name is provided ', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', 'function-config.js', '--config-name', 'test']); + it("should log error if invalid config name is provided ", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "function-config.js", + "--config-name", + "test", + ]); expect(exitCode).toBe(2); expect(stderr).toContain('Configuration with the name "test" was not found.'); diff --git a/test/build/config-name/function-config.js b/test/build/config-name/function-config.js index aea6af2f9fb..1f3c3343254 100644 --- a/test/build/config-name/function-config.js +++ b/test/build/config-name/function-config.js @@ -1,26 +1,26 @@ module.exports = () => [ { output: { - filename: './dist-first.js', + filename: "./dist-first.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', + name: "first", + entry: "./src/first.js", + mode: "development", }, { output: { - filename: './dist-second.js', + filename: "./dist-second.js", }, - name: 'second', - entry: './src/second.js', - mode: 'development', + name: "second", + entry: "./src/second.js", + mode: "development", }, { output: { - filename: './dist-third.js', + filename: "./dist-third.js", }, - name: 'third', - entry: './src/third.js', - mode: 'none', + name: "third", + entry: "./src/third.js", + mode: "none", }, ]; diff --git a/test/build/config-name/single-config.js b/test/build/config-name/single-config.js index e5fff043bc6..aa3c87af2b5 100644 --- a/test/build/config-name/single-config.js +++ b/test/build/config-name/single-config.js @@ -1,8 +1,8 @@ module.exports = { output: { - filename: './dist-single.js', + filename: "./dist-single.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', + name: "first", + entry: "./src/first.js", + mode: "development", }; diff --git a/test/build/config-name/single-other-config.js b/test/build/config-name/single-other-config.js index fd4c4a325a8..46055e1a635 100644 --- a/test/build/config-name/single-other-config.js +++ b/test/build/config-name/single-other-config.js @@ -1,8 +1,8 @@ module.exports = { output: { - filename: './dist-single.js', + filename: "./dist-single.js", }, - name: 'four', - entry: './src/first.js', - mode: 'development', + name: "four", + entry: "./src/first.js", + mode: "development", }; diff --git a/test/build/config-name/src/first.js b/test/build/config-name/src/first.js index 3dfd0a1def0..c0db0a7cb59 100644 --- a/test/build/config-name/src/first.js +++ b/test/build/config-name/src/first.js @@ -1 +1 @@ -console.log('first config'); +console.log("first config"); diff --git a/test/build/config-name/src/second.js b/test/build/config-name/src/second.js index 15c0f734c34..98f5a5f5420 100644 --- a/test/build/config-name/src/second.js +++ b/test/build/config-name/src/second.js @@ -1 +1 @@ -console.log('second config'); +console.log("second config"); diff --git a/test/build/config-name/src/third.js b/test/build/config-name/src/third.js index 1047ae56bdc..372f49950f7 100644 --- a/test/build/config-name/src/third.js +++ b/test/build/config-name/src/third.js @@ -1 +1 @@ -console.log('third config'); +console.log("third config"); diff --git a/test/build/config-name/webpack.config.js b/test/build/config-name/webpack.config.js index e3ea1bc7020..97ae11c7127 100644 --- a/test/build/config-name/webpack.config.js +++ b/test/build/config-name/webpack.config.js @@ -1,27 +1,27 @@ module.exports = [ { output: { - filename: './dist-first.js', + filename: "./dist-first.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', + name: "first", + entry: "./src/first.js", + mode: "development", }, { output: { - filename: './dist-second.js', + filename: "./dist-second.js", }, - name: 'second', - entry: './src/second.js', - mode: 'development', + name: "second", + entry: "./src/second.js", + mode: "development", }, { output: { - filename: './dist-third.js', + filename: "./dist-third.js", }, - name: 'third', - entry: './src/third.js', - mode: 'none', - stats: 'verbose', + name: "third", + entry: "./src/third.js", + mode: "none", + stats: "verbose", }, ]; diff --git a/test/build/config/absent/a.js b/test/build/config/absent/a.js index 8ac1838ebe9..fe6420ad3ce 100644 --- a/test/build/config/absent/a.js +++ b/test/build/config/absent/a.js @@ -1 +1 @@ -console.log('Zenitsu'); +console.log("Zenitsu"); diff --git a/test/build/config/absent/config-absent.test.js b/test/build/config/absent/config-absent.test.js index 61fcf448dc7..9442d6b6199 100644 --- a/test/build/config/absent/config-absent.test.js +++ b/test/build/config/absent/config-absent.test.js @@ -1,16 +1,21 @@ -'use strict'; +"use strict"; -const path = require('path'); -const { run } = require('../../../utils/test-utils'); +const path = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('Config:', () => { - it('supplied config file is absent', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', path.resolve(__dirname, 'webpack.config.js')]); +describe("Config:", () => { + it("supplied config file is absent", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + path.resolve(__dirname, "webpack.config.js"), + ]); // should throw with correct exit code expect(exitCode).toBe(2); // Should contain the correct error message - expect(stderr).toContain(`Failed to load '${path.resolve(__dirname, 'webpack.config.js')}' config`); + expect(stderr).toContain( + `Failed to load '${path.resolve(__dirname, "webpack.config.js")}' config`, + ); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/config/absent/webpack.config-absent.js b/test/build/config/absent/webpack.config-absent.js index b58f8a91f0d..70a68756b2f 100644 --- a/test/build/config/absent/webpack.config-absent.js +++ b/test/build/config/absent/webpack.config-absent.js @@ -1,9 +1,9 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: './a.js', + entry: "./a.js", output: { - path: resolve(__dirname, 'binary'), - filename: 'a.bundle.js', + path: resolve(__dirname, "binary"), + filename: "a.bundle.js", }, }; diff --git a/test/build/config/basic/a.js b/test/build/config/basic/a.js index 735d820f253..0e9a8dc5145 100644 --- a/test/build/config/basic/a.js +++ b/test/build/config/basic/a.js @@ -1 +1 @@ -module.exports = 'a.js'; +module.exports = "a.js"; diff --git a/test/build/config/basic/basic-config.test.js b/test/build/config/basic/basic-config.test.js index 3c7efd29718..3fa970ffdc4 100644 --- a/test/build/config/basic/basic-config.test.js +++ b/test/build/config/basic/basic-config.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +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', async () => { +describe("basic config file", () => { + it("is able to understand and parse a very basic configuration file", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - resolve(__dirname, 'webpack.config.js'), - '--output-path', - './binary', + "-c", + resolve(__dirname, "webpack.config.js"), + "--output-path", + "./binary", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/basic/webpack.config.js b/test/build/config/basic/webpack.config.js index b58f8a91f0d..70a68756b2f 100644 --- a/test/build/config/basic/webpack.config.js +++ b/test/build/config/basic/webpack.config.js @@ -1,9 +1,9 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: './a.js', + entry: "./a.js", output: { - path: resolve(__dirname, 'binary'), - filename: 'a.bundle.js', + path: resolve(__dirname, "binary"), + filename: "a.bundle.js", }, }; diff --git a/test/build/config/defaults/basic-config/default-js-config.test.js b/test/build/config/defaults/basic-config/default-js-config.test.js index 2fa41973d10..4c8545729c8 100644 --- a/test/build/config/defaults/basic-config/default-js-config.test.js +++ b/test/build/config/defaults/basic-config/default-js-config.test.js @@ -1,27 +1,27 @@ -const fs = require('fs'); -const path = require('path'); -const { run, isWebpack5 } = require('../../../../utils/test-utils'); +const fs = require("fs"); +const path = require("path"); +const { run, isWebpack5 } = require("../../../../utils/test-utils"); -describe('Zero Config', () => { - it('runs when config is present but not supplied via flag', async () => { +describe("Zero Config", () => { + it("runs when config is present but not supplied via flag", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); // default entry should be used - expect(stdout).toContain('./src/index.js'); + expect(stdout).toContain("./src/index.js"); // should pick up the output path from config - expect(stdout).toContain('test-output'); + expect(stdout).toContain("test-output"); if (!isWebpack5) { - expect(stdout).toContain('Hash'); - expect(stdout).toContain('Version'); - expect(stdout).toContain('Built at'); - expect(stdout).toContain('Time'); + expect(stdout).toContain("Hash"); + expect(stdout).toContain("Version"); + expect(stdout).toContain("Built at"); + expect(stdout).toContain("Time"); } // check that the output file exists - expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy(); + expect(fs.existsSync(path.join(__dirname, "/dist/test-output.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/defaults/basic-config/webpack.config.js b/test/build/config/defaults/basic-config/webpack.config.js index 6593a7a44a3..e153ad2935b 100644 --- a/test/build/config/defaults/basic-config/webpack.config.js +++ b/test/build/config/defaults/basic-config/webpack.config.js @@ -1,6 +1,6 @@ module.exports = { - mode: 'development', + mode: "development", output: { - filename: 'test-output.js', + filename: "test-output.js", }, }; diff --git a/test/build/config/defaults/cjs-config/default-cjs-config.test.js b/test/build/config/defaults/cjs-config/default-cjs-config.test.js index ef25d0ad564..096652549bf 100644 --- a/test/build/config/defaults/cjs-config/default-cjs-config.test.js +++ b/test/build/config/defaults/cjs-config/default-cjs-config.test.js @@ -1,26 +1,26 @@ -const fs = require('fs'); -const path = require('path'); -const { run, isWebpack5 } = require('../../../../utils/test-utils'); +const fs = require("fs"); +const path = require("path"); +const { run, isWebpack5 } = require("../../../../utils/test-utils"); -describe('Default Config:', () => { - it('Should be able to pick cjs config by default', async () => { +describe("Default Config:", () => { + it("Should be able to pick cjs config by default", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); // default entry should be used - expect(stdout).toContain('./src/index.js'); + expect(stdout).toContain("./src/index.js"); // should pick up the output path from config - expect(stdout).toContain('test-output'); + expect(stdout).toContain("test-output"); if (!isWebpack5) { - expect(stdout).toContain('Hash'); - expect(stdout).toContain('Version'); - expect(stdout).toContain('Built at'); - expect(stdout).toContain('Time'); + expect(stdout).toContain("Hash"); + expect(stdout).toContain("Version"); + expect(stdout).toContain("Built at"); + expect(stdout).toContain("Time"); } // check that the output file exists - expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy(); + expect(fs.existsSync(path.join(__dirname, "/dist/test-output.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/defaults/cjs-config/webpack.config.cjs b/test/build/config/defaults/cjs-config/webpack.config.cjs index 6593a7a44a3..e153ad2935b 100644 --- a/test/build/config/defaults/cjs-config/webpack.config.cjs +++ b/test/build/config/defaults/cjs-config/webpack.config.cjs @@ -1,6 +1,6 @@ module.exports = { - mode: 'development', + mode: "development", output: { - filename: 'test-output.js', + filename: "test-output.js", }, }; diff --git a/test/build/config/defaults/dot-webpack-directory-webpackfile/multiple-location-config.test.js b/test/build/config/defaults/dot-webpack-directory-webpackfile/multiple-location-config.test.js index 5b68f73dc03..d5bc1d8ad9c 100644 --- a/test/build/config/defaults/dot-webpack-directory-webpackfile/multiple-location-config.test.js +++ b/test/build/config/defaults/dot-webpack-directory-webpackfile/multiple-location-config.test.js @@ -1,14 +1,14 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('multiple dev config files with webpack.config.js', () => { - it('Uses webpack.config.development.js', async () => { +describe("multiple dev config files with webpack.config.js", () => { + it("Uses webpack.config.development.js", async () => { const { stdout, stderr, exitCode } = await run(__dirname, []); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); expect(stdout).not.toBe(undefined); - expect(existsSync(resolve(__dirname, './binary/dev.folder.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/dev.folder.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/defaults/dot-webpack-directory/dev-none-config.test.js b/test/build/config/defaults/dot-webpack-directory/dev-none-config.test.js index 5c59efbbc78..c4948bebd66 100644 --- a/test/build/config/defaults/dot-webpack-directory/dev-none-config.test.js +++ b/test/build/config/defaults/dot-webpack-directory/dev-none-config.test.js @@ -1,14 +1,14 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('multiple config files', () => { - it('Uses dev config when both dev and none are present', async () => { +describe("multiple config files", () => { + it("Uses dev config when both dev and none are present", async () => { const { stdout, stderr, exitCode } = await run(__dirname, []); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); expect(stdout).not.toBe(undefined); - expect(existsSync(resolve(__dirname, './binary/dev.bundle.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/dev.bundle.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/defaults/mjs-config/default-mjs-config.test.js b/test/build/config/defaults/mjs-config/default-mjs-config.test.js index 3e96d4388a3..3577a417d1d 100644 --- a/test/build/config/defaults/mjs-config/default-mjs-config.test.js +++ b/test/build/config/defaults/mjs-config/default-mjs-config.test.js @@ -1,10 +1,12 @@ -const fs = require('fs'); -const path = require('path'); -const { run, isWebpack5 } = require('../../../../utils/test-utils'); +const fs = require("fs"); +const path = require("path"); +const { run, isWebpack5 } = require("../../../../utils/test-utils"); -describe('Default Config:', () => { - it('Should be able to pick mjs config by default', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true } }); +describe("Default Config:", () => { + it("Should be able to pick mjs config by default", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [], { + env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, + }); if (/Error: Not supported/.test(stderr)) { expect(exitCode).toEqual(2); @@ -13,19 +15,19 @@ describe('Default Config:', () => { expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); // default entry should be used - expect(stdout).toContain('./src/index.js'); + expect(stdout).toContain("./src/index.js"); // should pick up the output path from config - expect(stdout).toContain('test-output'); + expect(stdout).toContain("test-output"); if (!isWebpack5) { - expect(stdout).toContain('Hash'); - expect(stdout).toContain('Version'); - expect(stdout).toContain('Built at'); - expect(stdout).toContain('Time'); + expect(stdout).toContain("Hash"); + expect(stdout).toContain("Version"); + expect(stdout).toContain("Built at"); + expect(stdout).toContain("Time"); } // check that the output file exists - expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy(); + expect(fs.existsSync(path.join(__dirname, "/dist/test-output.js"))).toBeTruthy(); } }); }); diff --git a/test/build/config/defaults/mjs-config/webpack.config.mjs b/test/build/config/defaults/mjs-config/webpack.config.mjs index 3c5c06d4449..07661617d18 100644 --- a/test/build/config/defaults/mjs-config/webpack.config.mjs +++ b/test/build/config/defaults/mjs-config/webpack.config.mjs @@ -1,6 +1,6 @@ export default { - mode: 'development', + mode: "development", output: { - filename: 'test-output.js', + filename: "test-output.js", }, }; diff --git a/test/build/config/defaults/with-mode/multiple-config.test.js b/test/build/config/defaults/with-mode/multiple-config.test.js index f95169c84ca..65fca69f2ee 100644 --- a/test/build/config/defaults/with-mode/multiple-config.test.js +++ b/test/build/config/defaults/with-mode/multiple-config.test.js @@ -1,14 +1,14 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('multiple config files', () => { - it('Uses dev config when development mode is supplied', async () => { - const { stdout, stderr, exitCode } = await run(__dirname, ['--mode', 'development']); +describe("multiple config files", () => { + it("Uses dev config when development mode is supplied", async () => { + const { stdout, stderr, exitCode } = await run(__dirname, ["--mode", "development"]); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); expect(stdout).not.toBe(undefined); - expect(existsSync(resolve(__dirname, './binary/dev.bundle.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/dev.bundle.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/defaults/with-mode/webpack.config.js b/test/build/config/defaults/with-mode/webpack.config.js index 0e8c35c932f..5bba6294662 100644 --- a/test/build/config/defaults/with-mode/webpack.config.js +++ b/test/build/config/defaults/with-mode/webpack.config.js @@ -1,9 +1,9 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: './index.js', + entry: "./index.js", output: { - path: resolve(__dirname, './binary'), - filename: 'dev.bundle.js', + path: resolve(__dirname, "./binary"), + filename: "dev.bundle.js", }, }; diff --git a/test/build/config/empty-array/empty-array.test.js b/test/build/config/empty-array/empty-array.test.js index 6433ec506c0..ec3ef7203b4 100644 --- a/test/build/config/empty-array/empty-array.test.js +++ b/test/build/config/empty-array/empty-array.test.js @@ -1,10 +1,13 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('config flag with empty config file', () => { - it('should throw error with no configuration or index file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("config flag with empty config file", () => { + it("should throw error with no configuration or index file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/empty-function/empty-function.test.js b/test/build/config/empty-function/empty-function.test.js index 6433ec506c0..ec3ef7203b4 100644 --- a/test/build/config/empty-function/empty-function.test.js +++ b/test/build/config/empty-function/empty-function.test.js @@ -1,10 +1,13 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('config flag with empty config file', () => { - it('should throw error with no configuration or index file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("config flag with empty config file", () => { + it("should throw error with no configuration or index file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/empty-promise/empty-promise.test.js b/test/build/config/empty-promise/empty-promise.test.js index 6433ec506c0..ec3ef7203b4 100644 --- a/test/build/config/empty-promise/empty-promise.test.js +++ b/test/build/config/empty-promise/empty-promise.test.js @@ -1,10 +1,13 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('config flag with empty config file', () => { - it('should throw error with no configuration or index file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("config flag with empty config file", () => { + it("should throw error with no configuration or index file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/empty/empty.test.js b/test/build/config/empty/empty.test.js index 6433ec506c0..ec3ef7203b4 100644 --- a/test/build/config/empty/empty.test.js +++ b/test/build/config/empty/empty.test.js @@ -1,10 +1,13 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('config flag with empty config file', () => { - it('should throw error with no configuration or index file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("config flag with empty config file", () => { + it("should throw error with no configuration or index file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/error-array/config-array-error.test.js b/test/build/config/error-array/config-array-error.test.js index d17d8453295..b803321dd7e 100644 --- a/test/build/config/error-array/config-array-error.test.js +++ b/test/build/config/error-array/config-array-error.test.js @@ -1,11 +1,11 @@ -'use strict'; -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { run } = require("../../../utils/test-utils"); -describe('array config error', () => { - it('should throw syntax error and exit with non-zero exit code when even 1 object has syntax error', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js']); +describe("array config error", () => { + it("should throw syntax error and exit with non-zero exit code when even 1 object has syntax error", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); expect(exitCode).toBe(2); - expect(stderr).toContain('SyntaxError: Unexpected token'); + expect(stderr).toContain("SyntaxError: Unexpected token"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/config/error-commonjs/config-error.test.js b/test/build/config/error-commonjs/config-error.test.js index 8ab2a66de0c..89f2969234d 100644 --- a/test/build/config/error-commonjs/config-error.test.js +++ b/test/build/config/error-commonjs/config-error.test.js @@ -1,22 +1,28 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('config error', () => { - it('should throw error with invalid configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("config error", () => { + it("should throw error with invalid configuration", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(2); - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); expect(stderr).toContain(`"development" | "production" | "none"`); expect(stdout).toBeFalsy(); }); - it('should throw syntax error and exit with non-zero exit code', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'syntax-error.js')]); + it("should throw syntax error and exit with non-zero exit code", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "syntax-error.js"), + ]); expect(exitCode).toBe(2); - expect(stderr).toContain('SyntaxError: Unexpected token'); + expect(stderr).toContain("SyntaxError: Unexpected token"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/config/error-commonjs/webpack.config.js b/test/build/config/error-commonjs/webpack.config.js index a967a05223c..a54311d53f7 100644 --- a/test/build/config/error-commonjs/webpack.config.js +++ b/test/build/config/error-commonjs/webpack.config.js @@ -1,5 +1,5 @@ module.exports = { - name: 'config-error', - mode: 'unknown', //error - target: 'node', + name: "config-error", + mode: "unknown", //error + target: "node", }; diff --git a/test/build/config/error-mjs/config-error.test.js b/test/build/config/error-mjs/config-error.test.js index c31d02ea66d..6a69898ca13 100644 --- a/test/build/config/error-mjs/config-error.test.js +++ b/test/build/config/error-mjs/config-error.test.js @@ -1,32 +1,40 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); - -describe('config error', () => { - it('should throw error with invalid configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.mjs')], { - env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, - }); +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); + +describe("config error", () => { + it("should throw error with invalid configuration", async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", resolve(__dirname, "webpack.config.mjs")], + { + env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, + }, + ); expect(exitCode).toBe(2); if (!/Error: Not supported/.test(stderr)) { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); expect(stderr).toContain(`"development" | "production" | "none"`); } expect(stdout).toBeFalsy(); }); - it('should throw syntax error and exit with non-zero exit code', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'syntax-error.mjs')], { - env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, - }); + it("should throw syntax error and exit with non-zero exit code", async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", resolve(__dirname, "syntax-error.mjs")], + { + env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true }, + }, + ); expect(exitCode).toBe(2); if (!/Error: Not supported/.test(stderr)) { - expect(stderr).toContain('SyntaxError: Unexpected token'); + expect(stderr).toContain("SyntaxError: Unexpected token"); } expect(stdout).toBeFalsy(); diff --git a/test/build/config/error-mjs/webpack.config.mjs b/test/build/config/error-mjs/webpack.config.mjs index 2f7dc4a7e49..6f46f196806 100644 --- a/test/build/config/error-mjs/webpack.config.mjs +++ b/test/build/config/error-mjs/webpack.config.mjs @@ -1,5 +1,5 @@ export default { - name: 'config-error', - mode: 'unknown', //error - target: 'node', + name: "config-error", + mode: "unknown", //error + target: "node", }; diff --git a/test/build/config/function/functional-config.test.js b/test/build/config/function/functional-config.test.js index 1d6dca4c3c7..034ece3a855 100644 --- a/test/build/config/function/functional-config.test.js +++ b/test/build/config/function/functional-config.test.js @@ -1,27 +1,33 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { existsSync } = require('fs'); -const { run } = require('../../../utils/test-utils'); +const { resolve } = require("path"); +const { existsSync } = require("fs"); +const { run } = require("../../../utils/test-utils"); -describe('functional config', () => { - it('should work as expected in case of single config', async () => { - const { stderr, stdout, exitCode } = await run(__dirname, ['--config', resolve(__dirname, 'single-webpack.config.js')]); +describe("functional config", () => { + it("should work as expected in case of single config", async () => { + const { stderr, stdout, exitCode } = await run(__dirname, [ + "--config", + resolve(__dirname, "single-webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('./src/index.js'); - expect(existsSync(resolve(__dirname, './dist/dist-single.js'))).toBeTruthy(); + expect(stdout).toContain("./src/index.js"); + expect(existsSync(resolve(__dirname, "./dist/dist-single.js"))).toBeTruthy(); }); - it('should work as expected in case of multiple config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', resolve(__dirname, 'multi-webpack.config.js')]); + it("should work as expected in case of multiple config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + resolve(__dirname, "multi-webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('first'); - expect(stdout).toContain('second'); - expect(existsSync(resolve(__dirname, './dist/dist-first.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/dist-second.js'))).toBeTruthy(); + expect(stdout).toContain("first"); + expect(stdout).toContain("second"); + expect(existsSync(resolve(__dirname, "./dist/dist-first.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dist-second.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/function/multi-webpack.config.js b/test/build/config/function/multi-webpack.config.js index 17546d938aa..e2d8ab2eb43 100644 --- a/test/build/config/function/multi-webpack.config.js +++ b/test/build/config/function/multi-webpack.config.js @@ -1,20 +1,20 @@ module.exports = () => [ { output: { - filename: './dist-first.js', + filename: "./dist-first.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', - stats: 'minimal', + name: "first", + entry: "./src/first.js", + mode: "development", + stats: "minimal", }, { output: { - filename: './dist-second.js', + filename: "./dist-second.js", }, - name: 'second', - entry: './src/second.js', - mode: 'development', - stats: 'minimal', + name: "second", + entry: "./src/second.js", + mode: "development", + stats: "minimal", }, ]; diff --git a/test/build/config/function/single-webpack.config.js b/test/build/config/function/single-webpack.config.js index dbf14dc44c9..c4f546f3f5d 100644 --- a/test/build/config/function/single-webpack.config.js +++ b/test/build/config/function/single-webpack.config.js @@ -1,9 +1,9 @@ module.exports = () => { return { output: { - filename: './dist-single.js', + filename: "./dist-single.js", }, - name: 'single', - mode: 'development', + name: "single", + mode: "development", }; }; diff --git a/test/build/config/function/src/first.js b/test/build/config/function/src/first.js index 5a33e8ffd02..b6c84715cfb 100644 --- a/test/build/config/function/src/first.js +++ b/test/build/config/function/src/first.js @@ -1 +1 @@ -console.log('first entry'); +console.log("first entry"); diff --git a/test/build/config/function/src/second.js b/test/build/config/function/src/second.js index 3ce234df055..284f324c0fc 100644 --- a/test/build/config/function/src/second.js +++ b/test/build/config/function/src/second.js @@ -1 +1 @@ -console.log('second entry'); +console.log("second entry"); diff --git a/test/build/config/invalid-export/invalid-export.test.js b/test/build/config/invalid-export/invalid-export.test.js index c38a21e3f51..7a70a7d5fa8 100644 --- a/test/build/config/invalid-export/invalid-export.test.js +++ b/test/build/config/invalid-export/invalid-export.test.js @@ -1,13 +1,18 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('invalid export', () => { - it('should throw error with no configuration or index file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("invalid export", () => { + it("should throw error with no configuration or index file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(2); - expect(stderr).toContain(`Invalid configuration in '${resolve(__dirname, 'webpack.config.js')}'`); + expect(stderr).toContain( + `Invalid configuration in '${resolve(__dirname, "webpack.config.js")}'`, + ); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/config/invalid-export/webpack.config.js b/test/build/config/invalid-export/webpack.config.js index 2651774ae60..e7134e7006d 100644 --- a/test/build/config/invalid-export/webpack.config.js +++ b/test/build/config/invalid-export/webpack.config.js @@ -1 +1 @@ -module.exports = 'foo'; +module.exports = "foo"; diff --git a/test/build/config/invalid-path/a.js b/test/build/config/invalid-path/a.js index 735d820f253..0e9a8dc5145 100644 --- a/test/build/config/invalid-path/a.js +++ b/test/build/config/invalid-path/a.js @@ -1 +1 @@ -module.exports = 'a.js'; +module.exports = "a.js"; diff --git a/test/build/config/invalid-path/invalid-path.test.js b/test/build/config/invalid-path/invalid-path.test.js index 4350753aaef..6b73ece3b70 100644 --- a/test/build/config/invalid-path/invalid-path.test.js +++ b/test/build/config/invalid-path/invalid-path.test.js @@ -1,13 +1,18 @@ -'use strict'; -const path = require('path'); -const { run } = require('../../../utils/test-utils'); +"use strict"; +const path = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('basic config file', () => { - it('is able to understand and parse a very basic configuration file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', path.resolve(__dirname, 'invalid-webpack.config.js')]); +describe("basic config file", () => { + it("is able to understand and parse a very basic configuration file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + path.resolve(__dirname, "invalid-webpack.config.js"), + ]); expect(exitCode).toBe(2); - expect(stderr).toContain(`Failed to load '${path.resolve(__dirname, 'invalid-webpack.config.js')}' config`); + expect(stderr).toContain( + `Failed to load '${path.resolve(__dirname, "invalid-webpack.config.js")}' config`, + ); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/config/invalid-path/webpack.config.js b/test/build/config/invalid-path/webpack.config.js index b58f8a91f0d..70a68756b2f 100644 --- a/test/build/config/invalid-path/webpack.config.js +++ b/test/build/config/invalid-path/webpack.config.js @@ -1,9 +1,9 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: './a.js', + entry: "./a.js", output: { - path: resolve(__dirname, 'binary'), - filename: 'a.bundle.js', + path: resolve(__dirname, "binary"), + filename: "a.bundle.js", }, }; diff --git a/test/build/config/multiple-with-one-compilation/a.js b/test/build/config/multiple-with-one-compilation/a.js index 735d820f253..0e9a8dc5145 100644 --- a/test/build/config/multiple-with-one-compilation/a.js +++ b/test/build/config/multiple-with-one-compilation/a.js @@ -1 +1 @@ -module.exports = 'a.js'; +module.exports = "a.js"; diff --git a/test/build/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js b/test/build/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js index 3c7efd29718..3fa970ffdc4 100644 --- a/test/build/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js +++ b/test/build/config/multiple-with-one-compilation/multiple-with-one-compilation.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +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', async () => { +describe("basic config file", () => { + it("is able to understand and parse a very basic configuration file", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - resolve(__dirname, 'webpack.config.js'), - '--output-path', - './binary', + "-c", + resolve(__dirname, "webpack.config.js"), + "--output-path", + "./binary", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/multiple-with-one-compilation/webpack.config.js b/test/build/config/multiple-with-one-compilation/webpack.config.js index fde09e6bba1..43c9fb9da62 100644 --- a/test/build/config/multiple-with-one-compilation/webpack.config.js +++ b/test/build/config/multiple-with-one-compilation/webpack.config.js @@ -1,11 +1,11 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = [ { - entry: './a.js', + entry: "./a.js", output: { - path: resolve(__dirname, 'binary'), - filename: 'a.bundle.js', + path: resolve(__dirname, "binary"), + filename: "a.bundle.js", }, }, ]; diff --git a/test/build/config/multiple/init.js b/test/build/config/multiple/init.js index 63e43c10599..d9d76664446 100644 --- a/test/build/config/multiple/init.js +++ b/test/build/config/multiple/init.js @@ -1 +1 @@ -console.log('Monkey D Luffy'); +console.log("Monkey D Luffy"); diff --git a/test/build/config/multiple/multiple-config.test.js b/test/build/config/multiple/multiple-config.test.js index 53ecd6edb02..fea09f2d6f7 100644 --- a/test/build/config/multiple/multiple-config.test.js +++ b/test/build/config/multiple/multiple-config.test.js @@ -1,16 +1,21 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('Multiple config flag: ', () => { - it('spawns multiple compilers for multiple configs', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', 'webpack1.config.js', '--config', 'webpack2.config.js']); +describe("Multiple config flag: ", () => { + it("spawns multiple compilers for multiple configs", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "webpack1.config.js", + "--config", + "webpack2.config.js", + ]); // Should contain the correct exit code expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); // Should spawn multiple compilers - expect(stdout).toContain('amd:'); - expect(stdout).toContain('commonjs:'); + expect(stdout).toContain("amd:"); + expect(stdout).toContain("commonjs:"); }); }); diff --git a/test/build/config/multiple/webpack1.config.js b/test/build/config/multiple/webpack1.config.js index 88edf6386be..7cc9c7ab4d8 100644 --- a/test/build/config/multiple/webpack1.config.js +++ b/test/build/config/multiple/webpack1.config.js @@ -1,10 +1,10 @@ module.exports = { output: { - filename: './dist-amd.js', - libraryTarget: 'amd', + filename: "./dist-amd.js", + libraryTarget: "amd", }, - name: 'amd', - entry: './init.js', - mode: 'development', - devtool: 'eval-cheap-module-source-map', + name: "amd", + entry: "./init.js", + mode: "development", + devtool: "eval-cheap-module-source-map", }; diff --git a/test/build/config/multiple/webpack2.config.js b/test/build/config/multiple/webpack2.config.js index 2b96dbfda64..ec3198f969e 100644 --- a/test/build/config/multiple/webpack2.config.js +++ b/test/build/config/multiple/webpack2.config.js @@ -1,10 +1,10 @@ module.exports = { output: { - filename: './dist-commonjs.js', - libraryTarget: 'commonjs', + filename: "./dist-commonjs.js", + libraryTarget: "commonjs", }, - name: 'commonjs', - entry: './init.js', - mode: 'development', - target: 'node', + name: "commonjs", + entry: "./init.js", + mode: "development", + target: "node", }; diff --git a/test/build/config/no-config-array/no-config-array.test.js b/test/build/config/no-config-array/no-config-array.test.js index 406199c785c..24593003722 100644 --- a/test/build/config/no-config-array/no-config-array.test.js +++ b/test/build/config/no-config-array/no-config-array.test.js @@ -1,11 +1,14 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('no configs in array', () => { - it('is able to understand and parse a very basic configuration file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("no configs in array", () => { + it("is able to understand and parse a very basic configuration file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/no-config-object/a.js b/test/build/config/no-config-object/a.js index 735d820f253..0e9a8dc5145 100644 --- a/test/build/config/no-config-object/a.js +++ b/test/build/config/no-config-object/a.js @@ -1 +1 @@ -module.exports = 'a.js'; +module.exports = "a.js"; diff --git a/test/build/config/no-config-object/no-config-object.test.js b/test/build/config/no-config-object/no-config-object.test.js index fc83afb8626..faba425b674 100644 --- a/test/build/config/no-config-object/no-config-object.test.js +++ b/test/build/config/no-config-object/no-config-object.test.js @@ -1,11 +1,16 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run } = require('../../../utils/test-utils'); +const { resolve } = require("path"); +const { run } = require("../../../utils/test-utils"); -describe('empty config', () => { - it('should work', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--mode', 'development']); +describe("empty config", () => { + it("should work", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + "--mode", + "development", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/type/array-function-with-argv/a.js b/test/build/config/type/array-function-with-argv/a.js index 8609d075540..7b2a3460115 100644 --- a/test/build/config/type/array-function-with-argv/a.js +++ b/test/build/config/type/array-function-with-argv/a.js @@ -1 +1 @@ -console.log('a'); +console.log("a"); diff --git a/test/build/config/type/array-function-with-argv/b.js b/test/build/config/type/array-function-with-argv/b.js index eeb313a0347..6d012e7f1f1 100644 --- a/test/build/config/type/array-function-with-argv/b.js +++ b/test/build/config/type/array-function-with-argv/b.js @@ -1 +1 @@ -console.log('b'); +console.log("b"); diff --git a/test/build/config/type/array-function-with-argv/function-with-argv.test.js b/test/build/config/type/array-function-with-argv/function-with-argv.test.js index 72b2a36bbb3..51827b912a6 100644 --- a/test/build/config/type/array-function-with-argv/function-with-argv.test.js +++ b/test/build/config/type/array-function-with-argv/function-with-argv.test.js @@ -1,16 +1,16 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = 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', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development']); +describe("array of function with args", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "development"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/a-dev.js'))); - expect(existsSync(resolve(__dirname, './dist/b-dev.js'))); + expect(existsSync(resolve(__dirname, "./dist/a-dev.js"))); + expect(existsSync(resolve(__dirname, "./dist/b-dev.js"))); }); }); diff --git a/test/build/config/type/array-function-with-argv/webpack.config.js b/test/build/config/type/array-function-with-argv/webpack.config.js index da04c44d114..6756d1b368e 100644 --- a/test/build/config/type/array-function-with-argv/webpack.config.js +++ b/test/build/config/type/array-function-with-argv/webpack.config.js @@ -2,20 +2,20 @@ module.exports = [ (env, argv) => { const { mode } = argv; return { - entry: './a.js', - name: 'first', + entry: "./a.js", + name: "first", output: { - filename: mode === 'production' ? 'a-prod.js' : 'a-dev.js', + filename: mode === "production" ? "a-prod.js" : "a-dev.js", }, }; }, (env, argv) => { const { mode } = argv; return { - entry: './b.js', - name: 'second', + entry: "./b.js", + name: "second", output: { - filename: mode === 'production' ? 'b-prod.js' : 'b-dev.js', + filename: mode === "production" ? "b-prod.js" : "b-dev.js", }, }; }, diff --git a/test/build/config/type/array-function-with-env/a.js b/test/build/config/type/array-function-with-env/a.js index 8609d075540..7b2a3460115 100644 --- a/test/build/config/type/array-function-with-env/a.js +++ b/test/build/config/type/array-function-with-env/a.js @@ -1 +1 @@ -console.log('a'); +console.log("a"); diff --git a/test/build/config/type/array-function-with-env/array-function-with-env.test.js b/test/build/config/type/array-function-with-env/array-function-with-env.test.js index 6dd1804a6a8..16274153435 100644 --- a/test/build/config/type/array-function-with-env/array-function-with-env.test.js +++ b/test/build/config/type/array-function-with-env/array-function-with-env.test.js @@ -1,16 +1,16 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = 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', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development']); +describe("array of functions with env", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "development"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/a-dev.js'))); - expect(existsSync(resolve(__dirname, './dist/b-dev.js'))); + expect(existsSync(resolve(__dirname, "./dist/a-dev.js"))); + expect(existsSync(resolve(__dirname, "./dist/b-dev.js"))); }); }); diff --git a/test/build/config/type/array-function-with-env/b.js b/test/build/config/type/array-function-with-env/b.js index eeb313a0347..6d012e7f1f1 100644 --- a/test/build/config/type/array-function-with-env/b.js +++ b/test/build/config/type/array-function-with-env/b.js @@ -1 +1 @@ -console.log('b'); +console.log("b"); diff --git a/test/build/config/type/array-function-with-env/webpack.config.js b/test/build/config/type/array-function-with-env/webpack.config.js index da04c44d114..6756d1b368e 100644 --- a/test/build/config/type/array-function-with-env/webpack.config.js +++ b/test/build/config/type/array-function-with-env/webpack.config.js @@ -2,20 +2,20 @@ module.exports = [ (env, argv) => { const { mode } = argv; return { - entry: './a.js', - name: 'first', + entry: "./a.js", + name: "first", output: { - filename: mode === 'production' ? 'a-prod.js' : 'a-dev.js', + filename: mode === "production" ? "a-prod.js" : "a-dev.js", }, }; }, (env, argv) => { const { mode } = argv; return { - entry: './b.js', - name: 'second', + entry: "./b.js", + name: "second", output: { - filename: mode === 'production' ? 'b-prod.js' : 'b-dev.js', + filename: mode === "production" ? "b-prod.js" : "b-dev.js", }, }; }, diff --git a/test/build/config/type/array-functions/a.js b/test/build/config/type/array-functions/a.js index ea51098c48f..2e67d56775e 100644 --- a/test/build/config/type/array-functions/a.js +++ b/test/build/config/type/array-functions/a.js @@ -1 +1 @@ -module.exports = 'a-function'; +module.exports = "a-function"; diff --git a/test/build/config/type/array-functions/array-functions.test.js b/test/build/config/type/array-functions/array-functions.test.js index de62cab46b8..23fa310800e 100644 --- a/test/build/config/type/array-functions/array-functions.test.js +++ b/test/build/config/type/array-functions/array-functions.test.js @@ -1,16 +1,19 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('array of functions', () => { - it('is able to understand a configuration file as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("array of functions", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/a-functor.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/b-functor.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/a-functor.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/b-functor.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/array-functions/b.js b/test/build/config/type/array-functions/b.js index 5614cdc34c5..0553594c766 100644 --- a/test/build/config/type/array-functions/b.js +++ b/test/build/config/type/array-functions/b.js @@ -1 +1 @@ -module.exports = 'b-function'; +module.exports = "b-function"; diff --git a/test/build/config/type/array-functions/webpack.config.js b/test/build/config/type/array-functions/webpack.config.js index 2d60cddbafb..81aaa17333c 100644 --- a/test/build/config/type/array-functions/webpack.config.js +++ b/test/build/config/type/array-functions/webpack.config.js @@ -1,21 +1,21 @@ module.exports = [ () => { return { - entry: './a', - name: 'first', + entry: "./a", + name: "first", output: { - path: __dirname + '/binary', - filename: 'a-functor.js', + path: __dirname + "/binary", + filename: "a-functor.js", }, }; }, () => { return { - entry: './b', - name: 'second', + entry: "./b", + name: "second", output: { - path: __dirname + '/binary', - filename: 'b-functor.js', + path: __dirname + "/binary", + filename: "b-functor.js", }, }; }, diff --git a/test/build/config/type/array-promises/a.js b/test/build/config/type/array-promises/a.js index 4f7f5db3d4c..312e630d83c 100644 --- a/test/build/config/type/array-promises/a.js +++ b/test/build/config/type/array-promises/a.js @@ -1 +1 @@ -module.exports = 'a-promise'; +module.exports = "a-promise"; diff --git a/test/build/config/type/array-promises/array-promises.test.js b/test/build/config/type/array-promises/array-promises.test.js index 828c0207f4b..40a7824e913 100644 --- a/test/build/config/type/array-promises/array-promises.test.js +++ b/test/build/config/type/array-promises/array-promises.test.js @@ -1,16 +1,16 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('array of promises', () => { - it('is able to understand a configuration file as a promise', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js']); +describe("array of promises", () => { + it("is able to understand a configuration file as a promise", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/a-promise.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/b-promise.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/a-promise.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/b-promise.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/array-promises/b.js b/test/build/config/type/array-promises/b.js index d4280020bd2..73caf59dfee 100644 --- a/test/build/config/type/array-promises/b.js +++ b/test/build/config/type/array-promises/b.js @@ -1 +1 @@ -module.exports = 'b-promise'; +module.exports = "b-promise"; diff --git a/test/build/config/type/array-promises/webpack.config.js b/test/build/config/type/array-promises/webpack.config.js index 9456d7a6bbd..483521b0405 100644 --- a/test/build/config/type/array-promises/webpack.config.js +++ b/test/build/config/type/array-promises/webpack.config.js @@ -2,11 +2,11 @@ module.exports = [ new Promise((resolve) => { setTimeout(() => { resolve({ - entry: './a', - name: 'first', + entry: "./a", + name: "first", output: { - path: __dirname + '/binary', - filename: 'a-promise.js', + path: __dirname + "/binary", + filename: "a-promise.js", }, }); }, 0); @@ -14,11 +14,11 @@ module.exports = [ new Promise((resolve) => { setTimeout(() => { resolve({ - entry: './b', - name: 'second', + entry: "./b", + name: "second", output: { - path: __dirname + '/binary', - filename: 'b-promise.js', + path: __dirname + "/binary", + filename: "b-promise.js", }, }); }, 0); diff --git a/test/build/config/type/array/a.js b/test/build/config/type/array/a.js index 14801125031..9dd44bc2f35 100644 --- a/test/build/config/type/array/a.js +++ b/test/build/config/type/array/a.js @@ -1 +1 @@ -module.exports = 'a-array'; +module.exports = "a-array"; diff --git a/test/build/config/type/array/array.test.js b/test/build/config/type/array/array.test.js index 44d5f5dcef4..60e82208882 100644 --- a/test/build/config/type/array/array.test.js +++ b/test/build/config/type/array/array.test.js @@ -1,27 +1,30 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('array config', () => { - it('is able to understand a configuration file in array format', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("array config", () => { + it("is able to understand a configuration file in array format", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/dist-commonjs.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/dist-amd.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dist-commonjs.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dist-amd.js"))).toBeTruthy(); }); - it('respect cli args with config as an array', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats', 'none']); + it("respect cli args with config as an array", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--stats", "none"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); // should not print anything because of stats: none expect(stdout).toBeFalsy(); - expect(existsSync(resolve(__dirname, './dist/dist-commonjs.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/dist-amd.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dist-commonjs.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dist-amd.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/array/webpack.config.js b/test/build/config/type/array/webpack.config.js index e8ca27db5fa..69bb0919988 100644 --- a/test/build/config/type/array/webpack.config.js +++ b/test/build/config/type/array/webpack.config.js @@ -1,24 +1,24 @@ module.exports = [ { output: { - filename: './dist-amd.js', - libraryTarget: 'amd', + filename: "./dist-amd.js", + libraryTarget: "amd", }, - name: 'amd', - entry: './a.js', - mode: 'development', - stats: 'verbose', - devtool: 'eval-cheap-module-source-map', + name: "amd", + entry: "./a.js", + mode: "development", + stats: "verbose", + devtool: "eval-cheap-module-source-map", }, { output: { - filename: './dist-commonjs.js', - libraryTarget: 'commonjs', + filename: "./dist-commonjs.js", + libraryTarget: "commonjs", }, - name: 'commonjs', - entry: './a.js', - mode: 'development', - stats: 'detailed', - target: 'node', + name: "commonjs", + entry: "./a.js", + mode: "development", + stats: "detailed", + target: "node", }, ]; diff --git a/test/build/config/type/function-array/a.js b/test/build/config/type/function-array/a.js index ea51098c48f..2e67d56775e 100644 --- a/test/build/config/type/function-array/a.js +++ b/test/build/config/type/function-array/a.js @@ -1 +1 @@ -module.exports = 'a-function'; +module.exports = "a-function"; diff --git a/test/build/config/type/function-array/b.js b/test/build/config/type/function-array/b.js index 5614cdc34c5..0553594c766 100644 --- a/test/build/config/type/function-array/b.js +++ b/test/build/config/type/function-array/b.js @@ -1 +1 @@ -module.exports = 'b-function'; +module.exports = "b-function"; diff --git a/test/build/config/type/function-array/function-array.test.js b/test/build/config/type/function-array/function-array.test.js index 12169a05639..92df4e46ed0 100644 --- a/test/build/config/type/function-array/function-array.test.js +++ b/test/build/config/type/function-array/function-array.test.js @@ -1,16 +1,19 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('function array', () => { - it('is able to understand a configuration file as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("function array", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/a-functor.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/b-functor.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/a-functor.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/b-functor.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/function-array/webpack.config.js b/test/build/config/type/function-array/webpack.config.js index 8e46701080a..eae05c3c191 100644 --- a/test/build/config/type/function-array/webpack.config.js +++ b/test/build/config/type/function-array/webpack.config.js @@ -1,18 +1,18 @@ module.exports = () => [ { - entry: './a', - name: 'first', + entry: "./a", + name: "first", output: { - path: __dirname + '/binary', - filename: 'a-functor.js', + path: __dirname + "/binary", + filename: "a-functor.js", }, }, { - entry: './b', - name: 'second', + entry: "./b", + name: "second", output: { - path: __dirname + '/binary', - filename: 'b-functor.js', + path: __dirname + "/binary", + filename: "b-functor.js", }, }, ]; diff --git a/test/build/config/type/function-async/a.js b/test/build/config/type/function-async/a.js index ea51098c48f..2e67d56775e 100644 --- a/test/build/config/type/function-async/a.js +++ b/test/build/config/type/function-async/a.js @@ -1 +1 @@ -module.exports = 'a-function'; +module.exports = "a-function"; diff --git a/test/build/config/type/function-async/function-async.test.js b/test/build/config/type/function-async/function-async.test.js index d3eb48eb837..29e27a7e789 100644 --- a/test/build/config/type/function-async/function-async.test.js +++ b/test/build/config/type/function-async/function-async.test.js @@ -1,15 +1,18 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('function async', () => { - it('is able to understand a configuration file as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("function async", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/functor.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/functor.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/function-async/webpack.config.js b/test/build/config/type/function-async/webpack.config.js index 6457b889f8c..41f47ea6162 100644 --- a/test/build/config/type/function-async/webpack.config.js +++ b/test/build/config/type/function-async/webpack.config.js @@ -1,9 +1,9 @@ module.exports = async () => { return { - entry: './a', + entry: "./a", output: { - path: __dirname + '/binary', - filename: 'functor.js', + path: __dirname + "/binary", + filename: "functor.js", }, }; }; diff --git a/test/build/config/type/function-promise/a.js b/test/build/config/type/function-promise/a.js index ea51098c48f..2e67d56775e 100644 --- a/test/build/config/type/function-promise/a.js +++ b/test/build/config/type/function-promise/a.js @@ -1 +1 @@ -module.exports = 'a-function'; +module.exports = "a-function"; diff --git a/test/build/config/type/function-promise/function-promise.test.js b/test/build/config/type/function-promise/function-promise.test.js index 15bfa3c4abb..236c1edd1cc 100644 --- a/test/build/config/type/function-promise/function-promise.test.js +++ b/test/build/config/type/function-promise/function-promise.test.js @@ -1,15 +1,18 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('function promise', () => { - it('is able to understand a configuration file as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("function promise", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/functor.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/functor.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/function-promise/webpack.config.js b/test/build/config/type/function-promise/webpack.config.js index 777459d6e0e..90723f2035c 100644 --- a/test/build/config/type/function-promise/webpack.config.js +++ b/test/build/config/type/function-promise/webpack.config.js @@ -2,10 +2,10 @@ module.exports = () => { return new Promise((resolve) => { setTimeout(() => { resolve({ - entry: './a', + entry: "./a", output: { - path: __dirname + '/binary', - filename: 'functor.js', + path: __dirname + "/binary", + filename: "functor.js", }, }); }); diff --git a/test/build/config/type/function-with-argv/a.js b/test/build/config/type/function-with-argv/a.js index d2525d8ea73..493137a97e1 100644 --- a/test/build/config/type/function-with-argv/a.js +++ b/test/build/config/type/function-with-argv/a.js @@ -1 +1 @@ -console.log('Dio'); +console.log("Dio"); diff --git a/test/build/config/type/function-with-argv/function-with-argv.test.js b/test/build/config/type/function-with-argv/function-with-argv.test.js index 1ad6ce20b6f..f9857bd5f65 100644 --- a/test/build/config/type/function-with-argv/function-with-argv.test.js +++ b/test/build/config/type/function-with-argv/function-with-argv.test.js @@ -1,18 +1,18 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = 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', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development']); +describe("function configuration", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "development"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(stdout).toContain('WEBPACK_BUNDLE: true'); - expect(stdout).toContain('WEBPACK_BUILD: true'); + expect(stdout).toContain("WEBPACK_BUNDLE: true"); + expect(stdout).toContain("WEBPACK_BUILD: true"); expect(stdout).toContain("mode: 'development'"); - expect(existsSync(resolve(__dirname, './dist/dev.js'))); + expect(existsSync(resolve(__dirname, "./dist/dev.js"))); }); }); diff --git a/test/build/config/type/function-with-argv/webpack.config.js b/test/build/config/type/function-with-argv/webpack.config.js index 7c313379be8..15b337ac978 100644 --- a/test/build/config/type/function-with-argv/webpack.config.js +++ b/test/build/config/type/function-with-argv/webpack.config.js @@ -2,9 +2,9 @@ module.exports = (env, argv) => { console.log({ argv }); const { mode } = argv; return { - entry: './a.js', + entry: "./a.js", output: { - filename: mode === 'production' ? 'prod.js' : 'dev.js', + filename: mode === "production" ? "prod.js" : "dev.js", }, }; }; diff --git a/test/build/config/type/function-with-env/a.js b/test/build/config/type/function-with-env/a.js index 542cfb7c49e..95512b73637 100644 --- a/test/build/config/type/function-with-env/a.js +++ b/test/build/config/type/function-with-env/a.js @@ -1,5 +1,5 @@ -console.log('chuntaro'); +console.log("chuntaro"); // eslint-disable-next-line no-undef if (envMessage) { - console.log('env message present'); + console.log("env message present"); } diff --git a/test/build/config/type/function-with-env/function-with-env.test.js b/test/build/config/type/function-with-env/function-with-env.test.js index f5050d481c0..4ba8da5d904 100644 --- a/test/build/config/type/function-with-env/function-with-env.test.js +++ b/test/build/config/type/function-with-env/function-with-env.test.js @@ -1,189 +1,196 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run, readFile } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run, readFile } = require("../../../../utils/test-utils"); -describe('function configuration', () => { - it('should throw when env is not supplied', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--env']); +describe("function configuration", () => { + it("should throw when env is not supplied", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--env"]); expect(exitCode).toBe(2); expect(stderr).toContain("Error: Option '--env ' argument missing"); expect(stdout).toBeFalsy(); }); - it('is able to understand a configuration file as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--env', 'isProd']); + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--env", "isProd"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/prod.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/prod.js"))).toBeTruthy(); }); - it('is able to understand a configuration file as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--env', 'isDev']); + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--env", "isDev"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/dev.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/dev.js"))).toBeTruthy(); }); - it('Supports passing string in env', async () => { + it("Supports passing string in env", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'environment=production', - '--env', - 'app.title=Luffy', - '-c', - 'webpack.env.config.js', + "--env", + "environment=production", + "--env", + "app.title=Luffy", + "-c", + "webpack.env.config.js", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/Luffy.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/Luffy.js"))).toBeTruthy(); }); - it('Supports long nested values in env', async () => { + it("Supports long nested values in env", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'file.name.is.this=Atsumu', - '--env', - 'environment=production', - '-c', - 'webpack.env.config.js', + "--env", + "file.name.is.this=Atsumu", + "--env", + "environment=production", + "-c", + "webpack.env.config.js", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/Atsumu.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/Atsumu.js"))).toBeTruthy(); }); - it('Supports multiple equal in a string', async () => { + it("Supports multiple equal in a string", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'file=name=is=Eren', - '--env', - 'environment=multipleq', - '-c', - 'webpack.env.config.js', + "--env", + "file=name=is=Eren", + "--env", + "environment=multipleq", + "-c", + "webpack.env.config.js", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/name=is=Eren.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/name=is=Eren.js"))).toBeTruthy(); }); - it('Supports dot at the end', async () => { + it("Supports dot at the end", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'name.=Hisoka', - '--env', - 'environment=dot', - '-c', - 'webpack.env.config.js', + "--env", + "name.=Hisoka", + "--env", + "environment=dot", + "-c", + "webpack.env.config.js", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/Hisoka.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/Hisoka.js"))).toBeTruthy(); }); - it('Supports dot at the end', async () => { + it("Supports dot at the end", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'name.', - '--env', - 'environment=dot', - '-c', - 'webpack.env.config.js', + "--env", + "name.", + "--env", + "environment=dot", + "-c", + "webpack.env.config.js", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/true.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/true.js"))).toBeTruthy(); }); - it('Supports empty string', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--env', `foo=''`]); + it("Supports empty string", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--env", `foo=''`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/empty-string.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/empty-string.js"))).toBeTruthy(); }); it('Supports empty string with multiple "="', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--env', `foo=bar=''`]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--env", `foo=bar=''`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/new-empty-string.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/new-empty-string.js"))).toBeTruthy(); }); it('Supports env variable with "=" at the end', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--env', `foo=`]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--env", `foo=`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/equal-at-the-end.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/equal-at-the-end.js"))).toBeTruthy(); }); - it('is able to understand multiple env flags', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--env', 'isDev', '--env', 'verboseStats', '--env', 'envMessage']); + it("is able to understand multiple env flags", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "isDev", + "--env", + "verboseStats", + "--env", + "envMessage", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // check that the verbose env is respected - expect(stdout).toContain('LOG from webpack'); + expect(stdout).toContain("LOG from webpack"); let data; try { - data = await readFile(resolve(__dirname, './dist/dev.js'), 'utf-8'); + data = await readFile(resolve(__dirname, "./dist/dev.js"), "utf-8"); } catch (error) { expect(error).toBe(null); } // check if the values from DefinePlugin make it to the compiled code - expect(data).toContain('env message present'); + expect(data).toContain("env message present"); }); - it('is able to apply last flag with same name', async () => { + it("is able to apply last flag with same name", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'name.=foo', - '--env', - 'name.=baz', - '--env', - 'environment=dot', - '-c', - 'webpack.env.config.js', + "--env", + "name.=foo", + "--env", + "name.=baz", + "--env", + "environment=dot", + "-c", + "webpack.env.config.js", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); // Should generate the appropriate files - expect(existsSync(resolve(__dirname, './dist/baz.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/baz.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/function-with-env/webpack.config.js b/test/build/config/type/function-with-env/webpack.config.js index 5a726c711f9..ecb9daebd6e 100644 --- a/test/build/config/type/function-with-env/webpack.config.js +++ b/test/build/config/type/function-with-env/webpack.config.js @@ -1,45 +1,49 @@ -const { DefinePlugin } = require('webpack'); +const { DefinePlugin } = require("webpack"); module.exports = (env) => { if (env.isProd) { return { - entry: './a.js', + entry: "./a.js", output: { - filename: 'prod.js', + filename: "prod.js", }, }; } if (env.foo === `''`) { return { - entry: './a.js', + entry: "./a.js", output: { - filename: 'empty-string.js', + filename: "empty-string.js", }, }; } if (env.foo === `bar=''`) { return { - entry: './a.js', + entry: "./a.js", output: { - filename: 'new-empty-string.js', + filename: "new-empty-string.js", }, }; } - if (env['foo=']) { + if (env["foo="]) { return { - entry: './a.js', + entry: "./a.js", output: { - filename: 'equal-at-the-end.js', + filename: "equal-at-the-end.js", }, }; } return { - entry: './a.js', - mode: 'development', - stats: env.verboseStats ? 'verbose' : 'normal', - plugins: [new DefinePlugin({ envMessage: env.envMessage ? JSON.stringify('env message present') : false })], + entry: "./a.js", + mode: "development", + stats: env.verboseStats ? "verbose" : "normal", + plugins: [ + new DefinePlugin({ + envMessage: env.envMessage ? JSON.stringify("env message present") : false, + }), + ], output: { - filename: 'dev.js', + filename: "dev.js", }, }; }; diff --git a/test/build/config/type/function-with-env/webpack.env.config.js b/test/build/config/type/function-with-env/webpack.env.config.js index b131cf9866d..3e789b2406e 100644 --- a/test/build/config/type/function-with-env/webpack.env.config.js +++ b/test/build/config/type/function-with-env/webpack.env.config.js @@ -2,27 +2,27 @@ module.exports = (env) => { const { environment, app, file } = env; const customName = file && file.name && file.name.is && file.name.is.this; const appTitle = app && app.title; - if (environment === 'production') { + if (environment === "production") { return { - entry: './a.js', + entry: "./a.js", output: { filename: `${customName ? customName : appTitle}.js`, }, }; } - if (environment === 'multipleq') { + if (environment === "multipleq") { const { file } = env; return { - entry: './a.js', + entry: "./a.js", output: { filename: `${file}.js`, }, }; } - if (environment === 'dot') { - const file = env['name.']; + if (environment === "dot") { + const file = env["name."]; return { - entry: './a.js', + entry: "./a.js", output: { filename: `${file}.js`, }, diff --git a/test/build/config/type/function/a.js b/test/build/config/type/function/a.js index ea51098c48f..2e67d56775e 100644 --- a/test/build/config/type/function/a.js +++ b/test/build/config/type/function/a.js @@ -1 +1 @@ -module.exports = 'a-function'; +module.exports = "a-function"; diff --git a/test/build/config/type/function/function.test.js b/test/build/config/type/function/function.test.js index 4f961672f8b..e507bddc6fb 100644 --- a/test/build/config/type/function/function.test.js +++ b/test/build/config/type/function/function.test.js @@ -1,15 +1,18 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('function', () => { - it('is able to understand a configuration file as a function', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); +describe("function", () => { + it("is able to understand a configuration file as a function", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/functor.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/functor.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/function/webpack.config.js b/test/build/config/type/function/webpack.config.js index e03949ce37e..b5bfe25cc36 100644 --- a/test/build/config/type/function/webpack.config.js +++ b/test/build/config/type/function/webpack.config.js @@ -1,9 +1,9 @@ module.exports = () => { return { - entry: './a', + entry: "./a", output: { - path: __dirname + '/binary', - filename: 'functor.js', + path: __dirname + "/binary", + filename: "functor.js", }, }; }; diff --git a/test/build/config/type/promise-array/a.js b/test/build/config/type/promise-array/a.js index 4f7f5db3d4c..312e630d83c 100644 --- a/test/build/config/type/promise-array/a.js +++ b/test/build/config/type/promise-array/a.js @@ -1 +1 @@ -module.exports = 'a-promise'; +module.exports = "a-promise"; diff --git a/test/build/config/type/promise-array/b.js b/test/build/config/type/promise-array/b.js index d4280020bd2..73caf59dfee 100644 --- a/test/build/config/type/promise-array/b.js +++ b/test/build/config/type/promise-array/b.js @@ -1 +1 @@ -module.exports = 'b-promise'; +module.exports = "b-promise"; diff --git a/test/build/config/type/promise-array/promise-array.test.js b/test/build/config/type/promise-array/promise-array.test.js index e2a2dc8dbde..930be8997d4 100644 --- a/test/build/config/type/promise-array/promise-array.test.js +++ b/test/build/config/type/promise-array/promise-array.test.js @@ -1,16 +1,16 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('promise array', () => { - it('is able to understand a configuration file as a promise', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js']); +describe("promise array", () => { + it("is able to understand a configuration file as a promise", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); expect(exitCode).toBe(0); expect(stdout).toBeTruthy(); expect(stderr).toBeFalsy(); - expect(existsSync(resolve(__dirname, './binary/a-promise.js'))).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/a-promise.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/a-promise.js"))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/a-promise.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/promise-array/webpack.config.js b/test/build/config/type/promise-array/webpack.config.js index 4779964e1af..36bcba559aa 100644 --- a/test/build/config/type/promise-array/webpack.config.js +++ b/test/build/config/type/promise-array/webpack.config.js @@ -2,17 +2,17 @@ module.exports = new Promise((resolve) => { setTimeout(() => { resolve([ { - entry: './a', + entry: "./a", output: { - path: __dirname + '/binary', - filename: 'a-promise.js', + path: __dirname + "/binary", + filename: "a-promise.js", }, }, { - entry: './b', + entry: "./b", output: { - path: __dirname + '/binary', - filename: 'b-promise.js', + path: __dirname + "/binary", + filename: "b-promise.js", }, }, ]); diff --git a/test/build/config/type/promise-function/a.js b/test/build/config/type/promise-function/a.js index 4f7f5db3d4c..312e630d83c 100644 --- a/test/build/config/type/promise-function/a.js +++ b/test/build/config/type/promise-function/a.js @@ -1 +1 @@ -module.exports = 'a-promise'; +module.exports = "a-promise"; diff --git a/test/build/config/type/promise-function/promise-function.test.js b/test/build/config/type/promise-function/promise-function.test.js index 74a44f2bf98..fb641cde158 100644 --- a/test/build/config/type/promise-function/promise-function.test.js +++ b/test/build/config/type/promise-function/promise-function.test.js @@ -1,16 +1,16 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('promise function', () => { - it('is able to understand a configuration file as a promise', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js']); +describe("promise function", () => { + it("is able to understand a configuration file as a promise", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/promise.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/promise.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/promise-function/webpack.config.js b/test/build/config/type/promise-function/webpack.config.js index f2881885ba2..88a78b1548f 100644 --- a/test/build/config/type/promise-function/webpack.config.js +++ b/test/build/config/type/promise-function/webpack.config.js @@ -1,10 +1,10 @@ module.exports = new Promise((resolve) => { setTimeout(() => { resolve(() => ({ - entry: './a', + entry: "./a", output: { - path: __dirname + '/binary', - filename: 'promise.js', + path: __dirname + "/binary", + filename: "promise.js", }, })); }, 0); diff --git a/test/build/config/type/promise/a.js b/test/build/config/type/promise/a.js index 4f7f5db3d4c..312e630d83c 100644 --- a/test/build/config/type/promise/a.js +++ b/test/build/config/type/promise/a.js @@ -1 +1 @@ -module.exports = 'a-promise'; +module.exports = "a-promise"; diff --git a/test/build/config/type/promise/promise.test.js b/test/build/config/type/promise/promise.test.js index e3b0ee3c1b2..7aa0d25cbbc 100644 --- a/test/build/config/type/promise/promise.test.js +++ b/test/build/config/type/promise/promise.test.js @@ -1,15 +1,15 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../../../utils/test-utils"); -describe('promise', () => { - it('is able to understand a configuration file as a promise', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js']); +describe("promise", () => { + it("is able to understand a configuration file as a promise", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/promise.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/promise.js"))).toBeTruthy(); }); }); diff --git a/test/build/config/type/promise/webpack.config.js b/test/build/config/type/promise/webpack.config.js index fdfbe448445..3e56fb16bf9 100644 --- a/test/build/config/type/promise/webpack.config.js +++ b/test/build/config/type/promise/webpack.config.js @@ -2,10 +2,10 @@ module.exports = () => new Promise((resolve) => { setTimeout(() => { resolve({ - entry: './a', + entry: "./a", output: { - path: __dirname + '/binary', - filename: 'promise.js', + path: __dirname + "/binary", + filename: "promise.js", }, }); }, 0); diff --git a/test/build/core-flags/amd-flag.test.js b/test/build/core-flags/amd-flag.test.js index e8702f51fcb..7a02a02d89e 100644 --- a/test/build/core-flags/amd-flag.test.js +++ b/test/build/core-flags/amd-flag.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--no-amd flag', () => { - it('should accept --no-amd', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-amd']); +describe("--no-amd flag", () => { + it("should accept --no-amd", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-amd"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('amd: false'); + expect(stdout).toContain("amd: false"); }); }); diff --git a/test/build/core-flags/bail-flag.test.js b/test/build/core-flags/bail-flag.test.js index d0166e8b759..e8928ff0c76 100644 --- a/test/build/core-flags/bail-flag.test.js +++ b/test/build/core-flags/bail-flag.test.js @@ -1,21 +1,21 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--bail flag', () => { - it('should set bail to true', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--bail']); +describe("--bail flag", () => { + it("should set bail to true", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--bail"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('bail: true'); + expect(stdout).toContain("bail: true"); }); - it('should set bail to false', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-bail']); + it("should set bail to false", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-bail"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('bail: false'); + expect(stdout).toContain("bail: false"); }); }); diff --git a/test/build/core-flags/cache-flags.test.js b/test/build/core-flags/cache-flags.test.js index 1ca65eb7b88..fda2212b367 100644 --- a/test/build/core-flags/cache-flags.test.js +++ b/test/build/core-flags/cache-flags.test.js @@ -1,86 +1,108 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const rimraf = require('rimraf'); -const { run } = require('../../utils/test-utils'); -const { existsSync, writeFileSync, unlinkSync } = require('fs'); -const { resolve } = require('path'); +const rimraf = require("rimraf"); +const { run } = require("../../utils/test-utils"); +const { existsSync, writeFileSync, unlinkSync } = require("fs"); +const { resolve } = require("path"); -describe('cache related flags from core', () => { - it('should be successful with --cache ', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--cache']); +describe("cache related flags from core", () => { + it("should be successful with --cache ", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--cache"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`type: 'memory'`); }); - it('should be successful with --no-cache ', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-cache']); + it("should be successful with --no-cache ", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-cache"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('cache: false'); + expect(stdout).toContain("cache: false"); }); - it('should set cache.type', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-type'); + it("should set cache.type", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-type", + ); rimraf.sync(cacheLocation); - const { exitCode, stderr, stdout } = await run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-location', cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`type: 'filesystem'`); }); - it('should set cache.cacheDirectory with --cache-cache-directory', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-cache-directory'); + it("should set cache.cacheDirectory with --cache-cache-directory", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-cache-directory", + ); rimraf.sync(cacheLocation); const { exitCode, stderr, stdout } = await run(__dirname, [ - '--cache-type', - 'filesystem', - '--cache-cache-directory', - './test-cache-path', - '--cache-cache-location', + "--cache-type", + "filesystem", + "--cache-cache-directory", + "./test-cache-path", + "--cache-cache-location", cacheLocation, ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("type: 'filesystem'"); - expect(stdout).toContain('test-cache-path'); + expect(stdout).toContain("test-cache-path"); }); - it('should set cache.cacheLocation with --cache-cache-locations', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-cache-location'); + it("should set cache.cacheLocation with --cache-cache-locations", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-cache-location", + ); rimraf.sync(cacheLocation); - const { exitCode, stderr, stdout } = await run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-location', cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("type: 'filesystem'"); - expect(stdout).toContain('cache-core-flag-test-cache-location'); + expect(stdout).toContain("cache-core-flag-test-cache-location"); expect(existsSync(cacheLocation)).toBeTruthy(); }); - it('should set cache.hashAlgorithm with --cache-hash-algorithm', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-hash-algorithm'); + it("should set cache.hashAlgorithm with --cache-hash-algorithm", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-hash-algorithm", + ); rimraf.sync(cacheLocation); const { exitCode, stderr, stdout } = await run(__dirname, [ - '--cache-type', - 'filesystem', - '--cache-hash-algorithm', - 'sha256', - '--cache-cache-location', + "--cache-type", + "filesystem", + "--cache-hash-algorithm", + "sha256", + "--cache-cache-location", cacheLocation, ]); @@ -90,17 +112,20 @@ describe('cache related flags from core', () => { expect(stdout).toContain(`hashAlgorithm: 'sha256'`); }); - it('should set cache.name with --cache-name', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-name'); + it("should set cache.name with --cache-name", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-name", + ); rimraf.sync(cacheLocation); const { exitCode, stderr, stdout } = await run(__dirname, [ - '--cache-type', - 'filesystem', - '--cache-name', - 'cli-test', - '--cache-cache-location', + "--cache-type", + "filesystem", + "--cache-name", + "cli-test", + "--cache-cache-location", cacheLocation, ]); @@ -110,17 +135,20 @@ describe('cache related flags from core', () => { expect(stdout).toContain(`name: 'cli-test'`); }); - it('should set cache.store with --cache-store', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-store'); + it("should set cache.store with --cache-store", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-store", + ); rimraf.sync(cacheLocation); const { exitCode, stderr, stdout } = await run(__dirname, [ - '--cache-type', - 'filesystem', - '--cache-store', - 'pack', - '--cache-cache-location', + "--cache-type", + "filesystem", + "--cache-store", + "pack", + "--cache-cache-location", cacheLocation, ]); @@ -130,17 +158,20 @@ describe('cache related flags from core', () => { expect(stdout).toContain(`store: 'pack'`); }); - it('should set cache.version with --cache-version', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-version'); + it("should set cache.version with --cache-version", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-version", + ); rimraf.sync(cacheLocation); const { exitCode, stderr, stdout } = await run(__dirname, [ - '--cache-type', - 'filesystem', - '--cache-version', - '1.1.3', - '--cache-cache-location', + "--cache-type", + "filesystem", + "--cache-version", + "1.1.3", + "--cache-cache-location", cacheLocation, ]); @@ -150,148 +181,199 @@ describe('cache related flags from core', () => { expect(stdout).toContain(`version: '1.1.3'`); }); - it('should assign cache build dependencies correctly when cache type is filesystem', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-build-dependencies'); + it("should assign cache build dependencies correctly when cache type is filesystem", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-build-dependencies", + ); rimraf.sync(cacheLocation); let { stderr, stdout, exitCode } = await run(__dirname, [ - '--cache-type', - 'filesystem', - '-c', - './webpack.config.js', - '--cache-cache-location', + "--cache-type", + "filesystem", + "-c", + "./webpack.config.js", + "--cache-cache-location", cacheLocation, ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("type: 'filesystem'"); - expect(stdout).toContain('buildDependencies'); + expect(stdout).toContain("buildDependencies"); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.config.js')}'`); - expect(stdout).not.toContain('[cached]'); + expect(stdout).not.toContain("[cached]"); // Run again to check for cache ({ exitCode, stderr, stdout } = await run(__dirname, [ - '--cache-type', - 'filesystem', - '-c', - './webpack.config.js', - '--cache-cache-location', + "--cache-type", + "filesystem", + "-c", + "./webpack.config.js", + "--cache-cache-location", cacheLocation, ])); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('[cached]'); + expect(stdout).toContain("[cached]"); }); - it('should assign cache build dependencies correctly when cache type is filesystem in config', async () => { + it("should assign cache build dependencies correctly when cache type is filesystem in config", async () => { const cacheLocation = path.resolve( __dirname, - '../../../node_modules/.cache/webpack/cache-core-flag-test-build-dependencies-in-config', + "../../../node_modules/.cache/webpack/cache-core-flag-test-build-dependencies-in-config", ); rimraf.sync(cacheLocation); let { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './webpack.cache.config.js', - '--cache-cache-location', + "-c", + "./webpack.cache.config.js", + "--cache-cache-location", cacheLocation, ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("type: 'filesystem'"); - expect(stdout).toContain('buildDependencies'); + expect(stdout).toContain("buildDependencies"); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.cache.config.js')}'`); // Run again to check for cache - ({ exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.cache.config.js', '--cache-cache-location', cacheLocation])); + ({ exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.cache.config.js", + "--cache-cache-location", + cacheLocation, + ])); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('[cached]'); + expect(stdout).toContain("[cached]"); }); - it('should assign cache build dependencies with multiple configs', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/config-cache')); + it("should assign cache build dependencies with multiple configs", async () => { + rimraf.sync(path.join(__dirname, "../../../node_modules/.cache/webpack/config-cache")); - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.cache.config.js", + "-c", + "./webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("type: 'filesystem'"); - expect(stdout).toContain('buildDependencies'); + expect(stdout).toContain("buildDependencies"); // expect(stdout).toContain(`'${resolve(__dirname, 'webpack.cache.config.js')}'`); - expect(stdout).not.toContain(`'${resolve(__dirname, 'webpack.config.js')}'`); + expect(stdout).not.toContain(`'${resolve(__dirname, "webpack.config.js")}'`); }); - it('should assign cache build dependencies with default config', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-development')); + it("should assign cache build dependencies with default config", async () => { + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-development", + ), + ); - const { exitCode, stderr, stdout } = await run(__dirname, ['--cache-type', 'filesystem', '--name', 'cache-core-flag-test']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--name", + "cache-core-flag-test", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('buildDependencies'); + 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', async () => { - const cacheLocation = path.resolve(__dirname, '../../../node_modules/.cache/webpack/cache-core-flag-test-merge'); + it("should assign cache build dependencies with merged configs", async () => { + const cacheLocation = path.resolve( + __dirname, + "../../../node_modules/.cache/webpack/cache-core-flag-test-merge", + ); rimraf.sync(cacheLocation); const { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './webpack.cache.config.js', - '-c', - './webpack.config.js', - '--merge', - '--cache-cache-location', + "-c", + "./webpack.cache.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--cache-cache-location", cacheLocation, ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("type: 'filesystem'"); - expect(stdout).toContain('buildDependencies'); + expect(stdout).toContain("buildDependencies"); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.cache.config.js')}'`); // expect(stdout).toContain(`'${path.join(__dirname, './webpack.config.js')}'`); }); - it('should invalidate cache when config changes', async () => { - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/default-development')); - rimraf.sync(path.join(__dirname, '../../../node_modules/.cache/webpack/default-production')); + it("should invalidate cache when config changes", async () => { + rimraf.sync( + path.join(__dirname, "../../../node_modules/.cache/webpack/default-development"), + ); + rimraf.sync( + path.join(__dirname, "../../../node_modules/.cache/webpack/default-production"), + ); // Creating a temporary webpack config - writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "development"}'); + writeFileSync( + resolve(__dirname, "./webpack.test.config.js"), + 'module.exports = {mode: "development"}', + ); - let { exitCode, stderr, stdout } = await run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); + let { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "-c", + "./webpack.test.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).not.toContain('[cached]'); + expect(stdout).not.toContain("[cached]"); // Running again should use the cache - ({ exitCode, stderr, stdout } = await run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js'])); + ({ exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "-c", + "./webpack.test.config.js", + ])); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('[cached]'); + expect(stdout).toContain("[cached]"); // Change config to invalidate cache - writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "production"}'); + writeFileSync( + resolve(__dirname, "./webpack.test.config.js"), + 'module.exports = {mode: "production"}', + ); - ({ exitCode, stderr, stdout } = await run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js'])); + ({ exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "-c", + "./webpack.test.config.js", + ])); - unlinkSync(resolve(__dirname, './webpack.test.config.js')); + unlinkSync(resolve(__dirname, "./webpack.test.config.js")); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).not.toContain('[cached]'); + expect(stdout).not.toContain("[cached]"); }); }); diff --git a/test/build/core-flags/context-flag.test.js b/test/build/core-flags/context-flag.test.js index 9e0784cb95c..38d4e7fb37b 100644 --- a/test/build/core-flags/context-flag.test.js +++ b/test/build/core-flags/context-flag.test.js @@ -1,25 +1,28 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run, isWindows } = require('../../utils/test-utils'); +const { resolve } = require("path"); +const { run, isWindows } = require("../../utils/test-utils"); -describe('--context flag', () => { - it('should allow to set context', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--context', './']); +describe("--context flag", () => { + it("should allow to set context", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--context", "./"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); if (isWindows) { - const windowsPath = resolve(__dirname, './').replace(/\\/g, '\\\\'); + const windowsPath = resolve(__dirname, "./").replace(/\\/g, "\\\\"); expect(stdout).toContain(`'${windowsPath}'`); } else { - expect(stdout).toContain(`'${resolve(__dirname, './')}'`); + expect(stdout).toContain(`'${resolve(__dirname, "./")}'`); } }); - it('should throw module not found error for invalid context', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--context', '/invalid-context-path']); + it("should throw module not found error for invalid context", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--context", + "/invalid-context-path", + ]); expect(exitCode).toBe(1); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/dependencies-flag.test.js b/test/build/core-flags/dependencies-flag.test.js index 2dbfdcff15f..643783d1d7d 100644 --- a/test/build/core-flags/dependencies-flag.test.js +++ b/test/build/core-flags/dependencies-flag.test.js @@ -1,21 +1,21 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--dependencies and related flags', () => { - it('should allow to set dependencies option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--dependencies', 'lodash']); +describe("--dependencies and related flags", () => { + it("should allow to set dependencies option", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--dependencies", "lodash"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`dependencies: [ 'lodash' ]`); }); - it('should reset dependencies option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--dependencies-reset']); + it("should reset dependencies option", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--dependencies-reset"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('dependencies: []'); + expect(stdout).toContain("dependencies: []"); }); }); diff --git a/test/build/core-flags/devtool-flag.test.js b/test/build/core-flags/devtool-flag.test.js index ee3697a52b1..86fff541e70 100644 --- a/test/build/core-flags/devtool-flag.test.js +++ b/test/build/core-flags/devtool-flag.test.js @@ -1,29 +1,29 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--devtool flag', () => { - it('should set devtool option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--devtool', 'source-map']); +describe("--devtool flag", () => { + it("should set devtool option", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--devtool", "source-map"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`devtool: 'source-map'`); }); - it('should set devtool option to false', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-devtool']); + it("should set devtool option to false", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-devtool"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`devtool: false`); }); - it('should log error for invalid config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--devtool', 'invalid']); + it("should log error for invalid config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--devtool", "invalid"]); expect(exitCode).toBe(2); - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/core-flags/entry-reset-flag.test.js b/test/build/core-flags/entry-reset-flag.test.js index 140cce8cff8..b8d3c176f63 100644 --- a/test/build/core-flags/entry-reset-flag.test.js +++ b/test/build/core-flags/entry-reset-flag.test.js @@ -1,22 +1,26 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--entry-reset flag', () => { - it('should reset entry correctly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry-reset', '--entry', './src/entry.js']); +describe("--entry-reset flag", () => { + it("should reset entry correctly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry-reset", + "--entry", + "./src/entry.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('src/entry.js'); - expect(stdout).not.toContain('src/main.js'); + expect(stdout).toContain("src/entry.js"); + expect(stdout).not.toContain("src/main.js"); }); - it('should throw error if entry is an empty array', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry-reset']); + it("should throw error if entry is an empty array", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--entry-reset"]); expect(exitCode).toBe(2); - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/core-flags/experiments-flag.test.js b/test/build/core-flags/experiments-flag.test.js index b083be50724..315ce4ffc21 100644 --- a/test/build/core-flags/experiments-flag.test.js +++ b/test/build/core-flags/experiments-flag.test.js @@ -1,33 +1,33 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const experimentsFlags = getWebpackCliArguments('experiments-'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const experimentsFlags = getWebpackCliArguments("experiments-"); -describe('experiments option related flag', () => { +describe("experiments option related flag", () => { for (const [name, value] of Object.entries(experimentsFlags)) { // extract property name from flag name let property; - if (name.includes('-lazy-compilation-')) { - property = name.split('experiments-lazy-compilation-')[1]; + if (name.includes("-lazy-compilation-")) { + property = name.split("experiments-lazy-compilation-")[1]; } else { - property = name.split('experiments-')[1]; + property = name.split("experiments-")[1]; } const propName = hyphenToUpperCase(property); - if (propName === 'client' || propName === 'test') { + if (propName === "client" || propName === "test") { return false; } - if (value.configs.filter((config) => config.type === 'boolean').length > 0) { + if (value.configs.filter((config) => config.type === "boolean").length > 0) { it(`should config --${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name.includes('-lazy-compilation-')) { + if (name.includes("-lazy-compilation-")) { expect(stdout).toContain(`lazyCompilation: { ${propName}: true }`); } else { expect(stdout).toContain(`${propName}: true`); @@ -40,7 +40,7 @@ describe('experiments option related flag', () => { expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name.includes('-lazy-compilation-')) { + if (name.includes("-lazy-compilation-")) { expect(stdout).toContain(`lazyCompilation: { ${propName}: false }`); } else { expect(stdout).toContain(`${propName}: false`); diff --git a/test/build/core-flags/externals-flags.test.js b/test/build/core-flags/externals-flags.test.js index 844c25e2ad9..da450af5117 100644 --- a/test/build/core-flags/externals-flags.test.js +++ b/test/build/core-flags/externals-flags.test.js @@ -1,35 +1,35 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const externalsPresetsFlags = getWebpackCliArguments('externals-presets-'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const externalsPresetsFlags = getWebpackCliArguments("externals-presets-"); -describe('externals related flag', () => { - it('should set externals properly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--externals', './main.js']); +describe("externals related flag", () => { + it("should set externals properly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--externals", "./main.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`externals: [ './main.js' ]`); }); - it('should set externalsType properly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--externals', 'var']); + it("should set externalsType properly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--externals", "var"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`externalsType: 'var'`); }); - it('should accept --external-type values', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--externals-type', 'var']); + it("should accept --external-type values", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--externals-type", "var"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`externalsType: 'var'`); }); - it('should reset externals', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--externals-reset']); + it("should reset externals", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--externals-reset"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -38,7 +38,7 @@ describe('externals related flag', () => { for (const [name] of Object.entries(externalsPresetsFlags)) { // extract property name from flag name - const property = name.split('externals-presets-')[1]; + const property = name.split("externals-presets-")[1]; const propName = hyphenToUpperCase(property); it(`should config --${name} correctly`, async () => { diff --git a/test/build/core-flags/ignore-warnings/ignore-warnings-flag.test.js b/test/build/core-flags/ignore-warnings/ignore-warnings-flag.test.js index 5dd613568d6..352cf704516 100644 --- a/test/build/core-flags/ignore-warnings/ignore-warnings-flag.test.js +++ b/test/build/core-flags/ignore-warnings/ignore-warnings-flag.test.js @@ -1,28 +1,35 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('ignore-warnings', () => { - it('should ignore the warning emitted', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--ignore-warnings', /Generated Warning/]); +describe("ignore-warnings", () => { + it("should ignore the warning emitted", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--ignore-warnings", + /Generated Warning/, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).not.toContain('Module Warning (from ./my-warning-loader.js):'); - expect(stdout).not.toContain('Generated Warning'); + expect(stdout).not.toContain("Module Warning (from ./my-warning-loader.js):"); + expect(stdout).not.toContain("Generated Warning"); }); - it('should reset options.ignoreWarnings', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--ignore-warnings', /Generated Warning/, '--ignore-warnings-reset']); + it("should reset options.ignoreWarnings", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--ignore-warnings", + /Generated Warning/, + "--ignore-warnings-reset", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('Module Warning (from ./my-warning-loader.js):'); - expect(stdout).toContain('Generated Warning'); + expect(stdout).toContain("Module Warning (from ./my-warning-loader.js):"); + expect(stdout).toContain("Generated Warning"); }); - it('should throw error for an invalid value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--ignore-warnings', 'abc']); + it("should throw error for an invalid value", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--ignore-warnings", "abc"]); expect(exitCode).toBe(2); expect(stderr).toContain(`Invalid value 'abc' for the '--ignore-warnings' option`); diff --git a/test/build/core-flags/ignore-warnings/my-warning-loader.js b/test/build/core-flags/ignore-warnings/my-warning-loader.js index dcf7db3737d..d72b4775718 100644 --- a/test/build/core-flags/ignore-warnings/my-warning-loader.js +++ b/test/build/core-flags/ignore-warnings/my-warning-loader.js @@ -1,5 +1,5 @@ module.exports = function loader(source) { const { emitWarning } = this; - emitWarning('Generated Warning'); + emitWarning("Generated Warning"); return source; }; diff --git a/test/build/core-flags/ignore-warnings/src/main.js b/test/build/core-flags/ignore-warnings/src/main.js index a136806e8f1..79f3f155834 100644 --- a/test/build/core-flags/ignore-warnings/src/main.js +++ b/test/build/core-flags/ignore-warnings/src/main.js @@ -1 +1 @@ -console.log('Entry'); +console.log("Entry"); diff --git a/test/build/core-flags/ignore-warnings/webpack.config.js b/test/build/core-flags/ignore-warnings/webpack.config.js index 521581d4a12..8535fb996b6 100644 --- a/test/build/core-flags/ignore-warnings/webpack.config.js +++ b/test/build/core-flags/ignore-warnings/webpack.config.js @@ -1,24 +1,24 @@ -const path = require('path'); +const path = require("path"); module.exports = { - mode: 'development', - entry: './src/main.js', + mode: "development", + entry: "./src/main.js", module: { rules: [ { test: /.(js|jsx)?$/, - loader: 'my-warning-loader', - include: [path.resolve(__dirname, 'src')], + loader: "my-warning-loader", + include: [path.resolve(__dirname, "src")], exclude: [/node_modules/], }, ], }, resolveLoader: { alias: { - 'my-warning-loader': require.resolve('./my-warning-loader'), + "my-warning-loader": require.resolve("./my-warning-loader"), }, }, performance: { - hints: 'warning', + hints: "warning", }, }; diff --git a/test/build/core-flags/infrastructure-logging.test.js b/test/build/core-flags/infrastructure-logging.test.js index 25aed04c93d..1f63f2c75e2 100644 --- a/test/build/core-flags/infrastructure-logging.test.js +++ b/test/build/core-flags/infrastructure-logging.test.js @@ -1,26 +1,34 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('infrastructure logging related flag', () => { - it('should set infrastructureLogging.debug properly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--infrastructure-logging-debug', 'myPlugin']); +describe("infrastructure logging related flag", () => { + it("should set infrastructureLogging.debug properly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--infrastructure-logging-debug", + "myPlugin", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`debug: [ 'myPlugin' ]`); }); - it('should reset infrastructureLogging.debug to []', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--infrastructure-logging-debug-reset']); + it("should reset infrastructureLogging.debug to []", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--infrastructure-logging-debug-reset", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`debug: []`); }); - it('should set infrastructureLogging.level properly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--infrastructure-logging-level', 'log']); + it("should set infrastructureLogging.level properly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--infrastructure-logging-level", + "log", + ]); expect(exitCode).toBe(0); expect(stderr).toContain("Compiler 'compiler' starting..."); diff --git a/test/build/core-flags/invalid-flag.test.js b/test/build/core-flags/invalid-flag.test.js index 3a06b2784b0..34dbc286c52 100644 --- a/test/build/core-flags/invalid-flag.test.js +++ b/test/build/core-flags/invalid-flag.test.js @@ -1,10 +1,13 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('invalid flag value', () => { - it('should throw an error for the invalid value passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--output-script-type', 'unknown']); +describe("invalid flag value", () => { + it("should throw an error for the invalid value passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--output-script-type", + "unknown", + ]); expect(exitCode).toBe(2); expect(stderr).toContain("Invalid value 'unknown' for the '--output-script-type' option"); diff --git a/test/build/core-flags/mock/mock.js b/test/build/core-flags/mock/mock.js index ca58180213d..f1e884cc25e 100644 --- a/test/build/core-flags/mock/mock.js +++ b/test/build/core-flags/mock/mock.js @@ -1 +1 @@ -console.log('MOCK'); +console.log("MOCK"); diff --git a/test/build/core-flags/module-flags.test.js b/test/build/core-flags/module-flags.test.js index 6b2f241ba6d..ae425b2386a 100644 --- a/test/build/core-flags/module-flags.test.js +++ b/test/build/core-flags/module-flags.test.js @@ -1,46 +1,53 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, normalizeStdout, getWebpackCliArguments } = require('../../utils/test-utils'); -const moduleFlags = getWebpackCliArguments('module-'); +const { + run, + hyphenToUpperCase, + normalizeStdout, + getWebpackCliArguments, +} = require("../../utils/test-utils"); +const moduleFlags = getWebpackCliArguments("module-"); -describe('module config related flag', () => { +describe("module config related flag", () => { for (const [name, value] of Object.entries(moduleFlags)) { // extract property name from flag name - let property = name.split('module-')[1]; + let property = name.split("module-")[1]; - if (property.includes('rules-') && property !== 'rules-reset') { - property = name.split('rules-')[1]; + if (property.includes("rules-") && property !== "rules-reset") { + property = name.split("rules-")[1]; } const propName = hyphenToUpperCase(property); if ( - value.configs.filter((config) => config.type === 'boolean').length > 0 && - !name.includes('module-no-parse') && - !name.includes('module-parser-') + value.configs.filter((config) => config.type === "boolean").length > 0 && + !name.includes("module-no-parse") && + !name.includes("module-parser-") ) { it(`should config --${name} correctly`, async () => { - if (name.includes('-reset')) { + if (name.includes("-reset")) { const { stderr, stdout } = await run(__dirname, [`--${name}`]); - const option = propName.split('Reset')[0]; + const option = propName.split("Reset")[0]; expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain(`${option}: []`); - } else if (name.includes('rules-')) { + } else if (name.includes("rules-")) { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain("sideEffects: 'flag'"); - } else if (name.startsWith('module-generator-')) { + } else if (name.startsWith("module-generator-")) { const { exitCode, stderr, stdout } = await run(__dirname, [ `--module-generator-asset-emit`, - '--module-generator-asset-resource-emit', + "--module-generator-asset-resource-emit", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(normalizeStdout(stdout)).toContain("generator: { asset: { emit: true }, 'asset/resource': { emit: true } }"); + expect(normalizeStdout(stdout)).toContain( + "generator: { asset: { emit: true }, 'asset/resource': { emit: true } }", + ); } else { const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`]); @@ -50,17 +57,17 @@ describe('module config related flag', () => { } }); - if (!name.endsWith('-reset')) { + if (!name.endsWith("-reset")) { it(`should config --no-${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name.includes('rules-')) { - expect(normalizeStdout(stdout)).toContain('sideEffects: false'); - } else if (name.startsWith('module-generator-')) { - expect(normalizeStdout(stdout)).toContain('emit: false'); + if (name.includes("rules-")) { + expect(normalizeStdout(stdout)).toContain("sideEffects: false"); + } else if (name.startsWith("module-generator-")) { + expect(normalizeStdout(stdout)).toContain("emit: false"); } else { expect(normalizeStdout(stdout)).toContain(`${propName}: false`); } @@ -69,39 +76,50 @@ describe('module config related flag', () => { } if ( - value.configs.filter((config) => config.type === 'string').length > 0 && - !(name.includes('module-parser-') || name.startsWith('module-generator')) + value.configs.filter((config) => config.type === "string").length > 0 && + !(name.includes("module-parser-") || name.startsWith("module-generator")) ) { it(`should config --${name} correctly`, async () => { - if (name === 'module-no-parse') { - let { stderr, stdout, exitCode } = await run(__dirname, [`--${name}`, 'value']); + if (name === "module-no-parse") { + let { stderr, stdout, exitCode } = await run(__dirname, [`--${name}`, "value"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(normalizeStdout(stdout)).toContain('value'); - } else if (name.includes('reg-exp')) { - let { stdout, stderr, exitCode } = await run(__dirname, [`--${name}`, '/ab?c*/']); + expect(normalizeStdout(stdout)).toContain("value"); + } else if (name.includes("reg-exp")) { + let { stdout, stderr, exitCode } = await run(__dirname, [ + `--${name}`, + "/ab?c*/", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain(`${propName}: /ab?c*/`); - } else if (name.includes('module-rules-')) { - if (propName === 'use' || propName === 'type') { - let { stdout } = await run(__dirname, [`--${name}`, 'javascript/auto']); + } else if (name.includes("module-rules-")) { + if (propName === "use" || propName === "type") { + let { stdout } = await run(__dirname, [`--${name}`, "javascript/auto"]); expect(normalizeStdout(stdout)).toContain(`${propName}: 'javascript/auto'`); - } else if (property.includes('use-')) { - let { stdout } = await run(__dirname, ['--module-rules-use-loader', 'myLoader']); + } else if (property.includes("use-")) { + let { stdout } = await run(__dirname, [ + "--module-rules-use-loader", + "myLoader", + ]); expect(normalizeStdout(stdout)).toContain(`use: [Object]`); - } else if (propName === 'enforce') { - let { stdout } = await run(__dirname, [`--${name}`, 'pre', '--module-rules-use-loader', 'myLoader']); + } else if (propName === "enforce") { + let { stdout } = await run(__dirname, [ + `--${name}`, + "pre", + "--module-rules-use-loader", + "myLoader", + ]); expect(normalizeStdout(stdout)).toContain(`${propName}: 'pre'`); } else { - let { stdout } = await run(__dirname, [`--${name}`, '/rules-value']); - expect(normalizeStdout(stdout)).toContain('rules-value'); + let { stdout } = await run(__dirname, [`--${name}`, "/rules-value"]); + expect(normalizeStdout(stdout)).toContain("rules-value"); } } else { - let { stderr, stdout, exitCode } = await run(__dirname, [`--${name}`, 'value']); + let { stderr, stdout, exitCode } = await run(__dirname, [`--${name}`, "value"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -111,12 +129,12 @@ describe('module config related flag', () => { } } - it('should config module.generator flags coorectly', async () => { + it("should config module.generator flags coorectly", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--module-generator-asset-data-url-encoding', - 'base64', - '--module-generator-asset-data-url-mimetype', - 'application/node', + "--module-generator-asset-data-url-encoding", + "base64", + "--module-generator-asset-data-url-mimetype", + "application/node", ]); expect(exitCode).toBe(0); @@ -124,38 +142,46 @@ describe('module config related flag', () => { expect(normalizeStdout(stdout)).toContain(`generator: { asset: { dataUrl: [Object] } }`); }); - it('should config module.parser flags correctly', async () => { + it("should config module.parser flags correctly", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--module-parser-javascript-browserify', - '--module-parser-javascript-commonjs', - '--module-parser-javascript-harmony', - '--module-parser-javascript-import', - '--no-module-parser-javascript-node', - '--module-parser-javascript-require-include', + "--module-parser-javascript-browserify", + "--module-parser-javascript-commonjs", + "--module-parser-javascript-harmony", + "--module-parser-javascript-import", + "--no-module-parser-javascript-node", + "--module-parser-javascript-require-include", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(normalizeStdout(stdout)).toContain('browserify: true'); - expect(normalizeStdout(stdout)).toContain('commonjs: true'); - expect(normalizeStdout(stdout)).toContain('harmony: true'); - expect(normalizeStdout(stdout)).toContain('import: true'); - expect(normalizeStdout(stdout)).toContain('node: false'); + expect(normalizeStdout(stdout)).toContain("browserify: true"); + expect(normalizeStdout(stdout)).toContain("commonjs: true"); + expect(normalizeStdout(stdout)).toContain("harmony: true"); + expect(normalizeStdout(stdout)).toContain("import: true"); + expect(normalizeStdout(stdout)).toContain("node: false"); }); - it('should accept --module-parser-javascript-url=relative', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--module-parser-javascript-url', 'relative']); + it("should accept --module-parser-javascript-url=relative", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--module-parser-javascript-url", + "relative", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain(`url: 'relative'`); }); - it('should throw an error for an invalid value of --module-parser-javascript-url', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--module-parser-javascript-url', 'test']); + it("should throw an error for an invalid value of --module-parser-javascript-url", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--module-parser-javascript-url", + "test", + ]); expect(exitCode).toBe(2); - expect(normalizeStdout(stderr)).toContain(`Invalid value 'test' for the '--module-parser-javascript-url' option`); + expect(normalizeStdout(stderr)).toContain( + `Invalid value 'test' for the '--module-parser-javascript-url' option`, + ); expect(normalizeStdout(stderr)).toContain(`Expected: 'relative'`); expect(stdout).toBeFalsy(); }); diff --git a/test/build/core-flags/node-flags.test.js b/test/build/core-flags/node-flags.test.js index c70338cd011..c1358879d51 100644 --- a/test/build/core-flags/node-flags.test.js +++ b/test/build/core-flags/node-flags.test.js @@ -1,26 +1,26 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('node option related flags', () => { - it('should config node option to false', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-node']); +describe("node option related flags", () => { + it("should config node option to false", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-node"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('node: false'); + expect(stdout).toContain("node: false"); }); - it('should set node.filename correctly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-filename', 'mock']); + it("should set node.filename correctly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--node-filename", "mock"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`__filename: 'mock'`); }); - it('should set node.filename correctly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-dirname', 'mock']); + it("should set node.filename correctly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--node-dirname", "mock"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/optimization-flags.test.js b/test/build/core-flags/optimization-flags.test.js index 409daa10f4f..c04e7c495d0 100644 --- a/test/build/core-flags/optimization-flags.test.js +++ b/test/build/core-flags/optimization-flags.test.js @@ -1,38 +1,38 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const optimizationFlags = getWebpackCliArguments('optimization-'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const optimizationFlags = getWebpackCliArguments("optimization-"); -describe('optimization config related flag', () => { +describe("optimization config related flag", () => { for (const [name, value] of Object.entries(optimizationFlags)) { // extract property name from flag name - let property = name.split('optimization-')[1]; + let property = name.split("optimization-")[1]; - if (name.includes('split-chunks')) { - property = name.split('optimization-split-chunks-')[1]; + if (name.includes("split-chunks")) { + property = name.split("optimization-split-chunks-")[1]; } let propName = hyphenToUpperCase(property); - if (name.includes('-reset')) { - propName = propName.split('Reset')[0]; + if (name.includes("-reset")) { + propName = propName.split("Reset")[0]; } - if (value.configs.filter((config) => config.type === 'boolean').length > 0) { + if (value.configs.filter((config) => config.type === "boolean").length > 0) { it(`should config --${name} correctly`, async () => { - if (name === 'optimization-split-chunks') { + if (name === "optimization-split-chunks") { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`splitChunks: false`); - } else if (name.includes('reset')) { + } else if (name.includes("reset")) { const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: []`); - } else if (name === 'optimization-runtime-chunk') { + } else if (name === "optimization-runtime-chunk") { const { exitCode, stderr } = await run(__dirname, [`--${name}`]); expect(exitCode).toBe(0); @@ -46,15 +46,15 @@ describe('optimization config related flag', () => { } }); - if (!name.includes('reset')) { + if (!name.includes("reset")) { it(`should config --no-${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name === 'optimization-split-chunks') { - expect(stdout).toContain('splitChunks: false'); + if (name === "optimization-split-chunks") { + expect(stdout).toContain("splitChunks: false"); } else { expect(stdout).toContain(`${propName}: false`); } @@ -65,43 +65,61 @@ describe('optimization config related flag', () => { // ignoring optimization-runtime-* and split-chunks-fallback-* flags because WebpackClITestPlugin logs [Object] // need improve the plugin to log for multi-level options i.e, optimization.runtime if ( - value.configs.filter((config) => config.type === 'string').length > 0 && - !name.includes('runtime-') && - !name.includes('fallback-') + value.configs.filter((config) => config.type === "string").length > 0 && + !name.includes("runtime-") && + !name.includes("fallback-") ) { it(`should config --${name} correctly`, async () => { - if (name === 'optimization-split-chunks-chunks') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'initial']); + if (name === "optimization-split-chunks-chunks") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "initial", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`chunks: 'initial'`); - } else if (name === 'optimization-mangle-exports') { - const { exitCode, stderr, stdout } = await run(__dirname, ['--optimization-mangle-exports', 'size']); + } else if (name === "optimization-mangle-exports") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--optimization-mangle-exports", + "size", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mangleExports: 'size'`); - } else if (name === 'optimization-used-exports') { - const { exitCode, stderr, stdout } = await run(__dirname, ['--optimization-used-exports', 'global']); + } else if (name === "optimization-used-exports") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--optimization-used-exports", + "global", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`usedExports: 'global'`); - } else if (name === 'optimization-split-chunks-default-size-types') { - const { exitCode, stderr, stdout } = await run(__dirname, ['--optimization-split-chunks-default-size-types', 'global']); + } else if (name === "optimization-split-chunks-default-size-types") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--optimization-split-chunks-default-size-types", + "global", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`defaultSizeTypes: [Array]`); - } else if (name === 'optimization-side-effects') { - const { exitCode, stderr, stdout } = await run(__dirname, ['--optimization-side-effects', 'flag']); + } else if (name === "optimization-side-effects") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--optimization-side-effects", + "flag", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'flag'`); } else { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'named']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "named", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -110,14 +128,17 @@ describe('optimization config related flag', () => { }); } - if (value.configs.filter((config) => config.type === 'number').length > 0 && !name.includes('fallback-')) { + if ( + value.configs.filter((config) => config.type === "number").length > 0 && + !name.includes("fallback-") + ) { it(`should config --${name} correctly`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '10']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "10"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name === 'optimization-split-chunks') { + if (name === "optimization-split-chunks") { expect(stdout).toContain(`chunks: 'async'`); expect(stdout).toContain(`minChunks: 1`); } else { diff --git a/test/build/core-flags/output-flags.test.js b/test/build/core-flags/output-flags.test.js index b87c943bbe6..b4a82de718f 100644 --- a/test/build/core-flags/output-flags.test.js +++ b/test/build/core-flags/output-flags.test.js @@ -1,40 +1,46 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const outputFlags = getWebpackCliArguments('output-'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const outputFlags = getWebpackCliArguments("output-"); -describe('output config related flag', () => { +describe("output config related flag", () => { for (const [name, value] of Object.entries(outputFlags)) { // extract property name from flag name - let property = name.split('output-')[1]; + let property = name.split("output-")[1]; - if (property.includes('environment-')) { - property = property.split('environment-')[1]; - } else if (property.includes('clean-')) { - property = property.split('clean-')[1]; + if (property.includes("environment-")) { + property = property.split("environment-")[1]; + } else if (property.includes("clean-")) { + property = property.split("clean-")[1]; } const propName = hyphenToUpperCase(property); - if (value.configs.filter((config) => config.type === 'boolean').length > 0 && !name.includes('output-library')) { + if ( + value.configs.filter((config) => config.type === "boolean").length > 0 && + !name.includes("output-library") + ) { it(`should config --${name} correctly`, async () => { let { stderr, stdout, exitCode } = await run(__dirname, [`--${name}`]); - if (name === 'output-module') { + if (name === "output-module") { //'output.module: true' is only allowed when 'experiments.outputModule' is enabled - ({ exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '--experiments-output-module'])); + ({ exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "--experiments-output-module", + ])); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('module: true'); - } else if (name === 'output-strict-module-error-handling') { - ({ exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '--hot'])); + expect(stdout).toContain("module: true"); + } else if (name === "output-strict-module-error-handling") { + ({ exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "--hot"])); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: true`); - } else if (name.includes('-reset')) { - const option = propName.split('Reset')[0]; + } else if (name.includes("-reset")) { + const option = propName.split("Reset")[0]; expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -46,7 +52,7 @@ describe('output config related flag', () => { } }); - if (!name.endsWith('-reset') && !name.includes('output-strict-module-error-handling')) { + if (!name.endsWith("-reset") && !name.includes("output-strict-module-error-handling")) { it(`should config --no-${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-${name}`]); @@ -57,9 +63,9 @@ describe('output config related flag', () => { } } - if (value.configs.filter((config) => config.type === 'number').length > 0) { + if (value.configs.filter((config) => config.type === "number").length > 0) { it(`should config --${name} correctly`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '10']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "10"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -67,88 +73,130 @@ describe('output config related flag', () => { }); } - if (value.configs.filter((config) => config.type === 'string').length > 0 && !name.includes('output-library')) { + if ( + value.configs.filter((config) => config.type === "string").length > 0 && + !name.includes("output-library") + ) { it(`should config --${name} correctly`, async () => { - if (name === 'output-cross-origin-loading') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'anonymous']); + if (name === "output-cross-origin-loading") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "anonymous", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'anonymous'`); - } else if (name === 'output-chunk-format') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'commonjs']); + } else if (name === "output-chunk-format") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "commonjs", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'commonjs'`); - } else if (name === 'output-chunk-loading') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'jsonp']); + } else if (name === "output-chunk-loading") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "jsonp", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'jsonp'`); - } else if (name === 'output-enabled-chunk-loading-types' || name === 'output-enabled-wasm-loading-types') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'async-node']); + } else if ( + name === "output-enabled-chunk-loading-types" || + name === "output-enabled-wasm-loading-types" + ) { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "async-node", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: [ 'async-node' ]`); - } else if (name === 'output-enabled-library-type') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'amd']); + } else if (name === "output-enabled-library-type") { + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "amd"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'amd'`); - } else if (name === 'output-hash-function') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'sha256']); + } else if (name === "output-hash-function") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "sha256", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`hashFunction: 'sha256'`); - } else if (name === 'output-script-type') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'module']); + } else if (name === "output-script-type") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "module", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'module'`); - } else if (name === 'output-enabled-library-types') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'var']); + } else if (name === "output-enabled-library-types") { + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "var"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: [ 'var' ]`); - } else if (name === 'output-path') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'test']); + } else if (name === "output-path") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "test", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('test'); - } else if (name === 'output-pathinfo') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'verbose']); + expect(stdout).toContain("test"); + } else if (name === "output-pathinfo") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "verbose", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`pathinfo: 'verbose'`); - } else if (name === 'output-worker-chunk-loading') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'async-node']); + } else if (name === "output-worker-chunk-loading") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "async-node", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'async-node'`); - } else if (name.includes('wasm')) { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'async-node']); + } else if (name.includes("wasm")) { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "async-node", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'async-node'`); - } else if (name.includes('trusted-types')) { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'test']); + } else if (name.includes("trusted-types")) { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "test", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`trustedTypes: { policyName: 'test' }`); } else { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'test']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "test", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -160,31 +208,35 @@ describe('output config related flag', () => { it(`should config name, type and export correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--output-library-name', - 'myLibrary', - '--output-library-type', - 'var', - '--output-library-export', - 'myExport', - '--output-library-auxiliary-comment', - 'comment', - '--output-library-umd-named-define', + "--output-library-name", + "myLibrary", + "--output-library-type", + "var", + "--output-library-export", + "myExport", + "--output-library-auxiliary-comment", + "comment", + "--output-library-umd-named-define", ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('myLibrary'); + expect(stdout).toContain("myLibrary"); expect(stdout).toContain(`type: 'var'`); - expect(stdout).toContain('export: [Array]'); + expect(stdout).toContain("export: [Array]"); expect(stdout).toContain(`auxiliaryComment: 'comment'`); - expect(stdout).toContain('umdNamedDefine: true'); + expect(stdout).toContain("umdNamedDefine: true"); }); - it('should be succesful with --output-library-reset correctly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--output-library-reset', '--output-library', 'newLibrary']); + it("should be succesful with --output-library-reset correctly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--output-library-reset", + "--output-library", + "newLibrary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('newLibrary'); + expect(stdout).toContain("newLibrary"); }); }); diff --git a/test/build/core-flags/parallelism-flag.test.js b/test/build/core-flags/parallelism-flag.test.js index 48c711a267b..cbf5017f25a 100644 --- a/test/build/core-flags/parallelism-flag.test.js +++ b/test/build/core-flags/parallelism-flag.test.js @@ -1,21 +1,21 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--parallelism flag', () => { - it('should set parallelism to the value passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--parallelism', '50']); +describe("--parallelism flag", () => { + it("should set parallelism to the value passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--parallelism", "50"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('parallelism: 50'); + expect(stdout).toContain("parallelism: 50"); }); - it('should throw error for invalid parallelism value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--parallelism', '0']); + it("should throw error for invalid parallelism value", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--parallelism", "0"]); expect(exitCode).toBe(2); - expect(stderr).toContain('configuration.parallelism should be >= 1'); + expect(stderr).toContain("configuration.parallelism should be >= 1"); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/core-flags/performance-flags.test.js b/test/build/core-flags/performance-flags.test.js index aec94cb16bf..129cdee0e4f 100644 --- a/test/build/core-flags/performance-flags.test.js +++ b/test/build/core-flags/performance-flags.test.js @@ -1,25 +1,25 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const performanceFlags = getWebpackCliArguments('performance-'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const performanceFlags = getWebpackCliArguments("performance-"); -describe('module config related flag', () => { +describe("module config related flag", () => { it(`should config --performance option correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-performance`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('performance: false'); + expect(stdout).toContain("performance: false"); }); for (const [name, value] of Object.entries(performanceFlags)) { // extract property name from flag name - const property = name.split('performance-')[1]; + const property = name.split("performance-")[1]; const propName = hyphenToUpperCase(property); - if (value.configs.filter((config) => config.type === 'number').length > 0) { + if (value.configs.filter((config) => config.type === "number").length > 0) { it(`should config --${name} correctly`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '10']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "10"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -27,9 +27,9 @@ describe('module config related flag', () => { }); } - if (value.configs.filter((config) => config.type === 'string').length > 0) { + if (value.configs.filter((config) => config.type === "string").length > 0) { it(`should config --${name} correctly`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'warning']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "warning"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/profile-flag.test.js b/test/build/core-flags/profile-flag.test.js index 84148ead247..516b82122b0 100644 --- a/test/build/core-flags/profile-flag.test.js +++ b/test/build/core-flags/profile-flag.test.js @@ -1,21 +1,21 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--profile flag', () => { - it('should set profile to true', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--profile']); +describe("--profile flag", () => { + it("should set profile to true", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--profile"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('profile: true'); + expect(stdout).toContain("profile: true"); }); - it('should set profile to false', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-profile']); + it("should set profile to false", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-profile"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('profile: false'); + expect(stdout).toContain("profile: false"); }); }); diff --git a/test/build/core-flags/records-flag.test.js b/test/build/core-flags/records-flag.test.js index 21d89336160..684f4199490 100644 --- a/test/build/core-flags/records-flag.test.js +++ b/test/build/core-flags/records-flag.test.js @@ -1,29 +1,38 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('module config related flag', () => { - it('should config records-path correctly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--records-path', './bin/records.json']); +describe("module config related flag", () => { + it("should config records-path correctly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--records-path", + "./bin/records.json", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('records.json'); + expect(stdout).toContain("records.json"); }); - it('should config records-input-path correctly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--records-input-path', './bin/records.json']); + it("should config records-input-path correctly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--records-input-path", + "./bin/records.json", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('records.json'); + expect(stdout).toContain("records.json"); }); - it('should config records-output-path correctly', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--records-output-path', './bin/records.json']); + it("should config records-output-path correctly", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--records-output-path", + "./bin/records.json", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('records.json'); + expect(stdout).toContain("records.json"); }); }); diff --git a/test/build/core-flags/resolve-flags.test.js b/test/build/core-flags/resolve-flags.test.js index 3b00780c830..0101f1a62c4 100644 --- a/test/build/core-flags/resolve-flags.test.js +++ b/test/build/core-flags/resolve-flags.test.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const resolveFlags = getWebpackCliArguments('resolve'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const resolveFlags = getWebpackCliArguments("resolve"); -describe('resolve config related flags', () => { +describe("resolve config related flags", () => { for (const [name, value] of Object.entries(resolveFlags)) { // extract property name from flag name - let property = name.split('resolve-')[1]; + let property = name.split("resolve-")[1]; - if (name.startsWith('resolve-loader')) { - property = name.split('resolve-loader-')[1]; + if (name.startsWith("resolve-loader")) { + property = name.split("resolve-loader-")[1]; } const propName = hyphenToUpperCase(property); if ( - value.configs.filter((config) => config.type === 'boolean').length > 0 && - !name.includes('alias-') && - !name.includes('fallback-') + value.configs.filter((config) => config.type === "boolean").length > 0 && + !name.includes("alias-") && + !name.includes("fallback-") ) { it(`should config --${name} correctly`, async () => { const { stderr, stdout } = await run(__dirname, [`--${name}`]); @@ -25,8 +25,8 @@ describe('resolve config related flags', () => { // expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name.includes('reset')) { - const option = propName.split('Reset')[0]; + if (name.includes("reset")) { + const option = propName.split("Reset")[0]; expect(stdout).toContain(`${option}: []`); } else { expect(stdout).toContain(`${propName}: true`); @@ -35,47 +35,47 @@ describe('resolve config related flags', () => { } if ( - value.configs.filter((config) => config.type === 'string').length > 0 && - !name.includes('alias-') && - !name.includes('fallback-') + value.configs.filter((config) => config.type === "string").length > 0 && + !name.includes("alias-") && + !name.includes("fallback-") ) { it(`should config --${name} correctly`, async () => { - const { stderr, stdout } = await run(__dirname, [`--${name}`, 'browser']); + const { stderr, stdout } = await run(__dirname, [`--${name}`, "browser"]); // expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (propName === 'restrictions') { - expect(stdout).toContain('browser'); + if (propName === "restrictions") { + expect(stdout).toContain("browser"); } else { expect(stdout).toContain(`${propName}: [ 'browser' ]`); } }); } - if (name.includes('alias-') || name.includes('fallback-')) { + if (name.includes("alias-") || name.includes("fallback-")) { it(`should config --${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ `--resolve-alias-alias`, - 'alias', - '--resolve-alias-name', - 'name', - '--resolve-alias-fields', - 'aliasField', - '--resolve-loader-alias-alias', - 'loaderAlias', - '--resolve-loader-alias-name', - 'loaderName', - '--resolve-loader-alias-fields', - 'loader-field', - '--resolve-fallback-alias', - 'fall-alias', - '--resolve-fallback-name', - 'fall-name', - '--resolve-loader-fallback-alias', - 'loader-fall-alias', - '--resolve-loader-fallback-name', - 'loader-fall-name', + "alias", + "--resolve-alias-name", + "name", + "--resolve-alias-fields", + "aliasField", + "--resolve-loader-alias-alias", + "loaderAlias", + "--resolve-loader-alias-name", + "loaderName", + "--resolve-loader-alias-fields", + "loader-field", + "--resolve-fallback-alias", + "fall-alias", + "--resolve-fallback-name", + "fall-name", + "--resolve-loader-fallback-alias", + "loader-fall-alias", + "--resolve-loader-fallback-name", + "loader-fall-name", ]); expect(exitCode).toBe(0); @@ -84,21 +84,21 @@ describe('resolve config related flags', () => { expect(stdout).toContain(`aliasFields: [ 'aliasField' ]`); expect(stdout).toContain(`alias: [ { alias: 'loaderAlias', name: 'loaderName' } ]`); expect(stdout).toContain(`aliasFields: [ 'loader-field' ]`); - expect(stdout).toContain('fall-name'); - expect(stdout).toContain('fall-alias'); - expect(stdout).toContain('loader-fall-name'); - expect(stdout).toContain('loader-fall-alias'); + expect(stdout).toContain("fall-name"); + expect(stdout).toContain("fall-alias"); + expect(stdout).toContain("loader-fall-name"); + expect(stdout).toContain("loader-fall-alias"); }); - if (name.includes('reset')) { + if (name.includes("reset")) { it(`should config --${name} alias-reset flags correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--resolve-alias-reset', - '--resolve-fallback-reset', - '--resolve-alias-fields-reset', - '--resolve-loader-alias-reset', - '--resolve-loader-alias-fields-reset', - '--resolve-loader-fallback-reset', + "--resolve-alias-reset", + "--resolve-fallback-reset", + "--resolve-alias-fields-reset", + "--resolve-loader-alias-reset", + "--resolve-loader-alias-fields-reset", + "--resolve-loader-fallback-reset", ]); expect(exitCode).toBe(0); diff --git a/test/build/core-flags/snapshot-flags.test.js b/test/build/core-flags/snapshot-flags.test.js index 44795b67699..68400f5bc59 100644 --- a/test/build/core-flags/snapshot-flags.test.js +++ b/test/build/core-flags/snapshot-flags.test.js @@ -1,39 +1,42 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const snapshotFlags = getWebpackCliArguments('snapshot'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const snapshotFlags = getWebpackCliArguments("snapshot"); -describe('snapshot config related flags', () => { +describe("snapshot config related flags", () => { for (const [name, value] of Object.entries(snapshotFlags)) { // extract property name from flag name - let property = name.split('snapshot-')[1]; + let property = name.split("snapshot-")[1]; const propName = hyphenToUpperCase(property); - if (value.configs.filter((config) => config.type === 'boolean').length > 0) { + if (value.configs.filter((config) => config.type === "boolean").length > 0) { it(`should config --${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name.includes('reset')) { - const option = propName.split('Reset')[0]; + if (name.includes("reset")) { + const option = propName.split("Reset")[0]; expect(stdout).toContain(`${option}: []`); - } else if (name.includes('timestamp')) { + } else if (name.includes("timestamp")) { expect(stdout).toContain(`timestamp: true`); - } else if (name.includes('hash')) { + } else if (name.includes("hash")) { expect(stdout).toContain(`hash: true`); } }); } - if (value.configs.filter((config) => config.type === 'string').length > 0) { + if (value.configs.filter((config) => config.type === "string").length > 0) { it(`should config --${name} correctly`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, './mock/mock.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "./mock/mock.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('./mock/mock.js'); + expect(stdout).toContain("./mock/mock.js"); }); } } diff --git a/test/build/core-flags/src/entry.js b/test/build/core-flags/src/entry.js index 944b40c99df..306235e5203 100644 --- a/test/build/core-flags/src/entry.js +++ b/test/build/core-flags/src/entry.js @@ -1 +1 @@ -console.log('another-entry'); +console.log("another-entry"); diff --git a/test/build/core-flags/src/main.js b/test/build/core-flags/src/main.js index dcab1dbfb46..61b567951ff 100644 --- a/test/build/core-flags/src/main.js +++ b/test/build/core-flags/src/main.js @@ -1 +1 @@ -console.log('core-flags tests'); +console.log("core-flags tests"); diff --git a/test/build/core-flags/stats-flags.test.js b/test/build/core-flags/stats-flags.test.js index 21b58777c5c..f4f47b6277f 100644 --- a/test/build/core-flags/stats-flags.test.js +++ b/test/build/core-flags/stats-flags.test.js @@ -1,30 +1,30 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const statsFlags = getWebpackCliArguments('stats-'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const statsFlags = getWebpackCliArguments("stats-"); -describe('stats config related flag', () => { +describe("stats config related flag", () => { for (const [name, value] of Object.entries(statsFlags)) { // extract property name from flag name - const property = name.split('stats-')[1]; + const property = name.split("stats-")[1]; const propName = hyphenToUpperCase(property); - if (value.configs.filter((config) => config.type === 'boolean').length > 0) { + if (value.configs.filter((config) => config.type === "boolean").length > 0) { it(`should config --${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name.includes('-reset')) { - const option = propName.split('Reset')[0]; + if (name.includes("-reset")) { + const option = propName.split("Reset")[0]; expect(stdout).toContain(`${option}: []`); } else { expect(stdout).toContain(`${propName}: true`); } }); - if (!name.endsWith('-reset')) { + if (!name.endsWith("-reset")) { it(`should config --no-${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-${name}`]); @@ -35,9 +35,9 @@ describe('stats config related flag', () => { } } - if (value.configs.filter((config) => config.type === 'number').length > 0) { + if (value.configs.filter((config) => config.type === "number").length > 0) { it(`should config --${name} correctly`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '10']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "10"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -45,37 +45,49 @@ describe('stats config related flag', () => { }); } - if (value.configs.filter((config) => config.type === 'string').length > 0) { - const acceptsSingleValue = ['preset', 'modulesSort', 'logging', 'chunksSort', 'assetsSort']; + if (value.configs.filter((config) => config.type === "string").length > 0) { + const acceptsSingleValue = [ + "preset", + "modulesSort", + "logging", + "chunksSort", + "assetsSort", + ]; it(`should config --${name} correctly`, async () => { - if (name.includes('stats-colors')) { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'u001b[32m']); - const option = name.split('stats-colors-')[1]; + if (name.includes("stats-colors")) { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "u001b[32m", + ]); + const option = name.split("stats-colors-")[1]; expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`colors: { ${option}: 'u001b[32m' }`); } else if (acceptsSingleValue.includes(propName)) { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'log']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "log"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'log'`); - } else if (name === 'stats-context') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'log']); + } else if (name === "stats-context") { + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "log"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('log'); - } else if (name === 'stats-entrypoints' || name === 'stats-error-details') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'auto']); + expect(stdout).toContain("log"); + } else if (name === "stats-entrypoints" || name === "stats-error-details") { + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "auto", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'auto'`); } else { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'log']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "log"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/watch-flags.test.js b/test/build/core-flags/watch-flags.test.js index 1f9c3959467..13095c01403 100644 --- a/test/build/core-flags/watch-flags.test.js +++ b/test/build/core-flags/watch-flags.test.js @@ -1,33 +1,36 @@ -'use strict'; +"use strict"; -const { run, hyphenToUpperCase, getWebpackCliArguments } = require('../../utils/test-utils'); -const watchFlags = getWebpackCliArguments('watch'); +const { run, hyphenToUpperCase, getWebpackCliArguments } = require("../../utils/test-utils"); +const watchFlags = getWebpackCliArguments("watch"); -describe('watch config related flag', () => { +describe("watch config related flag", () => { for (const [name, value] of Object.entries(watchFlags)) { // extract property name from flag name - const property = name.split('watch-options-')[1]; + const property = name.split("watch-options-")[1]; const propName = hyphenToUpperCase(property); - if (propName === 'stdin') { + if (propName === "stdin") { return; } - if (value.configs.filter((config) => config.type === 'boolean').length > 0 && name !== 'watch') { + if ( + value.configs.filter((config) => config.type === "boolean").length > 0 && + name !== "watch" + ) { it(`should config --${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - if (name.includes('reset')) { + if (name.includes("reset")) { expect(stdout).toContain(`watchOptions: { ignored: [] }`); } else { expect(stdout).toContain(`watchOptions: { ${propName}: true }`); } }); - if (!name.endsWith('-reset')) { + if (!name.endsWith("-reset")) { it(`should config --no-${name} correctly`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, [`--no-${name}`]); @@ -38,9 +41,9 @@ describe('watch config related flag', () => { } } - if (value.configs.filter((config) => config.type === 'number').length > 0) { + if (value.configs.filter((config) => config.type === "number").length > 0) { it(`should config --${name} correctly`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '10']); + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "10"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -48,16 +51,19 @@ describe('watch config related flag', () => { }); } - if (value.configs.filter((config) => config.type === 'string').length > 0) { + if (value.configs.filter((config) => config.type === "string").length > 0) { it(`should config --${name} correctly`, async () => { - if (propName === 'poll') { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, '200']); + if (propName === "poll") { + const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "200"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`watchOptions: { ${propName}: 200 }`); } else { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, 'ignore.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "ignore.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/webpack.cache.config.js b/test/build/core-flags/webpack.cache.config.js index c8f315b98ee..cfeed391a1e 100644 --- a/test/build/core-flags/webpack.cache.config.js +++ b/test/build/core-flags/webpack.cache.config.js @@ -1,12 +1,12 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); module.exports = { - entry: './src/main.js', - mode: 'development', + entry: "./src/main.js", + mode: "development", cache: { - type: 'filesystem', - name: 'config-cache', + type: "filesystem", + name: "config-cache", }, - name: 'compiler-cache', - plugins: [new WebpackCLITestPlugin(['cache'])], + name: "compiler-cache", + plugins: [new WebpackCLITestPlugin(["cache"])], }; diff --git a/test/build/core-flags/webpack.config.js b/test/build/core-flags/webpack.config.js index 44254055243..124ca164206 100644 --- a/test/build/core-flags/webpack.config.js +++ b/test/build/core-flags/webpack.config.js @@ -1,8 +1,8 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); module.exports = { - entry: './src/main.js', - mode: 'development', - name: 'compiler', - plugins: [new WebpackCLITestPlugin(['module', 'entry', 'resolve', 'resolveLoader', 'cache'])], + entry: "./src/main.js", + mode: "development", + name: "compiler", + plugins: [new WebpackCLITestPlugin(["module", "entry", "resolve", "resolveLoader", "cache"])], }; diff --git a/test/build/custom-webpack/custom-webpack.js b/test/build/custom-webpack/custom-webpack.js index dfe19cee008..898d4002902 100644 --- a/test/build/custom-webpack/custom-webpack.js +++ b/test/build/custom-webpack/custom-webpack.js @@ -1 +1 @@ -module.exports = require('webpack'); +module.exports = require("webpack"); diff --git a/test/build/custom-webpack/custom-webpack.test.js b/test/build/custom-webpack/custom-webpack.test.js index ec57011ef31..92c8bd922de 100644 --- a/test/build/custom-webpack/custom-webpack.test.js +++ b/test/build/custom-webpack/custom-webpack.test.js @@ -1,22 +1,24 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run } = require('../../utils/test-utils'); +const { resolve } = require("path"); +const { run } = require("../../utils/test-utils"); -describe('custom-webpack', () => { - it('should use custom-webpack.js', async () => { +describe("custom-webpack", () => { + it("should use custom-webpack.js", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [], { - env: { WEBPACK_PACKAGE: resolve(__dirname, './custom-webpack.js') }, + env: { WEBPACK_PACKAGE: resolve(__dirname, "./custom-webpack.js") }, }); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); - it('should throw an error for invalid-webpack.js', async () => { + it("should throw an error for invalid-webpack.js", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [], { - env: { WEBPACK_PACKAGE: resolve(__dirname, './invalid-webpack.js') }, + env: { + WEBPACK_PACKAGE: resolve(__dirname, "./invalid-webpack.js"), + }, }); expect(exitCode).toBe(2); diff --git a/test/build/custom-webpack/webpack.config.js b/test/build/custom-webpack/webpack.config.js index 5b69c702150..529ce401c0c 100644 --- a/test/build/custom-webpack/webpack.config.js +++ b/test/build/custom-webpack/webpack.config.js @@ -1,3 +1,3 @@ module.exports = { - mode: 'production', + mode: "production", }; diff --git a/test/build/defaults/a.js b/test/build/defaults/a.js index 51aa40ce33d..f4bee164a97 100644 --- a/test/build/defaults/a.js +++ b/test/build/defaults/a.js @@ -1 +1 @@ -module.export = 'output-flag-test'; +module.export = "output-flag-test"; diff --git a/test/build/defaults/output-defaults.test.js b/test/build/defaults/output-defaults.test.js index 1d8afe1ea7c..f4f2bff82b3 100644 --- a/test/build/defaults/output-defaults.test.js +++ b/test/build/defaults/output-defaults.test.js @@ -1,32 +1,41 @@ -'use strict'; +"use strict"; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../utils/test-utils'); +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run } = require("../../utils/test-utils"); -describe('output flag defaults', () => { - it('should create default file for a given directory', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', './a.js', '--output-path', './binary']); +describe("output flag defaults", () => { + it("should create default file for a given directory", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry", + "./a.js", + "--output-path", + "./binary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); // Should print warning about config fallback - expect(stdout).toContain('option has not been set, webpack will fallback to'); + expect(stdout).toContain("option has not been set, webpack will fallback to"); - expect(existsSync(resolve(__dirname, './binary/main.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/main.js"))).toBeTruthy(); }); - it('set default output directory on no output flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', './a.js']); + it("set default output directory on no output flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--entry", "./a.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './binary/main.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./binary/main.js"))).toBeTruthy(); }); - it('throw error on empty output flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', './a.js', '--output-path']); + it("throw error on empty output flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry", + "./a.js", + "--output-path", + ]); expect(exitCode).toBe(2); expect(stderr).toContain("Error: Option '-o, --output-path ' argument missing"); diff --git a/test/build/devtool/array/source-map-array.test.js b/test/build/devtool/array/source-map-array.test.js index c15d94c0b5f..ee45e79dd06 100644 --- a/test/build/devtool/array/source-map-array.test.js +++ b/test/build/devtool/array/source-map-array.test.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run, readdir } = require('../../../utils/test-utils'); +const { resolve } = require("path"); +const { run, readdir } = require("../../../utils/test-utils"); -describe('source-map object', () => { - it('should treat source-map settings right', async () => { +describe("source-map object", () => { + it("should treat source-map settings right", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); @@ -16,7 +16,7 @@ describe('source-map object', () => { let files; try { - files = await readdir(resolve(__dirname, 'dist')); + files = await readdir(resolve(__dirname, "dist")); } catch (error) { expect(error).toBe(null); } @@ -24,8 +24,13 @@ describe('source-map object', () => { expect(files.length).toBe(3); }); - it('should override entire array on flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--devtool', 'source-map', '--output-path', './binary']); + it("should override entire array on flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--devtool", + "source-map", + "--output-path", + "./binary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -34,7 +39,7 @@ describe('source-map object', () => { let files; try { - files = await readdir(resolve(__dirname, 'binary')); + files = await readdir(resolve(__dirname, "binary")); } catch (error) { expect(error).toBe(null); } diff --git a/test/build/devtool/array/webpack.config.js b/test/build/devtool/array/webpack.config.js index b43cebaa257..8e8d0582195 100644 --- a/test/build/devtool/array/webpack.config.js +++ b/test/build/devtool/array/webpack.config.js @@ -1,27 +1,27 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = [ { output: { - filename: './dist-amd.js', - libraryTarget: 'amd', + filename: "./dist-amd.js", + libraryTarget: "amd", }, - name: 'amd', - entry: './index.js', - mode: 'development', - devtool: 'eval-cheap-module-source-map', + name: "amd", + entry: "./index.js", + mode: "development", + devtool: "eval-cheap-module-source-map", plugins: [new WebpackCLITestPlugin()], }, { output: { - filename: './dist-commonjs.js', - libraryTarget: 'commonjs', + filename: "./dist-commonjs.js", + libraryTarget: "commonjs", }, - name: 'commonjs', - entry: './index.js', - mode: 'development', - devtool: 'source-map', - target: 'node', + name: "commonjs", + entry: "./index.js", + mode: "development", + devtool: "source-map", + target: "node", plugins: [new WebpackCLITestPlugin()], }, ]; diff --git a/test/build/devtool/object/source-map-object.test.js b/test/build/devtool/object/source-map-object.test.js index 33caeb866ee..77be45d52ac 100644 --- a/test/build/devtool/object/source-map-object.test.js +++ b/test/build/devtool/object/source-map-object.test.js @@ -1,11 +1,14 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run, readdir } = require('../../../utils/test-utils'); +"use strict"; +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const { run, readdir } = require("../../../utils/test-utils"); -describe('source-map object', () => { - it('should not write a source map for obj config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.eval.config.js']); +describe("source-map object", () => { + it("should not write a source map for obj config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.eval.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -14,7 +17,7 @@ describe('source-map object', () => { let files; try { - files = await readdir(resolve(__dirname, 'dist')); + files = await readdir(resolve(__dirname, "dist")); } catch (error) { expect(error).toBe(null); } @@ -22,38 +25,41 @@ describe('source-map object', () => { expect(files.length).toBeGreaterThanOrEqual(1); }); - it('should write a sourcemap file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.source.config.js']); + it("should write a sourcemap file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.source.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("devtool: 'source-map'"); - expect(existsSync(resolve(__dirname, 'dist/dist-amd.js.map'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "dist/dist-amd.js.map"))).toBeTruthy(); }); - it('should override config with source-map', async () => { + it("should override config with source-map", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['-c', './webpack.eval.config.js', '--devtool', 'source-map', '-o', './binary'], + ["-c", "./webpack.eval.config.js", "--devtool", "source-map", "-o", "./binary"], false, ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain("devtool: 'source-map'"); - expect(existsSync(resolve(__dirname, 'binary/dist-amd.js.map'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "binary/dist-amd.js.map"))).toBeTruthy(); }); - it('should override config with devtool false', async () => { + it("should override config with devtool false", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['-c', './webpack.eval.config.js', '--no-devtool', '-o', './binary'], + ["-c", "./webpack.eval.config.js", "--no-devtool", "-o", "./binary"], false, ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('devtool: false'); - expect(existsSync(resolve(__dirname, 'binary/dist-amd.js.map'))).toBeTruthy(); + expect(stdout).toContain("devtool: false"); + expect(existsSync(resolve(__dirname, "binary/dist-amd.js.map"))).toBeTruthy(); }); }); diff --git a/test/build/devtool/object/webpack.eval.config.js b/test/build/devtool/object/webpack.eval.config.js index 7c2bec6f0d6..39643fefd9f 100644 --- a/test/build/devtool/object/webpack.eval.config.js +++ b/test/build/devtool/object/webpack.eval.config.js @@ -1,13 +1,13 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { output: { - filename: './dist-amd.js', - libraryTarget: 'amd', + filename: "./dist-amd.js", + libraryTarget: "amd", }, - name: 'amd', - entry: './index.js', - mode: 'development', - devtool: 'eval-cheap-module-source-map', + name: "amd", + entry: "./index.js", + mode: "development", + devtool: "eval-cheap-module-source-map", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/devtool/object/webpack.source.config.js b/test/build/devtool/object/webpack.source.config.js index efb87fa2f90..2972b444959 100644 --- a/test/build/devtool/object/webpack.source.config.js +++ b/test/build/devtool/object/webpack.source.config.js @@ -1,13 +1,13 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { output: { - filename: './dist-amd.js', - libraryTarget: 'amd', + filename: "./dist-amd.js", + libraryTarget: "amd", }, - name: 'amd', - entry: './index.js', - mode: 'development', - devtool: 'source-map', + name: "amd", + entry: "./index.js", + mode: "development", + devtool: "source-map", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/entry/config-entry/1.js b/test/build/entry/config-entry/1.js index f14be438871..fd01d9ae015 100644 --- a/test/build/entry/config-entry/1.js +++ b/test/build/entry/config-entry/1.js @@ -1,11 +1,11 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { entry: { - index: '../a.js', + index: "../a.js", }, output: { - path: resolve(process.cwd(), 'binary'), - filename: '[name].bundle.js', + path: resolve(process.cwd(), "binary"), + filename: "[name].bundle.js", }, }; diff --git a/test/build/entry/config-entry/entry-with-config/entry-with-config.test.js b/test/build/entry/config-entry/entry-with-config/entry-with-config.test.js index ebf897aee24..c63e2723bf9 100644 --- a/test/build/entry/config-entry/entry-with-config/entry-with-config.test.js +++ b/test/build/entry/config-entry/entry-with-config/entry-with-config.test.js @@ -1,15 +1,15 @@ -'use strict'; -const { existsSync } = require('fs'); -const { resolve } = require('path'); -const { run } = require('../../../../utils/test-utils'); +"use strict"; +const { existsSync } = 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', async () => { - const { stdout, stderr, exitCode } = await run(__dirname, ['-c', '../1.js']); +describe("default entry and config entry all exist", () => { + it("should use config entry if config entry existed", async () => { + const { stdout, stderr, exitCode } = await run(__dirname, ["-c", "../1.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('./a.js'); - expect(existsSync(resolve(__dirname, './binary/index.bundle.js'))).toBeTruthy(); + expect(stdout).toContain("./a.js"); + expect(existsSync(resolve(__dirname, "./binary/index.bundle.js"))).toBeTruthy(); }); }); diff --git a/test/build/entry/config-entry/entry-with-index/entry-with-config.test.js b/test/build/entry/config-entry/entry-with-index/entry-with-config.test.js index 685486c05be..b4de568e1e0 100644 --- a/test/build/entry/config-entry/entry-with-index/entry-with-config.test.js +++ b/test/build/entry/config-entry/entry-with-index/entry-with-config.test.js @@ -1,20 +1,20 @@ -'use strict'; +"use strict"; -const { run } = require('../../../../utils/test-utils'); +const { run } = require("../../../../utils/test-utils"); -describe('default entry and config entry all exist', () => { - it('should use config entry if config entry existed', async () => { +describe("default entry and config entry all exist", () => { + it("should use config entry if config entry existed", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); // Should contain the relevant entry - expect(stdout).toContain('./src/app.js'); - expect(stdout).toContain('./src/print.js'); + expect(stdout).toContain("./src/app.js"); + expect(stdout).toContain("./src/print.js"); // Should contain the relevant bundle - expect(stdout).toContain('app.bundle.js'); - expect(stdout).toContain('print.bundle.js'); - expect(stdout).not.toContain('index.js'); + expect(stdout).toContain("app.bundle.js"); + expect(stdout).toContain("print.bundle.js"); + expect(stdout).not.toContain("index.js"); }); }); diff --git a/test/build/entry/config-entry/entry-with-index/src/app.js b/test/build/entry/config-entry/entry-with-index/src/app.js index 071620eafba..702645f13de 100644 --- a/test/build/entry/config-entry/entry-with-index/src/app.js +++ b/test/build/entry/config-entry/entry-with-index/src/app.js @@ -1 +1 @@ -console.log('app'); +console.log("app"); diff --git a/test/build/entry/config-entry/entry-with-index/src/print.js b/test/build/entry/config-entry/entry-with-index/src/print.js index 3c34c1ca320..c27e5ca9466 100644 --- a/test/build/entry/config-entry/entry-with-index/src/print.js +++ b/test/build/entry/config-entry/entry-with-index/src/print.js @@ -1 +1 @@ -console.log('print'); +console.log("print"); diff --git a/test/build/entry/config-entry/entry-with-index/webpack.config.js b/test/build/entry/config-entry/entry-with-index/webpack.config.js index 5c48520f84b..daa57e5a211 100644 --- a/test/build/entry/config-entry/entry-with-index/webpack.config.js +++ b/test/build/entry/config-entry/entry-with-index/webpack.config.js @@ -1,13 +1,13 @@ -const path = require('path'); +const path = require("path"); module.exports = { - mode: 'development', + mode: "development", entry: { - app: './src/app.js', - print: './src/print.js', + app: "./src/app.js", + print: "./src/print.js", }, output: { - filename: '[name].bundle.js', - path: path.resolve(__dirname, 'dist'), + filename: "[name].bundle.js", + path: path.resolve(__dirname, "dist"), }, }; diff --git a/test/build/entry/defaults-empty/entry-single-arg.test.js b/test/build/entry/defaults-empty/entry-single-arg.test.js index a4c944ff67a..0d4deab2e67 100644 --- a/test/build/entry/defaults-empty/entry-single-arg.test.js +++ b/test/build/entry/defaults-empty/entry-single-arg.test.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('single entry flag empty project', () => { - it('sets default entry, compiles but throw missing module error', async () => { +describe("single entry flag empty project", () => { + it("sets default entry, compiles but throw missing module error", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(1); diff --git a/test/build/entry/defaults-index/entry-multi-args.test.js b/test/build/entry/defaults-index/entry-multi-args.test.js index b99ecd35aad..eab4821ffd7 100644 --- a/test/build/entry/defaults-index/entry-multi-args.test.js +++ b/test/build/entry/defaults-index/entry-multi-args.test.js @@ -1,26 +1,26 @@ -'use strict'; +"use strict"; -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('single entry flag index present', () => { - it('finds default index file and compiles successfully', async () => { +describe("single entry flag index present", () => { + it("finds default index file and compiles successfully", async () => { const { stderr, stdout, exitCode } = await run(__dirname); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stderr).not.toContain('Module not found'); + expect(stderr).not.toContain("Module not found"); expect(stdout).toBeTruthy(); }); - it('finds default index file, compiles and overrides with flags successfully', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--output-path', 'bin']); + it("finds default index file, compiles and overrides with flags successfully", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--output-path", "bin"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './bin/main.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./bin/main.js"))).toBeTruthy(); }); }); diff --git a/test/build/entry/flag-entry/entry-with-flag.test.js b/test/build/entry/flag-entry/entry-with-flag.test.js index 0a75a5d3dad..aea0411bb0f 100644 --- a/test/build/entry/flag-entry/entry-with-flag.test.js +++ b/test/build/entry/flag-entry/entry-with-flag.test.js @@ -1,46 +1,51 @@ -'use strict'; +"use strict"; -const { run, readFile } = require('../../../utils/test-utils'); -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { run, readFile } = require("../../../utils/test-utils"); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -describe('entry flag', () => { - it('should resolve the path to src/index.cjs', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', './src/index.cjs', '-o', './dist/']); +describe("entry flag", () => { + it("should resolve the path to src/index.cjs", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry", + "./src/index.cjs", + "-o", + "./dist/", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should load ./src/a.js as entry', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', './src/a.js']); + it("should load ./src/a.js as entry", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--entry", "./src/a.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should resolve the path to /src/a.js as ./src/a.js', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', '/src/a.js']); + it("should resolve the path to /src/a.js as ./src/a.js", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--entry", "/src/a.js"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/main.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/main.js"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, './dist/main.js'), 'utf-8'); + data = await readFile(resolve(__dirname, "./dist/main.js"), "utf-8"); } catch (error) { expect(error).toBe(null); } - expect(data).toContain('Hello from a.js'); + expect(data).toContain("Hello from a.js"); }); - it('should throw error for invalid entry file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', './src/test.js']); + it("should throw error for invalid entry file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--entry", "./src/test.js"]); expect(exitCode).toEqual(1); expect(stderr).toBeFalsy(); diff --git a/test/build/entry/flag-entry/src/a.js b/test/build/entry/flag-entry/src/a.js index 5b4dd8b52eb..8a700c3d098 100644 --- a/test/build/entry/flag-entry/src/a.js +++ b/test/build/entry/flag-entry/src/a.js @@ -1 +1 @@ -console.log('Hello from a.js'); +console.log("Hello from a.js"); diff --git a/test/build/entry/flag-entry/src/index.cjs b/test/build/entry/flag-entry/src/index.cjs index f96f188d697..a741ab3334d 100644 --- a/test/build/entry/flag-entry/src/index.cjs +++ b/test/build/entry/flag-entry/src/index.cjs @@ -1 +1 @@ -console.log('Kazuya Miyuki'); +console.log("Kazuya Miyuki"); diff --git a/test/build/entry/multiple-entries/multi-entries.test.js b/test/build/entry/multiple-entries/multi-entries.test.js index 5d70b2666c0..cbf765751ee 100644 --- a/test/build/entry/multiple-entries/multi-entries.test.js +++ b/test/build/entry/multiple-entries/multi-entries.test.js @@ -1,27 +1,32 @@ -'use strict'; +"use strict"; -const { run, readFile } = require('../../../utils/test-utils'); -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { run, readFile } = require("../../../utils/test-utils"); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -describe(' multiple entries', () => { - it('should allow multiple entry flags', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entry', './src/a.js', '--entry', './src/b.js']); +describe(" multiple entries", () => { + it("should allow multiple entry flags", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry", + "./src/a.js", + "--entry", + "./src/b.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - expect(existsSync(resolve(__dirname, './dist/main.js'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./dist/main.js"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, './dist/main.js'), 'utf-8'); + data = await readFile(resolve(__dirname, "./dist/main.js"), "utf-8"); } catch (error) { expect(error).toBe(null); } - expect(data).toContain('Hello from a.js'); - expect(data).toContain('Hello from b.js'); + expect(data).toContain("Hello from a.js"); + expect(data).toContain("Hello from b.js"); }); }); diff --git a/test/build/entry/multiple-entries/src/a.js b/test/build/entry/multiple-entries/src/a.js index 5b4dd8b52eb..8a700c3d098 100644 --- a/test/build/entry/multiple-entries/src/a.js +++ b/test/build/entry/multiple-entries/src/a.js @@ -1 +1 @@ -console.log('Hello from a.js'); +console.log("Hello from a.js"); diff --git a/test/build/entry/multiple-entries/src/b.js b/test/build/entry/multiple-entries/src/b.js index 4eb2d45c855..a5cc96f74cb 100644 --- a/test/build/entry/multiple-entries/src/b.js +++ b/test/build/entry/multiple-entries/src/b.js @@ -1 +1 @@ -console.log('Hello from b.js'); +console.log("Hello from b.js"); diff --git a/test/build/entry/multiple-entries/src/c.js b/test/build/entry/multiple-entries/src/c.js index 68ea4af8491..ae96e42b67a 100644 --- a/test/build/entry/multiple-entries/src/c.js +++ b/test/build/entry/multiple-entries/src/c.js @@ -1 +1 @@ -console.log('Hello from c.js'); +console.log("Hello from c.js"); diff --git a/test/build/entry/scss/home.js b/test/build/entry/scss/home.js index 2c794ff0941..4d24d7f91ca 100644 --- a/test/build/entry/scss/home.js +++ b/test/build/entry/scss/home.js @@ -1 +1 @@ -console.log('home'); +console.log("home"); diff --git a/test/build/entry/scss/scss.test.js b/test/build/entry/scss/scss.test.js index c5406962f6f..52f609c136a 100644 --- a/test/build/entry/scss/scss.test.js +++ b/test/build/entry/scss/scss.test.js @@ -1,12 +1,12 @@ /* eslint-disable node/no-unpublished-require */ -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('entry point', () => { - it('should support SCSS files', async () => { +describe("entry point", () => { + it("should support SCSS files", async () => { const { stdout } = await run(__dirname); expect(stdout).toBeTruthy(); - expect(stdout).toContain('home.scss'); - expect(stdout).toContain('home.js'); + expect(stdout).toContain("home.scss"); + expect(stdout).toContain("home.js"); }); }); diff --git a/test/build/entry/scss/webpack.config.js b/test/build/entry/scss/webpack.config.js index 5f80bebe789..265ae5f8c31 100644 --- a/test/build/entry/scss/webpack.config.js +++ b/test/build/entry/scss/webpack.config.js @@ -1,13 +1,13 @@ // eslint-disable-next-line node/no-missing-require -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); module.exports = { - mode: 'development', + mode: "development", entry: { - home: ['./home.js', './home.scss'], + home: ["./home.js", "./home.scss"], }, output: { - filename: '[name].js', + filename: "[name].js", }, module: { rules: [ @@ -16,15 +16,15 @@ module.exports = { use: [ // fallback to style-loader in development MiniCssExtractPlugin.loader, - 'css-loader', - 'sass-loader', + "css-loader", + "sass-loader", ], }, ], }, plugins: [ new MiniCssExtractPlugin({ - filename: '[name].css', + filename: "[name].css", }), ], }; diff --git a/test/build/env/array/array-env.test.js b/test/build/env/array/array-env.test.js index 17c94642010..78e47247b77 100644 --- a/test/build/env/array/array-env.test.js +++ b/test/build/env/array/array-env.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const execa = require('execa'); +const execa = require("execa"); const { sync: spawnSync } = execa; -const { run, isWebpack5 } = require('../../../utils/test-utils'); +const { run, isWebpack5 } = require("../../../utils/test-utils"); -const devFile = path.join(__dirname, './dist/dev.js'); -const prodFile = path.join(__dirname, './dist/prod.js'); +const devFile = path.join(__dirname, "./dist/dev.js"); +const prodFile = path.join(__dirname, "./dist/prod.js"); -describe('env array', () => { - it('is able to set two different environments for an array configuration', async () => { +describe("env array", () => { + it("is able to set two different environments for an array configuration", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(0); @@ -19,11 +19,11 @@ describe('env array', () => { expect(stdout).toBeTruthy(); if (isWebpack5) { - const devScript = spawnSync('node', [devFile]); - const prodScript = spawnSync('node', [prodFile]); + const devScript = spawnSync("node", [devFile]); + const prodScript = spawnSync("node", [prodFile]); - expect(devScript.stdout).toBe('environment is development'); - expect(prodScript.stdout).toBe('environment is production'); + expect(devScript.stdout).toBe("environment is development"); + expect(prodScript.stdout).toBe("environment is production"); } }); }); diff --git a/test/build/env/array/webpack.config.js b/test/build/env/array/webpack.config.js index ec67e7da042..0e907ca83c0 100644 --- a/test/build/env/array/webpack.config.js +++ b/test/build/env/array/webpack.config.js @@ -1,13 +1,13 @@ -const webpack = require('webpack'); +const webpack = require("webpack"); module.exports = [ { output: { - filename: 'prod.js', + filename: "prod.js", }, - mode: 'production', - devtool: 'eval-cheap-module-source-map', - target: 'node', + mode: "production", + devtool: "eval-cheap-module-source-map", + target: "node", plugins: [ new webpack.DefinePlugin({ PRODUCTION: JSON.stringify(true), @@ -16,10 +16,10 @@ module.exports = [ }, { output: { - filename: 'dev.js', + filename: "dev.js", }, - mode: 'development', - target: 'node', + mode: "development", + target: "node", plugins: [ new webpack.DefinePlugin({ PRODUCTION: JSON.stringify(false), diff --git a/test/build/env/object/object-env.test.js b/test/build/env/object/object-env.test.js index cb100ee74fd..0a66e50fad5 100644 --- a/test/build/env/object/object-env.test.js +++ b/test/build/env/object/object-env.test.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const execa = require('execa'); +const execa = require("execa"); const { sync: spawnSync } = execa; -const { run, isWebpack5 } = require('../../../utils/test-utils'); +const { run, isWebpack5 } = require("../../../utils/test-utils"); -describe('env object', () => { - it('is able to set env for an object', async () => { +describe("env object", () => { + it("is able to set env for an object", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(0); @@ -16,9 +16,9 @@ describe('env object', () => { expect(stdout).toBeTruthy(); if (isWebpack5) { - const executable = path.join(__dirname, './dist/main.js'); - const bundledScript = spawnSync('node', [executable]); - expect(bundledScript.stdout).toBe('environment is development'); + const executable = path.join(__dirname, "./dist/main.js"); + const bundledScript = spawnSync("node", [executable]); + expect(bundledScript.stdout).toBe("environment is development"); } }); }); diff --git a/test/build/env/object/webpack.config.js b/test/build/env/object/webpack.config.js index 6298db87f9d..84e75adab17 100644 --- a/test/build/env/object/webpack.config.js +++ b/test/build/env/object/webpack.config.js @@ -1,9 +1,9 @@ -const webpack = require('webpack'); +const webpack = require("webpack"); module.exports = { - mode: 'development', - devtool: 'eval-cheap-module-source-map', - target: 'node', + mode: "development", + devtool: "eval-cheap-module-source-map", + target: "node", plugins: [ new webpack.DefinePlugin({ PRODUCTION: JSON.stringify(false), diff --git a/test/build/error/error-in-plugin/error.test.js b/test/build/error/error-in-plugin/error.test.js index 97233904e9c..e8951f69201 100644 --- a/test/build/error/error-in-plugin/error.test.js +++ b/test/build/error/error-in-plugin/error.test.js @@ -1,31 +1,31 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('error', () => { - it('should log error with stacktrace', async () => { +describe("error", () => { + it("should log error with stacktrace", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(2); - expect(stderr).toContain('Error: test'); + expect(stderr).toContain("Error: test"); expect(stderr).toMatch(/at .+ (.+)/); expect(stdout).toBeFalsy(); }); it('should log error with stacktrace using the "bundle" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle']); + const { exitCode, stderr, stdout } = await run(__dirname, ["bundle"]); expect(exitCode).toBe(2); - expect(stderr).toContain('Error: test'); + expect(stderr).toContain("Error: test"); expect(stderr).toMatch(/at .+ (.+)/); expect(stdout).toBeFalsy(); }); it('should log error with stacktrace using the "serve" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve']); + const { exitCode, stderr, stdout } = await run(__dirname, ["serve"]); expect(exitCode).toBe(2); - expect(stderr).toContain('Error: test'); + expect(stderr).toContain("Error: test"); expect(stderr).toMatch(/at .+ (.+)/); expect(stdout).toBeFalsy(); }); diff --git a/test/build/error/error-in-plugin/webpack.config.js b/test/build/error/error-in-plugin/webpack.config.js index 25018a41285..ce907f08a78 100644 --- a/test/build/error/error-in-plugin/webpack.config.js +++ b/test/build/error/error-in-plugin/webpack.config.js @@ -2,7 +2,7 @@ module.exports = { plugins: [ { apply() { - throw new Error('test'); + throw new Error("test"); }, }, ], diff --git a/test/build/error/invalid-schema/invalid-schema.test.js b/test/build/error/invalid-schema/invalid-schema.test.js index f54291cb7be..de901331213 100644 --- a/test/build/error/invalid-schema/invalid-schema.test.js +++ b/test/build/error/invalid-schema/invalid-schema.test.js @@ -1,41 +1,55 @@ -'use strict'; -const { run, isWebpack5 } = require('../../../utils/test-utils'); +"use strict"; +const { run, isWebpack5 } = require("../../../utils/test-utils"); -describe('invalid schema', () => { - it('should log error on invalid config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './webpack.mock.config.js']); +describe("invalid schema", () => { + it("should log error on invalid config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./webpack.mock.config.js", + ]); expect(exitCode).toEqual(2); - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); expect(stdout).toBeFalsy(); }); - it('should log error on invalid plugin options', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './webpack.plugin-mock.config.js']); + it("should log error on invalid plugin options", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./webpack.plugin-mock.config.js", + ]); expect(exitCode).toEqual(2); - expect(stderr).toContain(isWebpack5 ? 'Invalid options object' : 'Invalid Options'); + expect(stderr).toContain(isWebpack5 ? "Invalid options object" : "Invalid Options"); expect(stdout).toBeFalsy(); }); it('should log error on invalid config using the "bundle" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', '--config', './webpack.mock.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "bundle", + "--config", + "./webpack.mock.config.js", + ]); expect(exitCode).toEqual(2); - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); expect(stdout).toBeFalsy(); }); it('should log error on invalid config using the "serve" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--config', './webpack.mock.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "serve", + "--config", + "./webpack.mock.config.js", + ]); expect(exitCode).toEqual(2); - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); expect(stdout).toBeFalsy(); }); - it('should log error on invalid option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'Yukihira']); + it("should log error on invalid option", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -43,14 +57,14 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); }); it('should log error on invalid option using "build" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['build', '--mode', 'Yukihira']); + const { exitCode, stderr, stdout } = await run(__dirname, ["build", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -58,14 +72,14 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); }); it('should log error on invalid option using "bundle" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', '--mode', 'Yukihira']); + const { exitCode, stderr, stdout } = await run(__dirname, ["bundle", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -73,14 +87,14 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); }); it('should log error on invalid option using "b" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['b', '--mode', 'Yukihira']); + const { exitCode, stderr, stdout } = await run(__dirname, ["b", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -88,14 +102,14 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); }); it('should log error on invalid option using "watch" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['watch', '--mode', 'Yukihira']); + const { exitCode, stderr, stdout } = await run(__dirname, ["watch", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -103,14 +117,14 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); }); it('should log error on invalid option using "w" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['w', '--mode', 'Yukihira']); + const { exitCode, stderr, stdout } = await run(__dirname, ["w", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -118,14 +132,14 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); }); it('should log error on invalid option using "server" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--mode', 'Yukihira']); + const { exitCode, stderr, stdout } = await run(__dirname, ["serve", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -133,14 +147,14 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); }); it('should log error on invalid option using "s" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['s', '--mode', 'Yukihira']); + const { exitCode, stderr, stdout } = await run(__dirname, ["s", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); @@ -148,7 +162,7 @@ describe('invalid schema', () => { expect(stderr).toContain("Invalid value 'Yukihira' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain("Invalid configuration object"); } expect(stdout).toBeFalsy(); diff --git a/test/build/error/invalid-schema/webpack.mock.config.js b/test/build/error/invalid-schema/webpack.mock.config.js index f6d8ff0ce80..d436ef9ecc5 100644 --- a/test/build/error/invalid-schema/webpack.mock.config.js +++ b/test/build/error/invalid-schema/webpack.mock.config.js @@ -1,3 +1,3 @@ module.exports = { - mode: 'Nishinoya Yuu', + mode: "Nishinoya Yuu", }; diff --git a/test/build/error/invalid-schema/webpack.plugin-mock.config.js b/test/build/error/invalid-schema/webpack.plugin-mock.config.js index 24a228b9d92..0505173c867 100644 --- a/test/build/error/invalid-schema/webpack.plugin-mock.config.js +++ b/test/build/error/invalid-schema/webpack.plugin-mock.config.js @@ -1,10 +1,10 @@ -const webpack = require('webpack'); +const webpack = require("webpack"); module.exports = { - mode: 'development', + mode: "development", plugins: [ new webpack.BannerPlugin({ - unknown: 'unknown', + unknown: "unknown", }), ], }; diff --git a/test/build/hot/hot-flag.test.js b/test/build/hot/hot-flag.test.js index 2ada45b259d..877973de9a5 100644 --- a/test/build/hot/hot-flag.test.js +++ b/test/build/hot/hot-flag.test.js @@ -1,41 +1,47 @@ -'use strict'; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); -const { readFileSync } = require('fs'); -const { resolve } = require('path'); +"use strict"; +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); +const { readFileSync } = require("fs"); +const { resolve } = require("path"); -describe('--hot flag', () => { - it('should be successful when --hot is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--hot']); +describe("--hot flag", () => { + it("should be successful when --hot is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--hot"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); expect(stdout).toBeTruthy(); - expect(readFileSync(resolve(__dirname, './dist/main.js')).toString()).toContain('webpackHotUpdate'); + expect(readFileSync(resolve(__dirname, "./dist/main.js")).toString()).toContain( + "webpackHotUpdate", + ); }); - it('should be successful when --hot=only is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--hot', 'only']); + it("should be successful when --hot=only is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--hot", "only"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); expect(stdout).toBeTruthy(); - expect(readFileSync(resolve(__dirname, './dist/main.js')).toString()).toContain('webpackHotUpdate'); + expect(readFileSync(resolve(__dirname, "./dist/main.js")).toString()).toContain( + "webpackHotUpdate", + ); }); - it('should throw an error for invalid value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--hot', 'unknown']); + it("should throw an error for invalid value", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--hot", "unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should be successful when --no-hot is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-hot']); + it("should be successful when --no-hot is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-hot"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); expect(stdout).toBeTruthy(); - expect(readFileSync(resolve(__dirname, './dist/main.js')).toString()).not.toContain('webpackHotUpdate'); + expect(readFileSync(resolve(__dirname, "./dist/main.js")).toString()).not.toContain( + "webpackHotUpdate", + ); }); }); diff --git a/test/build/hot/webpack.config.js b/test/build/hot/webpack.config.js index 37c48e745b2..8bac08756f3 100644 --- a/test/build/hot/webpack.config.js +++ b/test/build/hot/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { - mode: 'development', - stats: 'verbose', + mode: "development", + stats: "verbose", }; diff --git a/test/build/import-local/import-local.test.js b/test/build/import-local/import-local.test.js index 06536e7173a..37d1d110478 100644 --- a/test/build/import-local/import-local.test.js +++ b/test/build/import-local/import-local.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); const importLocalMock = jest.fn(); -jest.setMock('import-local', importLocalMock); +jest.setMock("import-local", importLocalMock); -describe('import local', () => { +describe("import local", () => { beforeEach(() => { importLocalMock.mockClear(); }); - it('should skip import local when supplied', async () => { + it("should skip import local when supplied", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [], { env: { WEBPACK_CLI_SKIP_IMPORT_LOCAL: true }, }); diff --git a/test/build/json/json.test.js b/test/build/json/json.test.js index f45d86e96b3..37294945fb6 100644 --- a/test/build/json/json.test.js +++ b/test/build/json/json.test.js @@ -1,160 +1,181 @@ -'use strict'; +"use strict"; -const { run, readFile } = require('../../utils/test-utils'); -const { existsSync } = require('fs'); -const { resolve } = require('path'); +const { run, readFile } = require("../../utils/test-utils"); +const { existsSync } = require("fs"); +const { resolve } = require("path"); -const successMessage = 'stats are successfully stored as json to stats.json'; +const successMessage = "stats are successfully stored as json to stats.json"; -describe('json', () => { - it('should work and output json stats', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json']); +describe("json", () => { + it("should work and output json stats", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--json"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(() => JSON.parse(stdout)).not.toThrow(); - expect(JSON.parse(stdout)['hash']).toBeDefined(); + expect(JSON.parse(stdout)["hash"]).toBeDefined(); }); - it('should work and store json to a file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', 'stats.json']); + it("should work and store json to a file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--json", "stats.json"]); expect(exitCode).toBe(0); expect(stderr).toContain(successMessage); expect(stdout).toBeFalsy(); - expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./stats.json"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, 'stats.json'), 'utf-8'); + data = await readFile(resolve(__dirname, "stats.json"), "utf-8"); } catch (error) { expect(error).toBe(null); } - expect(JSON.parse(data)['hash']).toBeTruthy(); - expect(JSON.parse(data)['version']).toBeTruthy(); - expect(JSON.parse(data)['time']).toBeTruthy(); + expect(JSON.parse(data)["hash"]).toBeTruthy(); + expect(JSON.parse(data)["version"]).toBeTruthy(); + expect(JSON.parse(data)["time"]).toBeTruthy(); expect(() => JSON.parse(data)).not.toThrow(); }); - it('should work and store json to a file and respect --color flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', 'stats.json', '--color'], { env: { FORCE_COLOR: true } }); + it("should work and store json to a file and respect --color flag", async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--json", "stats.json", "--color"], + { env: { FORCE_COLOR: true } }, + ); expect(exitCode).toBe(0); expect(stderr).toContain(`\u001b[32m${successMessage}`); expect(stdout).toBeFalsy(); - expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./stats.json"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, 'stats.json'), 'utf-8'); + data = await readFile(resolve(__dirname, "stats.json"), "utf-8"); } catch (error) { expect(error).toBe(null); } - expect(JSON.parse(data)['hash']).toBeTruthy(); - expect(JSON.parse(data)['version']).toBeTruthy(); - expect(JSON.parse(data)['time']).toBeTruthy(); + expect(JSON.parse(data)["hash"]).toBeTruthy(); + expect(JSON.parse(data)["version"]).toBeTruthy(); + expect(JSON.parse(data)["time"]).toBeTruthy(); expect(() => JSON.parse(data)).not.toThrow(); }); - it('should work and store json to a file and respect --no-color', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', 'stats.json', '--no-color']); + it("should work and store json to a file and respect --no-color", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--json", + "stats.json", + "--no-color", + ]); expect(exitCode).toBe(0); expect(stderr).not.toContain(`\u001b[32m${successMessage}`); expect(stderr).toContain(`${successMessage}`); expect(stdout).toBeFalsy(); - expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./stats.json"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, 'stats.json'), 'utf-8'); + data = await readFile(resolve(__dirname, "stats.json"), "utf-8"); } catch (error) { expect(error).toBe(null); } - expect(JSON.parse(data)['hash']).toBeTruthy(); - expect(JSON.parse(data)['version']).toBeTruthy(); - expect(JSON.parse(data)['time']).toBeTruthy(); + expect(JSON.parse(data)["hash"]).toBeTruthy(); + expect(JSON.parse(data)["version"]).toBeTruthy(); + expect(JSON.parse(data)["time"]).toBeTruthy(); expect(() => JSON.parse(data)).not.toThrow(); }); it('should work using the "-j" option (alias)', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-j']); + const { exitCode, stderr, stdout } = await run(__dirname, ["-j"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(() => JSON.parse(stdout)).not.toThrow(); - expect(JSON.parse(stdout)['hash']).toBeDefined(); + expect(JSON.parse(stdout)["hash"]).toBeDefined(); }); it('should work and output json stats with the "--progress" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', '--progress']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--json", "--progress"]); expect(exitCode).toBe(0); - expect(stderr).toContain('webpack.Progress'); + expect(stderr).toContain("webpack.Progress"); expect(() => JSON.parse(stdout)).not.toThrow(); - expect(JSON.parse(stdout)['hash']).toBeDefined(); + expect(JSON.parse(stdout)["hash"]).toBeDefined(); }); it('should work and store json to a file with the "--progress" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', 'stats.json', '--progress']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--json", + "stats.json", + "--progress", + ]); expect(exitCode).toBe(0); - expect(stderr).toContain('webpack.Progress'); + expect(stderr).toContain("webpack.Progress"); expect(stderr).toContain(successMessage); expect(stdout).toBeFalsy(); - expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./stats.json"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, 'stats.json'), 'utf-8'); + data = await readFile(resolve(__dirname, "stats.json"), "utf-8"); } catch (error) { expect(error).toBe(null); } - expect(JSON.parse(data)['hash']).toBeTruthy(); - expect(JSON.parse(data)['version']).toBeTruthy(); - expect(JSON.parse(data)['time']).toBeTruthy(); + expect(JSON.parse(data)["hash"]).toBeTruthy(); + expect(JSON.parse(data)["version"]).toBeTruthy(); + expect(JSON.parse(data)["time"]).toBeTruthy(); expect(() => JSON.parse(data)).not.toThrow(); }); - it('should work and output json stats with cli logs', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', '--config', 'logging.config.js']); + it("should work and output json stats with cli logs", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--json", + "--config", + "logging.config.js", + ]); expect(exitCode).toBe(0); - expect(stderr).toContain('Compiler starting...'); - expect(stderr).toContain('Compiler finished'); + expect(stderr).toContain("Compiler starting..."); + expect(stderr).toContain("Compiler finished"); expect(() => JSON.parse(stdout)).not.toThrow(); - expect(JSON.parse(stdout)['hash']).toBeDefined(); + expect(JSON.parse(stdout)["hash"]).toBeDefined(); }); - it('should work and store json to a file with cli logs', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--json', 'stats.json', '--config', 'logging.config.js']); + it("should work and store json to a file with cli logs", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--json", + "stats.json", + "--config", + "logging.config.js", + ]); expect(exitCode).toBe(0); - expect(stderr).toContain('Compiler starting...'); - expect(stderr).toContain('Compiler finished'); + expect(stderr).toContain("Compiler starting..."); + expect(stderr).toContain("Compiler finished"); expect(stderr).toContain(successMessage); expect(stdout).toBeFalsy(); - expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy(); + expect(existsSync(resolve(__dirname, "./stats.json"))).toBeTruthy(); let data; try { - data = await readFile(resolve(__dirname, 'stats.json'), 'utf-8'); + data = await readFile(resolve(__dirname, "stats.json"), "utf-8"); } catch (error) { expect(error).toBe(null); } - expect(JSON.parse(data)['hash']).toBeTruthy(); - expect(JSON.parse(data)['version']).toBeTruthy(); - expect(JSON.parse(data)['time']).toBeTruthy(); + expect(JSON.parse(data)["hash"]).toBeTruthy(); + expect(JSON.parse(data)["version"]).toBeTruthy(); + expect(JSON.parse(data)["time"]).toBeTruthy(); expect(() => JSON.parse(data)).not.toThrow(); }); }); diff --git a/test/build/json/logging.config.js b/test/build/json/logging.config.js index 481fe38bff4..d95eb5d6505 100644 --- a/test/build/json/logging.config.js +++ b/test/build/json/logging.config.js @@ -1,5 +1,5 @@ module.exports = { infrastructureLogging: { - level: 'log', + level: "log", }, }; diff --git a/test/build/merge/config-absent/1.js b/test/build/merge/config-absent/1.js index 133fc6944be..dd5fda8eb9b 100644 --- a/test/build/merge/config-absent/1.js +++ b/test/build/merge/config-absent/1.js @@ -1,3 +1,3 @@ module.exports = { - entry: './some_entry.js', + entry: "./some_entry.js", }; diff --git a/test/build/merge/config-absent/merge-config-absent.test.js b/test/build/merge/config-absent/merge-config-absent.test.js index f2ad6d92c7e..78a2dc4cdae 100644 --- a/test/build/merge/config-absent/merge-config-absent.test.js +++ b/test/build/merge/config-absent/merge-config-absent.test.js @@ -1,18 +1,24 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('merge flag configuration', () => { - it('Show warning message when the merge config is absent', async () => { +describe("merge flag configuration", () => { + it("Show warning message when the merge config is absent", async () => { // 2.js doesn't exist, let's try merging with it - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './1.js', '--config', './2.js', '--merge']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./1.js", + "--config", + "./2.js", + "--merge", + ]); expect(exitCode).toEqual(2); // Since the process will exit, nothing on stdout expect(stdout).toBeFalsy(); // Confirm that the user is notified - expect(stderr).toContain(`Failed to load '${path.resolve(__dirname, './2.js')}' config`); + expect(stderr).toContain(`Failed to load '${path.resolve(__dirname, "./2.js")}' config`); }); }); diff --git a/test/build/merge/config-absent/some_entry.js b/test/build/merge/config-absent/some_entry.js index cae68b1307a..3241ee52fce 100644 --- a/test/build/merge/config-absent/some_entry.js +++ b/test/build/merge/config-absent/some_entry.js @@ -1 +1 @@ -console.log('Oikawa'); +console.log("Oikawa"); diff --git a/test/build/merge/config/1.js b/test/build/merge/config/1.js index d625438dde2..75c2976b1f1 100644 --- a/test/build/merge/config/1.js +++ b/test/build/merge/config/1.js @@ -1,10 +1,10 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { - entry: './first-entry.js', - mode: 'development', + entry: "./first-entry.js", + mode: "development", output: { - filename: 'first-output.js', + filename: "first-output.js", }, plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/merge/config/2.js b/test/build/merge/config/2.js index cdf6f428467..74ca9242e4f 100644 --- a/test/build/merge/config/2.js +++ b/test/build/merge/config/2.js @@ -1,7 +1,7 @@ module.exports = { - entry: './second-entry.js', - target: 'node', + entry: "./second-entry.js", + target: "node", output: { - filename: 'second-output.js', + filename: "second-output.js", }, }; diff --git a/test/build/merge/config/3.js b/test/build/merge/config/3.js index eb2a7d3a6f5..2b511143d51 100644 --- a/test/build/merge/config/3.js +++ b/test/build/merge/config/3.js @@ -1,6 +1,6 @@ module.exports = { - entry: './third-entry.js', + entry: "./third-entry.js", output: { - filename: 'third-output.js', + filename: "third-output.js", }, }; diff --git a/test/build/merge/config/first-entry.js b/test/build/merge/config/first-entry.js index e5ba023838e..8a9423b5c10 100644 --- a/test/build/merge/config/first-entry.js +++ b/test/build/merge/config/first-entry.js @@ -1 +1 @@ -console.log('first'); +console.log("first"); diff --git a/test/build/merge/config/merge-config.test.js b/test/build/merge/config/merge-config.test.js index 7583fbd6940..53653068ca3 100644 --- a/test/build/merge/config/merge-config.test.js +++ b/test/build/merge/config/merge-config.test.js @@ -1,45 +1,61 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('merge flag configuration', () => { - it('merges two configurations together', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './1.js', '--config', './2.js', '--merge']); +describe("merge flag configuration", () => { + it("merges two configurations together", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./1.js", + "--config", + "./2.js", + "--merge", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js - expect(stdout).toContain('second-output.js'); // from 2.js + expect(stdout).toContain("WebpackCLITestPlugin"); // from 1.js + expect(stdout).toContain("second-output.js"); // from 2.js }); - it('merges more than two configurations together', async () => { + it("merges more than two configurations together", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['--config', './1.js', '--config', './2.js', '--config', './3.js', '--merge'], + ["--config", "./1.js", "--config", "./2.js", "--config", "./3.js", "--merge"], false, ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js + expect(stdout).toContain("WebpackCLITestPlugin"); // from 1.js expect(stdout).toContain("target: 'node'"); // from 2.js - expect(stdout).toContain('third-output.js'); // from 3.js + expect(stdout).toContain("third-output.js"); // from 3.js }); - it('merges two configurations together with flag alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './1.js', '--config', './2.js', '-m']); + it("merges two configurations together with flag alias", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./1.js", + "--config", + "./2.js", + "-m", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js - expect(stdout).toContain('second-output.js'); // from 2.js + expect(stdout).toContain("WebpackCLITestPlugin"); // from 1.js + expect(stdout).toContain("second-output.js"); // from 2.js }); - it('fails when there are less than 2 configurations to merge', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './1.js', '--merge']); + it("fails when there are less than 2 configurations to merge", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./1.js", + "--merge", + ]); expect(exitCode).toBe(2); - expect(stderr).toContain('At least two configurations are required for merge.'); + expect(stderr).toContain("At least two configurations are required for merge."); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/merge/config/second-entry.js b/test/build/merge/config/second-entry.js index e1595dffb00..5023a5896d0 100644 --- a/test/build/merge/config/second-entry.js +++ b/test/build/merge/config/second-entry.js @@ -1 +1 @@ -console.log('second'); +console.log("second"); diff --git a/test/build/merge/config/third-entry.js b/test/build/merge/config/third-entry.js index 29134430a5e..f532661b412 100644 --- a/test/build/merge/config/third-entry.js +++ b/test/build/merge/config/third-entry.js @@ -1 +1 @@ -console.log('third'); +console.log("third"); diff --git a/test/build/mode/mode-single-arg/mode-single-arg.test.js b/test/build/mode/mode-single-arg/mode-single-arg.test.js index c7bafa5670d..e96aad5796b 100644 --- a/test/build/mode/mode-single-arg/mode-single-arg.test.js +++ b/test/build/mode/mode-single-arg/mode-single-arg.test.js @@ -1,51 +1,55 @@ -'use strict'; +"use strict"; -const { run, isWebpack5 } = require('../../../utils/test-utils'); +const { run, isWebpack5 } = require("../../../utils/test-utils"); -describe('mode flags', () => { - it('should not set mode=production by default', async () => { +describe("mode flags", () => { + it("should not set mode=production by default", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).not.toContain(`mode: 'production'`); - expect(stdout).toContain(`The 'mode' option has not been set, webpack will fallback to 'production' for this value.`); + 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', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development']); + it("should load a development config when --mode=development is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "development"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'development'`); }); - it('should load a production config when --mode=production is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'production']); + it("should load a production config when --mode=production is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "production"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'production'`); }); - it('should load a none config when --mode=none is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'none']); + it("should load a none config when --mode=none is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "none"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'none'`); }); - it('should pick mode form NODE_ENV', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { env: { NODE_ENV: 'development' } }); + it("should pick mode form NODE_ENV", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [], { + env: { NODE_ENV: "development" }, + }); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'development'`); }); - it('should throw error when --mode=abcd is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'abcd']); + it("should throw error when --mode=abcd is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--mode", "abcd"]); expect(exitCode).toBe(2); @@ -53,7 +57,7 @@ describe('mode flags', () => { expect(stderr).toContain("Invalid value 'abcd' for the '--mode' option"); expect(stderr).toContain("Expected: 'development | production | none'"); } else { - expect(stderr).toContain('configuration.mode should be one of these'); + expect(stderr).toContain("configuration.mode should be one of these"); expect(stderr).toContain(`"development" | "production" | "none"`); } diff --git a/test/build/mode/mode-single-arg/webpack.config.js b/test/build/mode/mode-single-arg/webpack.config.js index 92b325a3c41..59a9a8c360c 100644 --- a/test/build/mode/mode-single-arg/webpack.config.js +++ b/test/build/mode/mode-single-arg/webpack.config.js @@ -1,6 +1,6 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { - entry: './src/index.js', + entry: "./src/index.js", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/mode/mode-with-config/mode-with-config.test.js b/test/build/mode/mode-with-config/mode-with-config.test.js index aa98f9cd9cc..9a611a314b2 100644 --- a/test/build/mode/mode-with-config/mode-with-config.test.js +++ b/test/build/mode/mode-with-config/mode-with-config.test.js @@ -1,10 +1,15 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('mode flags with config', () => { - it('should run in production mode when --mode=production is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'production', '--config', './webpack.config.js']); +describe("mode flags with config", () => { + it("should run in production mode when --mode=production is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "production", + "--config", + "./webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -12,8 +17,13 @@ describe('mode flags with config', () => { expect(stdout).toContain(`mode: 'production'`); }); - it('should run in development mode when --mode=development is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development', '--config', './webpack.config.js']); + it("should run in development mode when --mode=development is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "development", + "--config", + "./webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -21,8 +31,13 @@ describe('mode flags with config', () => { expect(stdout).toContain(`mode: 'development'`); }); - it('should run in none mode when --mode=none is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'none', '--config', './webpack.config.js']); + it("should run in none mode when --mode=none is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "none", + "--config", + "./webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -31,60 +46,74 @@ describe('mode flags with config', () => { }); it('should use mode from flag over "process.env.NODE_ENV"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'none', '-c', 'webpack.config2.js'], [], { - NODE_ENV: 'production', - }); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--mode", "none", "-c", "webpack.config2.js"], + [], + { + NODE_ENV: "production", + }, + ); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'none'`); }); - it('should use mode from config over NODE_ENV', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config2.js']); + it("should use mode from config over NODE_ENV", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config2.js"]); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'development'`); }); - it('should use mode from config when multiple config are supplied', async () => { - const { exitCode, stdout, stderr } = await run(__dirname, ['-c', 'webpack.config3.js', '-c', 'webpack.config2.js']); + it("should use mode from config when multiple config are supplied", async () => { + const { exitCode, stdout, stderr } = await run(__dirname, [ + "-c", + "webpack.config3.js", + "-c", + "webpack.config2.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'development'`); - expect(stdout.match(new RegExp("mode: 'development'", 'g')).length).toEqual(1); + expect(stdout.match(new RegExp("mode: 'development'", "g")).length).toEqual(1); }); - it('mode flag should apply to all configs', async () => { + it("mode flag should apply to all configs", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - '--mode', - 'none', - '-c', - './webpack.config3.js', - '-c', - './webpack.config2.js', + "--mode", + "none", + "-c", + "./webpack.config3.js", + "-c", + "./webpack.config2.js", ]); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'none'`); - expect(stdout.match(new RegExp("mode: 'none'", 'g')).length).toEqual(2); + expect(stdout.match(new RegExp("mode: 'none'", "g")).length).toEqual(2); }); - it('only config where mode is absent pick up from NODE_ENV', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config3.js', '-c', './webpack.config2.js'], { - env: { - NODE_ENV: 'production', + it("only config where mode is absent pick up from NODE_ENV", async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", "./webpack.config3.js", "-c", "./webpack.config2.js"], + { + env: { + NODE_ENV: "production", + }, }, - }); + ); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`mode: 'production'`); expect(stdout).toContain(`mode: 'development'`); - expect(stdout.match(new RegExp("mode: 'production'", 'g')).length).toEqual(1); - expect(stdout.match(new RegExp("mode: 'development'", 'g')).length).toEqual(1); + expect(stdout.match(new RegExp("mode: 'production'", "g")).length).toEqual(1); + expect(stdout.match(new RegExp("mode: 'development'", "g")).length).toEqual(1); }); }); diff --git a/test/build/mode/mode-with-config/webpack.config.js b/test/build/mode/mode-with-config/webpack.config.js index 938c3552a34..d54eae282f5 100644 --- a/test/build/mode/mode-with-config/webpack.config.js +++ b/test/build/mode/mode-with-config/webpack.config.js @@ -1,10 +1,10 @@ -const path = require('path'); -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const path = require("path"); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { output: { - path: path.join(__dirname, 'dist'), - filename: '[name].js', + path: path.join(__dirname, "dist"), + filename: "[name].js", }, plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/mode/mode-with-config/webpack.config2.js b/test/build/mode/mode-with-config/webpack.config2.js index f06b817c4bf..56e4d9fe88e 100644 --- a/test/build/mode/mode-with-config/webpack.config2.js +++ b/test/build/mode/mode-with-config/webpack.config2.js @@ -1,6 +1,6 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { - mode: 'development', + mode: "development", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/mode/mode-with-config/webpack.config3.js b/test/build/mode/mode-with-config/webpack.config3.js index 996241cb577..dca1bf8e00c 100644 --- a/test/build/mode/mode-with-config/webpack.config3.js +++ b/test/build/mode/mode-with-config/webpack.config3.js @@ -1,4 +1,4 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { plugins: [new WebpackCLITestPlugin()], diff --git a/test/build/name/name.test.js b/test/build/name/name.test.js index e937735a610..9b07d0bb58d 100644 --- a/test/build/name/name.test.js +++ b/test/build/name/name.test.js @@ -1,9 +1,9 @@ -'use strict'; -const { run } = require('../../utils/test-utils'); +"use strict"; +const { run } = require("../../utils/test-utils"); -describe('name flag', () => { - it('should set the flag in the config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--name', 'config-name']); +describe("name flag", () => { + it("should set the flag in the config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--name", "config-name"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/name/webpack.config.js b/test/build/name/webpack.config.js index 7e2e7a43158..5f26f45fe05 100644 --- a/test/build/name/webpack.config.js +++ b/test/build/name/webpack.config.js @@ -1,4 +1,4 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); module.exports = { plugins: [new WebpackCLITestPlugin()], diff --git a/test/build/node-env/auto-mode.config.js b/test/build/node-env/auto-mode.config.js index 7e2e7a43158..5f26f45fe05 100644 --- a/test/build/node-env/auto-mode.config.js +++ b/test/build/node-env/auto-mode.config.js @@ -1,4 +1,4 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); module.exports = { plugins: [new WebpackCLITestPlugin()], diff --git a/test/build/node-env/node-env.test.js b/test/build/node-env/node-env.test.js index 9d4869d4053..479c1d90d7f 100644 --- a/test/build/node-env/node-env.test.js +++ b/test/build/node-env/node-env.test.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('--node-env flag', () => { +describe("--node-env flag", () => { it('should set "process.env.NODE_ENV" to "development"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-env', 'development']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--node-env", "development"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -12,7 +12,7 @@ describe('--node-env flag', () => { }); it('should set "process.env.NODE_ENV" to "production"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-env', 'production']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--node-env", "production"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -20,7 +20,7 @@ describe('--node-env flag', () => { }); it('should set "process.env.NODE_ENV" to "none"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-env', 'none']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--node-env", "none"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -28,7 +28,12 @@ describe('--node-env flag', () => { }); it('should set "process.env.NODE_ENV" and the "mode" option to "development"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-env', 'development', '--config', './auto-mode.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--node-env", + "development", + "--config", + "./auto-mode.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -36,7 +41,12 @@ describe('--node-env flag', () => { }); it('should set "process.env.NODE_ENV" and the "mode" option to "production"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-env', 'production', '--config', './auto-mode.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--node-env", + "production", + "--config", + "./auto-mode.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -44,7 +54,12 @@ describe('--node-env flag', () => { }); it('should set "process.env.NODE_ENV" and the "mode" option to "none"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--node-env', 'none', '--config', './auto-mode.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--node-env", + "none", + "--config", + "./auto-mode.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/node-env/webpack.config.js b/test/build/node-env/webpack.config.js index 7b4174b3f64..0c4532b82cd 100644 --- a/test/build/node-env/webpack.config.js +++ b/test/build/node-env/webpack.config.js @@ -1,4 +1,4 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); module.exports = { mode: process.env.NODE_ENV, diff --git a/test/build/node/a.js b/test/build/node/a.js index 735d820f253..0e9a8dc5145 100644 --- a/test/build/node/a.js +++ b/test/build/node/a.js @@ -1 +1 @@ -module.exports = 'a.js'; +module.exports = "a.js"; diff --git a/test/build/node/bootstrap.js b/test/build/node/bootstrap.js index 0980f54d442..93d93cf74cf 100644 --- a/test/build/node/bootstrap.js +++ b/test/build/node/bootstrap.js @@ -1 +1 @@ -console.log('---from bootstrap.js---'); +console.log("---from bootstrap.js---"); diff --git a/test/build/node/bootstrap2.js b/test/build/node/bootstrap2.js index 5105ea40c01..4d1743d6349 100644 --- a/test/build/node/bootstrap2.js +++ b/test/build/node/bootstrap2.js @@ -1 +1 @@ -console.log('---from bootstrap2.js---'); +console.log("---from bootstrap2.js---"); diff --git a/test/build/node/node.test.js b/test/build/node/node.test.js index a062d06656b..5689d97b95b 100644 --- a/test/build/node/node.test.js +++ b/test/build/node/node.test.js @@ -1,40 +1,51 @@ -'use strict'; -const { resolve } = require('path'); -const { run } = require('../../utils/test-utils'); - -describe('node flags', () => { - it('is able to pass the options flags to node js', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--output-path', './bin'], { - nodeOptions: [`--require=${resolve(__dirname, 'bootstrap.js')}`, `--require=${resolve(__dirname, 'bootstrap2.js')}`], +"use strict"; +const { resolve } = require("path"); +const { run } = require("../../utils/test-utils"); + +describe("node flags", () => { + it("is able to pass the options flags to node js", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--output-path", "./bin"], { + nodeOptions: [ + `--require=${resolve(__dirname, "bootstrap.js")}`, + `--require=${resolve(__dirname, "bootstrap2.js")}`, + ], }); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('---from bootstrap.js---'); - expect(stdout).toContain('---from bootstrap2.js---'); + expect(stdout).toContain("---from bootstrap.js---"); + expect(stdout).toContain("---from bootstrap2.js---"); }); - it('throws an error on supplying unknown flags', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { nodeOptions: ['--unknown'] }); + it("throws an error on supplying unknown flags", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [], { + nodeOptions: ["--unknown"], + }); expect(exitCode).not.toBe(0); - expect(stderr).toContain('bad option'); + expect(stderr).toContain("bad option"); expect(stdout).toBeFalsy(); }); - it('throws an error if no values were supplied with --max-old-space-size', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { nodeOptions: ['--max-old-space-size'] }); + it("throws an error if no values were supplied with --max-old-space-size", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [], { + nodeOptions: ["--max-old-space-size"], + }); expect(exitCode).not.toBe(0); - expect(stderr).toContain('value for flag --max-old-space-size'); + 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 { exitCode, stderr, stdout } = await run(__dirname, [], { nodeOptions: ['--max_old_space_size=1024a'] }); + it("throws an error if an illegal value was supplied with --max-old-space-size", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [], { + nodeOptions: ["--max_old_space_size=1024a"], + }); expect(exitCode).not.toBe(0); - expect(stderr).toContain('Error: illegal value for flag --max_old_space_size=1024a of type size_t'); + expect(stderr).toContain( + "Error: illegal value for flag --max_old_space_size=1024a of type size_t", + ); expect(stdout).toBeFalsy(); }); }); diff --git a/test/build/node/webpack.config.js b/test/build/node/webpack.config.js index 4913dff71b6..2ba79e7a44a 100644 --- a/test/build/node/webpack.config.js +++ b/test/build/node/webpack.config.js @@ -1,9 +1,9 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: './a.js', + entry: "./a.js", output: { - path: resolve(__dirname, 'binary'), - filename: '[name].bundle.js', + path: resolve(__dirname, "binary"), + filename: "[name].bundle.js", }, }; diff --git a/test/build/output/a.js b/test/build/output/a.js index 8f17634893a..5af61abbbef 100644 --- a/test/build/output/a.js +++ b/test/build/output/a.js @@ -1 +1 @@ -module.export = 'output-flag-test-overwrite-a.js'; +module.export = "output-flag-test-overwrite-a.js"; diff --git a/test/build/output/b.js b/test/build/output/b.js index a80d9d5559a..cdf5f144c61 100644 --- a/test/build/output/b.js +++ b/test/build/output/b.js @@ -1 +1 @@ -module.export = 'output-flag-test-overwrite-b.js'; +module.export = "output-flag-test-overwrite-b.js"; diff --git a/test/build/output/c.js b/test/build/output/c.js index 4bedd16bc01..8924478406f 100644 --- a/test/build/output/c.js +++ b/test/build/output/c.js @@ -1 +1 @@ -module.export = 'output-flag-test-overwrite-c.js'; +module.export = "output-flag-test-overwrite-c.js"; diff --git a/test/build/output/output-named-bundles.test.js b/test/build/output/output-named-bundles.test.js index 23cafb259fd..f872fef7790 100644 --- a/test/build/output/output-named-bundles.test.js +++ b/test/build/output/output-named-bundles.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const { run, normalizeStdout, normalizeStderr } = require('../../utils/test-utils'); +const { resolve } = require("path"); +const { run, normalizeStdout, normalizeStderr } = require("../../utils/test-utils"); -describe('output flag named bundles', () => { - it('should output file given as flag instead of in configuration', async () => { +describe("output flag named bundles", () => { + it("should output file given as flag instead of in configuration", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], + ["-c", resolve(__dirname, "webpack.config.js"), "--output-path", "./binary"], false, ); @@ -16,10 +16,10 @@ describe('output flag named bundles', () => { expect(stdout).toBeTruthy(); }); - it('should resolve the path to binary/a.bundle.js as ./binary/a.bundle.js', async () => { + it("should resolve the path to binary/a.bundle.js as ./binary/a.bundle.js", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', 'binary'], + ["-c", resolve(__dirname, "webpack.config.js"), "--output-path", "binary"], false, ); @@ -28,10 +28,10 @@ describe('output flag named bundles', () => { expect(stdout).toBeTruthy(); }); - it('should create multiple bundles with an overriding flag', async () => { + it("should create multiple bundles with an overriding flag", async () => { const { exitCode, stderr, stdout } = await run( __dirname, - ['-c', resolve(__dirname, 'webpack.single.config.js'), '--output-path', './bin'], + ["-c", resolve(__dirname, "webpack.single.config.js"), "--output-path", "./bin"], false, ); @@ -40,19 +40,22 @@ describe('output flag named bundles', () => { expect(stdout).toBeTruthy(); }); - it('should successfully compile multiple entries', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', resolve(__dirname, 'webpack.multiple.config.js')]); + it("should successfully compile multiple entries", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.multiple.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should output file in bin directory using default webpack config with warning for empty output value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--output-path']); + it("should output file in bin directory using default webpack config with warning for empty output value", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--output-path"]); expect(exitCode).toEqual(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/build/output/webpack.config.js b/test/build/output/webpack.config.js index f1be65a15cc..14b4f23506b 100644 --- a/test/build/output/webpack.config.js +++ b/test/build/output/webpack.config.js @@ -1,10 +1,10 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { - entry: './a.js', - mode: 'development', + entry: "./a.js", + mode: "development", output: { - path: resolve(__dirname, 'bin'), - filename: 'a.bundle.js', + path: resolve(__dirname, "bin"), + filename: "a.bundle.js", }, }; diff --git a/test/build/output/webpack.defaults.config.js b/test/build/output/webpack.defaults.config.js index 69a38fff1c5..08608192ceb 100644 --- a/test/build/output/webpack.defaults.config.js +++ b/test/build/output/webpack.defaults.config.js @@ -1,7 +1,7 @@ module.exports = { entry: { - b: './b.js', - c: './c.js', + b: "./b.js", + c: "./c.js", }, - mode: 'development', + mode: "development", }; diff --git a/test/build/output/webpack.multiple.config.js b/test/build/output/webpack.multiple.config.js index a047b31864d..af105fab019 100644 --- a/test/build/output/webpack.multiple.config.js +++ b/test/build/output/webpack.multiple.config.js @@ -1,13 +1,13 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { entry: { - b: './b.js', - c: './c.js', + b: "./b.js", + c: "./c.js", }, output: { - path: resolve(__dirname, 'bin'), - filename: '[name].bundle.js', + path: resolve(__dirname, "bin"), + filename: "[name].bundle.js", }, - mode: 'development', + mode: "development", }; diff --git a/test/build/output/webpack.single.config.js b/test/build/output/webpack.single.config.js index a047b31864d..af105fab019 100644 --- a/test/build/output/webpack.single.config.js +++ b/test/build/output/webpack.single.config.js @@ -1,13 +1,13 @@ -const { resolve } = require('path'); +const { resolve } = require("path"); module.exports = { entry: { - b: './b.js', - c: './c.js', + b: "./b.js", + c: "./c.js", }, output: { - path: resolve(__dirname, 'bin'), - filename: '[name].bundle.js', + path: resolve(__dirname, "bin"), + filename: "[name].bundle.js", }, - mode: 'development', + mode: "development", }; diff --git a/test/build/prefetch/prefetch.test.js b/test/build/prefetch/prefetch.test.js index 3f4547daa9a..8a9b7c91fe7 100644 --- a/test/build/prefetch/prefetch.test.js +++ b/test/build/prefetch/prefetch.test.js @@ -1,29 +1,37 @@ -'use strict'; +"use strict"; -const { join } = require('path'); -const { run, readFile } = require('../../utils/test-utils'); +const { join } = require("path"); +const { run, readFile } = require("../../utils/test-utils"); // eslint-disable-next-line node/no-unpublished-require -const rimraf = require('rimraf'); +const rimraf = require("rimraf"); -describe('prefetch', () => { +describe("prefetch", () => { afterEach(() => { - rimraf.sync(join(__dirname, 'dist')); + rimraf.sync(join(__dirname, "dist")); }); - it('should load the prefetched file', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--prefetch', './src/p.js', '--mode', 'development']); + it("should load the prefetched file", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--prefetch", + "./src/p.js", + "--mode", + "development", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); - const content = await readFile(join(__dirname, '/dist/main.js'), 'utf-8'); + const content = await readFile(join(__dirname, "/dist/main.js"), "utf-8"); - expect(content).not.toContain('// no prefetching'); + expect(content).not.toContain("// no prefetching"); }); - it('should log error when the prefetched file is absent', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--prefetch', './src/somefile.js']); + it("should log error when the prefetched file is absent", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--prefetch", + "./src/somefile.js", + ]); expect(exitCode).toBe(1); expect(stderr).toBeFalsy(); @@ -31,8 +39,8 @@ describe('prefetch', () => { expect(stdout).toContain(`Error: Can't resolve './src/somefile.js'`); }); - it('should log error when flag value is not supplied', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--prefetch']); + it("should log error when flag value is not supplied", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--prefetch"]); expect(exitCode).toBe(2); expect(stderr).toContain(`Error: Option '--prefetch ' argument missing`); diff --git a/test/build/prefetch/src/p.js b/test/build/prefetch/src/p.js index 3bf8b892c52..cc132d2393a 100644 --- a/test/build/prefetch/src/p.js +++ b/test/build/prefetch/src/p.js @@ -1,3 +1,3 @@ -console.log('HERE'); +console.log("HERE"); -module.exports = 'async-value'; +module.exports = "async-value"; diff --git a/test/build/progress/progress-flag.test.js b/test/build/progress/progress-flag.test.js index 8a008e7b01f..3ddaf4003f2 100644 --- a/test/build/progress/progress-flag.test.js +++ b/test/build/progress/progress-flag.test.js @@ -1,19 +1,19 @@ -'use strict'; +"use strict"; -const { run, isWebpack5 } = require('../../utils/test-utils'); +const { run, isWebpack5 } = require("../../utils/test-utils"); -describe('progress flag', () => { - it('should show progress', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--progress']); +describe("progress flag", () => { + it("should show progress", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--progress"]); expect(exitCode).toBe(0); expect(stderr).not.toMatch(/\[webpack\.Progress] \d+ ms setup/); - expect(stderr).toContain('[webpack.Progress] 100%'); - expect(stdout).toContain('main.js'); + expect(stderr).toContain("[webpack.Progress] 100%"); + expect(stdout).toContain("main.js"); }); it('should support the "profile" value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--progress=profile']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--progress=profile"]); expect(exitCode).toBe(0); @@ -21,25 +21,31 @@ describe('progress flag', () => { expect(stderr).toMatch(/\[webpack\.Progress] \d+ ms setup/); } - expect(stderr).toContain('[webpack.Progress] 100%'); - expect(stdout).toContain('main.js'); + expect(stderr).toContain("[webpack.Progress] 100%"); + expect(stdout).toContain("main.js"); }); - it('should not support invalid value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--progress=unknown']); + it("should not support invalid value", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--progress=unknown"]); expect(exitCode).toBe(2); - expect(stderr).toContain(`'unknown' is an invalid value for the --progress option. Only 'profile' is allowed.`); + 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', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.progress.config.js', '--progress']); + it("should not add duplicate plugins", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "webpack.progress.config.js", + "--progress", + ]); expect(exitCode).toEqual(0); expect(stderr).not.toMatch(/\[webpack\.Progress] \d+ ms setup/); - expect(stderr).toContain('[webpack.Progress] 100%'); - expect(stdout).toContain('main.js'); + expect(stderr).toContain("[webpack.Progress] 100%"); + expect(stdout).toContain("main.js"); expect(stdout.match(/ProgressPlugin/g)).toHaveLength(1); }); }); diff --git a/test/build/progress/webpack.progress.config.js b/test/build/progress/webpack.progress.config.js index d376de11e67..f5d1aba13c7 100644 --- a/test/build/progress/webpack.progress.config.js +++ b/test/build/progress/webpack.progress.config.js @@ -1,5 +1,5 @@ -const { ProgressPlugin } = require('webpack'); -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); +const { ProgressPlugin } = require("webpack"); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); module.exports = { plugins: [new ProgressPlugin({}), new WebpackCLITestPlugin()], diff --git a/test/build/start-finish-force-log/start-finish-force-log.test.js b/test/build/start-finish-force-log/start-finish-force-log.test.js index 5e24d17d2d3..c3d79d7c9e6 100644 --- a/test/build/start-finish-force-log/start-finish-force-log.test.js +++ b/test/build/start-finish-force-log/start-finish-force-log.test.js @@ -1,51 +1,55 @@ -'use strict'; +"use strict"; -const { run, runWatch, isWebpack5 } = require('../../utils/test-utils'); +const { run, runWatch, isWebpack5 } = require("../../utils/test-utils"); -describe('start finish force log', () => { - it('start finish force log when env is set', async () => { +describe("start finish force log", () => { + it("start finish force log when env is set", async () => { const { exitCode, stderr, stdout } = await run(__dirname, [], { env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true }, }); expect(exitCode).toBe(0); - expect(stderr).toContain('Compiler starting...'); - expect(stderr).toContain('Compiler finished'); - const output = isWebpack5 ? 'compiled successfully' : 'main.js'; + expect(stderr).toContain("Compiler starting..."); + expect(stderr).toContain("Compiler finished"); + const output = isWebpack5 ? "compiled successfully" : "main.js"; expect(stdout).toContain(output); }); - it('should show name of the config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--name', 'log config'], { + it("should show name of the config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--name", "log config"], { env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true }, }); expect(exitCode).toBe(0); expect(stderr).toContain("Compiler 'log config' starting..."); expect(stderr).toContain("Compiler 'log config' finished"); - const output = isWebpack5 ? 'compiled successfully' : 'main.js'; + const output = isWebpack5 ? "compiled successfully" : "main.js"; expect(stdout).toContain(output); }); - it('should work with watch', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['watch'], { + it("should work with watch", async () => { + const { stderr, stdout } = await runWatch(__dirname, ["watch"], { env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true }, killString: /Compiler finished/, }); - expect(stderr).toContain('Compiler starting...'); - expect(stderr).toContain('Compiler finished'); - const output = isWebpack5 ? 'compiled successfully' : 'main.js'; + expect(stderr).toContain("Compiler starting..."); + expect(stderr).toContain("Compiler finished"); + const output = isWebpack5 ? "compiled successfully" : "main.js"; expect(stdout).toContain(output); }); - it('should work with multi compiler', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--config', './webpack.config.array.js'], { - env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true }, - }); + it("should work with multi compiler", async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config", "./webpack.config.array.js"], + { + env: { WEBPACK_CLI_START_FINISH_FORCE_LOG: true }, + }, + ); expect(exitCode).toBe(0); expect(stderr).toContain("Compiler 'Gojou' starting..."); expect(stderr).toContain("Compiler 'Satoru' starting..."); expect(stderr).toContain("Compiler 'Gojou' finished"); expect(stderr).toContain("Compiler 'Satoru' finished"); - const output = isWebpack5 ? 'compiled successfully' : 'main.js'; + const output = isWebpack5 ? "compiled successfully" : "main.js"; expect(stdout).toContain(output); }); }); diff --git a/test/build/start-finish-force-log/webpack.config.array.js b/test/build/start-finish-force-log/webpack.config.array.js index 14738c20f1b..f7313b8da56 100644 --- a/test/build/start-finish-force-log/webpack.config.array.js +++ b/test/build/start-finish-force-log/webpack.config.array.js @@ -1,10 +1,10 @@ module.exports = [ { - name: 'Gojou', - mode: 'development', + name: "Gojou", + mode: "development", }, { - name: 'Satoru', - mode: 'development', + name: "Satoru", + mode: "development", }, ]; diff --git a/test/build/start-finish-force-log/webpack.config.js b/test/build/start-finish-force-log/webpack.config.js index f2c3976d5d3..11623bb6280 100644 --- a/test/build/start-finish-force-log/webpack.config.js +++ b/test/build/start-finish-force-log/webpack.config.js @@ -1,3 +1,3 @@ module.exports = { - mode: 'development', + mode: "development", }; diff --git a/test/build/stats/config-no/main.js b/test/build/stats/config-no/main.js index a0a157ceeef..2aabf698f8d 100644 --- a/test/build/stats/config-no/main.js +++ b/test/build/stats/config-no/main.js @@ -1 +1 @@ -console.log('--no-stats with config test'); +console.log("--no-stats with config test"); diff --git a/test/build/stats/config-no/no-stats-with-config.test.js b/test/build/stats/config-no/no-stats-with-config.test.js index 3b4d28c7343..d42a1f63fff 100644 --- a/test/build/stats/config-no/no-stats-with-config.test.js +++ b/test/build/stats/config-no/no-stats-with-config.test.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; -const { run, isWebpack5 } = require('../../../utils/test-utils'); +const { run, isWebpack5 } = require("../../../utils/test-utils"); -describe('stats flag', () => { +describe("stats flag", () => { it(`should use stats 'detailed' as defined in webpack config`, async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); @@ -12,14 +12,14 @@ describe('stats flag', () => { if (isWebpack5) { expect(stdout).toContain("preset: 'detailed'"); } else { - expect(stdout).toContain('entrypoints: true'); - expect(stdout).toContain('logging: true'); - expect(stdout).toContain('maxModules: Infinity'); + expect(stdout).toContain("entrypoints: true"); + expect(stdout).toContain("logging: true"); + expect(stdout).toContain("maxModules: Infinity"); } }); it(`should use --no-stats and override value in config`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-stats']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-stats"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -27,7 +27,7 @@ describe('stats flag', () => { if (isWebpack5) { expect(stdout).toContain("preset: 'none'"); } else { - expect(stdout).toContain('all: false'); + expect(stdout).toContain("all: false"); } }); }); diff --git a/test/build/stats/config-no/webpack.config.js b/test/build/stats/config-no/webpack.config.js index 36d2ce45fae..f4eea6318f7 100644 --- a/test/build/stats/config-no/webpack.config.js +++ b/test/build/stats/config-no/webpack.config.js @@ -1,8 +1,8 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { - mode: 'development', - entry: './main.js', - stats: 'detailed', + mode: "development", + entry: "./main.js", + stats: "detailed", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/stats/config/stats.test.js b/test/build/stats/config/stats.test.js index 9fb653bbe01..912c10f38d3 100644 --- a/test/build/stats/config/stats.test.js +++ b/test/build/stats/config/stats.test.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; -const { run, isWebpack5 } = require('../../../utils/test-utils'); +const { run, isWebpack5 } = require("../../../utils/test-utils"); // 'normal' is used in webpack.config.js -const statsPresets = ['detailed', 'errors-only', 'errors-warnings', 'minimal', 'verbose', 'none']; +const statsPresets = ["detailed", "errors-only", "errors-warnings", "minimal", "verbose", "none"]; if (isWebpack5) { - statsPresets.push('summary'); + statsPresets.push("summary"); } -describe('stats flag with config', () => { - it('should compile without stats flag', async () => { +describe("stats flag with config", () => { + it("should compile without stats flag", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); @@ -25,7 +25,7 @@ describe('stats flag with config', () => { for (const preset of statsPresets) { it(`should override 'noramal' value in config with "${preset}"`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats', `${preset}`]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--stats", `${preset}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -34,31 +34,31 @@ describe('stats flag with config', () => { expect(stdout).toContain(`preset: '${preset}'`); } else { switch (preset) { - case 'normal': - expect(stdout).toContain('stats:'); + case "normal": + expect(stdout).toContain("stats:"); break; - case 'detailed': - expect(stdout).toContain('entrypoints: true'); - expect(stdout).toContain('errorDetails: true'); + case "detailed": + expect(stdout).toContain("entrypoints: true"); + expect(stdout).toContain("errorDetails: true"); break; - case 'errors-only': - expect(stdout).toContain('all: false'); - expect(stdout).toContain('errors: true'); + case "errors-only": + expect(stdout).toContain("all: false"); + expect(stdout).toContain("errors: true"); break; - case 'errors-warnings': - expect(stdout).toContain('all: false'); - expect(stdout).toContain('errors: true'); - expect(stdout).toContain('warnings: true'); + case "errors-warnings": + expect(stdout).toContain("all: false"); + expect(stdout).toContain("errors: true"); + expect(stdout).toContain("warnings: true"); break; - case 'minimal': - expect(stdout).toContain('modules: true'); - expect(stdout).toContain('maxModules: 0'); + case "minimal": + expect(stdout).toContain("modules: true"); + expect(stdout).toContain("maxModules: 0"); break; - case 'verbose': + case "verbose": expect(stdout).toContain("logging: 'verbose'"); break; - case 'none': - expect(stdout).toContain('all: false'); + case "none": + expect(stdout).toContain("all: false"); break; default: expect(stdout).toContain(`preset: '${preset}'`); diff --git a/test/build/stats/config/webpack.config.js b/test/build/stats/config/webpack.config.js index f4cce3b8d56..be63b5f8d22 100644 --- a/test/build/stats/config/webpack.config.js +++ b/test/build/stats/config/webpack.config.js @@ -1,8 +1,8 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { - mode: 'development', - entry: './index.js', - stats: 'normal', + mode: "development", + entry: "./index.js", + stats: "normal", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/stats/flags/stats.test.js b/test/build/stats/flags/stats.test.js index fee38ce4e70..5f2e652ee98 100644 --- a/test/build/stats/flags/stats.test.js +++ b/test/build/stats/flags/stats.test.js @@ -1,17 +1,25 @@ -'use strict'; +"use strict"; -const { run, isWebpack5, normalizeStderr, normalizeStdout } = require('../../../utils/test-utils'); +const { run, isWebpack5, normalizeStderr, normalizeStdout } = require("../../../utils/test-utils"); -const presets = ['normal', 'detailed', 'errors-only', 'errors-warnings', 'minimal', 'verbose', 'none']; +const presets = [ + "normal", + "detailed", + "errors-only", + "errors-warnings", + "minimal", + "verbose", + "none", +]; if (isWebpack5) { - presets.push('summary'); + presets.push("summary"); } -describe('stats flag', () => { +describe("stats flag", () => { for (const preset of presets) { it(`should accept --stats "${preset}"`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats', `${preset}`]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--stats", `${preset}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -20,31 +28,31 @@ describe('stats flag', () => { expect(stdout).toContain(`preset: '${preset}'`); } else { switch (preset) { - case 'normal': - expect(stdout).toContain('stats:'); + case "normal": + expect(stdout).toContain("stats:"); break; - case 'detailed': - expect(stdout).toContain('entrypoints: true'); - expect(stdout).toContain('errorDetails: true'); + case "detailed": + expect(stdout).toContain("entrypoints: true"); + expect(stdout).toContain("errorDetails: true"); break; - case 'errors-only': - expect(stdout).toContain('all: false'); - expect(stdout).toContain('errors: true'); + case "errors-only": + expect(stdout).toContain("all: false"); + expect(stdout).toContain("errors: true"); break; - case 'errors-warnings': - expect(stdout).toContain('all: false'); - expect(stdout).toContain('errors: true'); - expect(stdout).toContain('warnings: true'); + case "errors-warnings": + expect(stdout).toContain("all: false"); + expect(stdout).toContain("errors: true"); + expect(stdout).toContain("warnings: true"); break; - case 'minimal': - expect(stdout).toContain('modules: true'); - expect(stdout).toContain('maxModules: 0'); + case "minimal": + expect(stdout).toContain("modules: true"); + expect(stdout).toContain("maxModules: 0"); break; - case 'verbose': + case "verbose": expect(stdout).toContain("logging: 'verbose'"); break; - case 'none': - expect(stdout).toContain('all: false'); + case "none": + expect(stdout).toContain("all: false"); break; default: expect(stdout).toContain(`preset: '${preset}'`); @@ -53,8 +61,8 @@ describe('stats flag', () => { }); } - it('should accept stats as boolean', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats']); + it("should accept stats as boolean", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--stats"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -62,12 +70,12 @@ describe('stats flag', () => { if (isWebpack5) { expect(stdout).toContain("preset: 'normal'"); } else { - expect(stdout).toContain('stats:'); + expect(stdout).toContain("stats:"); } }); - it('should accept --no-stats as boolean', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--no-stats']); + it("should accept --no-stats as boolean", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--no-stats"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -75,15 +83,15 @@ describe('stats flag', () => { if (isWebpack5) { expect(stdout).toContain("preset: 'none'"); } else { - expect(stdout).toContain('all: false'); + expect(stdout).toContain("all: false"); } }); - it('should log error when an unknown flag stats value is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--stats', 'foo']); + it("should log error when an unknown flag stats value is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--stats", "foo"]); expect(exitCode).toEqual(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/build/stats/flags/webpack.config.js b/test/build/stats/flags/webpack.config.js index 90a7f8873af..eb5656d862a 100644 --- a/test/build/stats/flags/webpack.config.js +++ b/test/build/stats/flags/webpack.config.js @@ -1,7 +1,7 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { - mode: 'development', - entry: './index.js', + mode: "development", + entry: "./index.js", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/target/flag-test/target-flag.test.js b/test/build/target/flag-test/target-flag.test.js index 1846fe0db73..71b53e3515f 100644 --- a/test/build/target/flag-test/target-flag.test.js +++ b/test/build/target/flag-test/target-flag.test.js @@ -1,12 +1,21 @@ -'use strict'; -const { run, isWebpack5, normalizeStdout, normalizeStderr } = require('../../../utils/test-utils'); - -const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload']; - -describe('--target flag', () => { +"use strict"; +const { run, isWebpack5, normalizeStdout, normalizeStderr } = 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`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--target', `${val}`]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--target", `${val}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -19,7 +28,7 @@ describe('--target flag', () => { }); it(`should accept ${val} with -t alias`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-t', `${val}`]); + const { exitCode, stderr, stdout } = await run(__dirname, ["-t", `${val}`]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -33,52 +42,71 @@ describe('--target flag', () => { }); it(`should throw error with invalid value for --target`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--target', 'invalid']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--target", "invalid"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); if (isWebpack5) { - it('should allow multiple targets', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--target', 'node', '--target', 'async-node']); + it("should allow multiple targets", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target", + "node", + "--target", + "async-node", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`target: [ 'node', 'async-node' ]`); }); - it('should throw an error for invalid target in multiple syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--target', 'node', '--target', 'invalid']); + it("should throw an error for invalid target in multiple syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target", + "node", + "--target", + "invalid", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should throw an error for incompatible multiple targets', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--target', 'node', '--target', 'web']); + it("should throw an error for incompatible multiple targets", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target", + "node", + "--target", + "web", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should reset target from node to async-node with --target-reset', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--target-reset', '--target', 'async-node']); + it("should reset target from node to async-node with --target-reset", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target-reset", + "--target", + "async-node", + ]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); expect(stdout).toContain(`target: [ 'async-node' ]`); }); - it('should throw error if target is an empty array', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--target-reset']); + it("should throw error if target is an empty array", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--target-reset"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); } }); diff --git a/test/build/target/flag-test/webpack.config.js b/test/build/target/flag-test/webpack.config.js index 9e6e41805bf..3ef6a20b72d 100644 --- a/test/build/target/flag-test/webpack.config.js +++ b/test/build/target/flag-test/webpack.config.js @@ -1,8 +1,8 @@ -const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin"); module.exports = { - entry: './index.js', - mode: 'development', - target: 'node', + entry: "./index.js", + mode: "development", + target: "node", plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/target/node/main.js b/test/build/target/node/main.js index 2f859905116..4ef6e73abaa 100644 --- a/test/build/target/node/main.js +++ b/test/build/target/node/main.js @@ -1,2 +1,2 @@ -const url = require('url'); +const url = require("url"); console.log(url); diff --git a/test/build/target/node/new.js b/test/build/target/node/new.js index 2f859905116..4ef6e73abaa 100644 --- a/test/build/target/node/new.js +++ b/test/build/target/node/new.js @@ -1,2 +1,2 @@ -const url = require('url'); +const url = require("url"); console.log(url); diff --git a/test/build/target/node/node-test.test.js b/test/build/target/node/node-test.test.js index ff458dfc377..95dcc929d54 100644 --- a/test/build/target/node/node-test.test.js +++ b/test/build/target/node/node-test.test.js @@ -1,12 +1,12 @@ -'use strict'; -const { run, normalizeStderr } = require('../../../utils/test-utils'); +"use strict"; +const { run, normalizeStderr } = require("../../../utils/test-utils"); -describe('Node target', () => { - it('should emit the correct code', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js']); +describe("Node target", () => { + it("should emit the correct code", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); expect(stdout).toBeTruthy(); }); }); diff --git a/test/build/target/node/webpack.config.js b/test/build/target/node/webpack.config.js index 59b1da703f8..5742478fdf2 100644 --- a/test/build/target/node/webpack.config.js +++ b/test/build/target/node/webpack.config.js @@ -1,5 +1,5 @@ module.exports = { - entry: './main.js', - mode: 'development', - target: 'node', + entry: "./main.js", + mode: "development", + target: "node", }; diff --git a/test/build/unknown/unknown.test.js b/test/build/unknown/unknown.test.js index 68ca63b2864..5569953bd61 100644 --- a/test/build/unknown/unknown.test.js +++ b/test/build/unknown/unknown.test.js @@ -1,189 +1,202 @@ -'use strict'; +"use strict"; -const { run, normalizeStdout, normalizeStderr } = require('../../utils/test-utils'); +const { run, normalizeStdout, normalizeStderr } = require("../../utils/test-utils"); -describe('unknown behaviour', () => { - it('should log an error if an unknown flag is passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--unknown']); +describe("unknown behaviour", () => { + it("should log an error if an unknown flag is passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-u']); + it("should log an error if an unknown flag is passed #2", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-u"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed and includes =', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--unknown=foo']); + it("should log an error if an unknown flag is passed and includes =", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown=foo"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed #3', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-u', '--unknown']); + it("should log an error if an unknown flag is passed #3", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-u", "--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed #4', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-u', '-u']); + it("should log an error if an unknown flag is passed #4", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-u", "-u"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed #5', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-u', 'foo']); + it("should log an error if an unknown flag is passed #5", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-u", "foo"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed using "bundle" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', '--unknown']); + const { exitCode, stderr, stdout } = await run(__dirname, ["bundle", "--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed using "b" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['b', '--unknown']); + const { exitCode, stderr, stdout } = await run(__dirname, ["b", "--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed using "bundle" command #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--unknown', 'bundle']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown", "bundle"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed using "info" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--unknown']); + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed using "i" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['i', '--unknown']); + const { exitCode, stderr, stdout } = await run(__dirname, ["i", "--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed using "i" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--unknown', 'i']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown", "i"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error and respect --color flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--unknown', '--color'], { env: { FORCE_COLOR: true } }); + it("should log error and respect --color flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(2); - expect(stderr).toMatchSnapshot('stderr'); - expect(stdout).toMatchSnapshot('stdout'); + expect(stderr).toMatchSnapshot("stderr"); + expect(stdout).toMatchSnapshot("stdout"); }); - it('should log error for unknown flag and respect --no-color', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--unknown', '--no-color'], { env: { FORCE_COLOR: true } }); + it("should log error for unknown flag and respect --no-color", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown", "--no-color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(2); - expect(stderr).toMatchSnapshot('stderr'); - expect(stdout).toMatchSnapshot('stdout'); + expect(stderr).toMatchSnapshot("stderr"); + expect(stdout).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed and suggests the closest match to an unknown flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--entyr', './a.js']); + it("should log an error if an unknown flag is passed and suggests the closest match to an unknown flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--entyr", "./a.js"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--output-fileneme', '[name].js']); + it("should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #2", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--output-fileneme", + "[name].js", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #3', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--output-library-auxiliary-comment-commnjs']); + it("should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #3", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--output-library-auxiliary-comment-commnjs", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "bundle" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', '--entyr', './a.js']); + const { exitCode, stderr, stdout } = await run(__dirname, ["bundle", "--entyr", "./a.js"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "b" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['b', '--entyr', './a.js']); + const { exitCode, stderr, stdout } = await run(__dirname, ["b", "--entyr", "./a.js"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "info" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--outpyt']); + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--outpyt"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "i" command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['i', '--outpyt']); + const { exitCode, stderr, stdout } = await run(__dirname, ["i", "--outpyt"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error if an unknown command passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['qqq'], true, [], { TERM_PROGRAM: false }); + it("should log error if an unknown command passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["qqq"], true, [], { + TERM_PROGRAM: false, + }); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error and provide suggestion if an unknown command passed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serverr'], true, [], { TERM_PROGRAM: false }); + it("should log error and provide suggestion if an unknown command passed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["serverr"], true, [], { + TERM_PROGRAM: false, + }); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/build/zero-config/entry-absent/zero-config.test.js b/test/build/zero-config/entry-absent/zero-config.test.js index 8b3bf361318..715f360a0dd 100644 --- a/test/build/zero-config/entry-absent/zero-config.test.js +++ b/test/build/zero-config/entry-absent/zero-config.test.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('Zero Config tests', () => { - it('runs when config and entry are both absent', async () => { +describe("Zero Config tests", () => { + it("runs when config and entry are both absent", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(1); diff --git a/test/build/zero-config/entry-present/zero-config.test.js b/test/build/zero-config/entry-present/zero-config.test.js index 4597d246009..65520333582 100644 --- a/test/build/zero-config/entry-present/zero-config.test.js +++ b/test/build/zero-config/entry-present/zero-config.test.js @@ -1,14 +1,14 @@ -const { run } = require('../../../utils/test-utils'); +const { run } = require("../../../utils/test-utils"); -describe('Zero Config tests', () => { - it('runs when no config is supplied but entry is present', async () => { +describe("Zero Config tests", () => { + it("runs when no config is supplied but entry is present", async () => { const { exitCode, stderr, stdout } = await run(__dirname, []); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); // Should be able to find the entry file - expect(stdout).toContain('./src/index.js'); + expect(stdout).toContain("./src/index.js"); // Should output at the default output dir and filename - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); }); diff --git a/test/configtest/with-config-path/basic.config.js b/test/configtest/with-config-path/basic.config.js index bdaebdb6f26..a700197b9ca 100644 --- a/test/configtest/with-config-path/basic.config.js +++ b/test/configtest/with-config-path/basic.config.js @@ -1,5 +1,5 @@ module.exports = { - mode: 'development', - target: 'node', - stats: 'verbose', + mode: "development", + target: "node", + stats: "verbose", }; diff --git a/test/configtest/with-config-path/error.config.js b/test/configtest/with-config-path/error.config.js index 8e614cbed23..d4b60668433 100644 --- a/test/configtest/with-config-path/error.config.js +++ b/test/configtest/with-config-path/error.config.js @@ -1,5 +1,5 @@ module.exports = { - mode: 'dev', // error - target: 'node', - stats: 'normal', + mode: "dev", // error + target: "node", + stats: "normal", }; diff --git a/test/configtest/with-config-path/with-config-path.test.js b/test/configtest/with-config-path/with-config-path.test.js index a18a5877adc..530ce490fee 100644 --- a/test/configtest/with-config-path/with-config-path.test.js +++ b/test/configtest/with-config-path/with-config-path.test.js @@ -1,45 +1,54 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); describe("'configtest' command with the configuration path option", () => { - it('should validate webpack config successfully', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest', './basic.config.js']); + it("should validate webpack config successfully", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "configtest", + "./basic.config.js", + ]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should throw validation error', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest', './error.config.js']); + it("should throw validation error", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "configtest", + "./error.config.js", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should throw syntax error', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest', './syntax-error.config.js']); + it("should throw syntax error", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "configtest", + "./syntax-error.config.js", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it(`should validate the config with alias 't'`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['t', './error.config.js']); + const { exitCode, stderr, stdout } = await run(__dirname, ["t", "./error.config.js"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should throw error if configuration does not exist', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest', './a.js']); + it("should throw error if configuration does not exist", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["configtest", "./a.js"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr).split('\n')[0]).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr).split("\n")[0]).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/configtest/without-config-path-custom-extension/without-config-path.test.js b/test/configtest/without-config-path-custom-extension/without-config-path.test.js index a03239c9807..e0e61700a66 100644 --- a/test/configtest/without-config-path-custom-extension/without-config-path.test.js +++ b/test/configtest/without-config-path-custom-extension/without-config-path.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); describe("'configtest' command without the configuration path option", () => { - it.only('should validate default configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest']); + it.only("should validate default configuration", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["configtest"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/configtest/without-config-path-error/webpack.config.js b/test/configtest/without-config-path-error/webpack.config.js index 5dbbd664f31..4d2f03d5c8c 100644 --- a/test/configtest/without-config-path-error/webpack.config.js +++ b/test/configtest/without-config-path-error/webpack.config.js @@ -1,5 +1,5 @@ module.exports = { - mode: 'invalid', - target: 'node', - stats: 'verbose', + mode: "invalid", + target: "node", + stats: "verbose", }; diff --git a/test/configtest/without-config-path-error/without-config-path-error.test.js b/test/configtest/without-config-path-error/without-config-path-error.test.js index 4b1cec50515..a5502bc2622 100644 --- a/test/configtest/without-config-path-error/without-config-path-error.test.js +++ b/test/configtest/without-config-path-error/without-config-path-error.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); describe("'configtest' command without the configuration path option", () => { - it.only('should validate default configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest']); + it.only("should validate default configuration", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["configtest"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/configtest/without-config-path-multi-compiler-mode/webpack.config.js b/test/configtest/without-config-path-multi-compiler-mode/webpack.config.js index e198b8625cb..7390a6c5edd 100644 --- a/test/configtest/without-config-path-multi-compiler-mode/webpack.config.js +++ b/test/configtest/without-config-path-multi-compiler-mode/webpack.config.js @@ -1,12 +1,12 @@ module.exports = [ { - mode: 'development', - target: 'node', - stats: 'verbose', + mode: "development", + target: "node", + stats: "verbose", }, { - mode: 'development', - target: 'node', - stats: 'verbose', + mode: "development", + target: "node", + stats: "verbose", }, ]; diff --git a/test/configtest/without-config-path-multi-compiler-mode/without-config-path-multi-compiler-mode.test.js b/test/configtest/without-config-path-multi-compiler-mode/without-config-path-multi-compiler-mode.test.js index a03239c9807..e0e61700a66 100644 --- a/test/configtest/without-config-path-multi-compiler-mode/without-config-path-multi-compiler-mode.test.js +++ b/test/configtest/without-config-path-multi-compiler-mode/without-config-path-multi-compiler-mode.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); describe("'configtest' command without the configuration path option", () => { - it.only('should validate default configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest']); + it.only("should validate default configuration", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["configtest"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/configtest/without-config-path-no-configuration/without-config-path-no-configuration.test.js b/test/configtest/without-config-path-no-configuration/without-config-path-no-configuration.test.js index 4b1cec50515..a5502bc2622 100644 --- a/test/configtest/without-config-path-no-configuration/without-config-path-no-configuration.test.js +++ b/test/configtest/without-config-path-no-configuration/without-config-path-no-configuration.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); describe("'configtest' command without the configuration path option", () => { - it.only('should validate default configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest']); + it.only("should validate default configuration", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["configtest"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/configtest/without-config-path/webpack.config.js b/test/configtest/without-config-path/webpack.config.js index bdaebdb6f26..a700197b9ca 100644 --- a/test/configtest/without-config-path/webpack.config.js +++ b/test/configtest/without-config-path/webpack.config.js @@ -1,5 +1,5 @@ module.exports = { - mode: 'development', - target: 'node', - stats: 'verbose', + mode: "development", + target: "node", + stats: "verbose", }; diff --git a/test/configtest/without-config-path/without-config-path.test.js b/test/configtest/without-config-path/without-config-path.test.js index a03239c9807..e0e61700a66 100644 --- a/test/configtest/without-config-path/without-config-path.test.js +++ b/test/configtest/without-config-path/without-config-path.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); describe("'configtest' command without the configuration path option", () => { - it.only('should validate default configuration', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['configtest']); + it.only("should validate default configuration", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["configtest"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/help/help.test.js b/test/help/help.test.js index 61add1d701e..627a1ab9929 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -1,397 +1,430 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../utils/test-utils"); -describe('help', () => { +describe("help", () => { it('should show help information using the "--help" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it.skip('should show help information using the "--help" option with the "verbose" value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help', 'verbose']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help", "verbose"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it.skip('should show help information using the "--help" option with the "verbose" value #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help=verbose']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help=verbose"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should show help information using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help']); + it("should show help information using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show the same information using the "--help" option and command syntax', async () => { - const { exitCode: exitCodeFromOption, stderr: stderrFromOption, stdout: stdoutFromOption } = await run(__dirname, ['--help']); + const { + exitCode: exitCodeFromOption, + stderr: stderrFromOption, + stdout: stdoutFromOption, + } = await run(__dirname, ["--help"]); const { exitCode: exitCodeFromCommandSyntax, stderr: stderrFromCommandSyntax, stdout: stdoutFromCommandSyntax, - } = await run(__dirname, ['help']); + } = await run(__dirname, ["help"]); expect(exitCodeFromOption).toBe(0); expect(exitCodeFromCommandSyntax).toBe(0); - expect(normalizeStderr(stderrFromOption)).toMatchSnapshot('stderr from option'); - expect(normalizeStderr(stderrFromCommandSyntax)).toMatchSnapshot('stderr from command syntax'); + expect(normalizeStderr(stderrFromOption)).toMatchSnapshot("stderr from option"); + expect(normalizeStderr(stderrFromCommandSyntax)).toMatchSnapshot( + "stderr from command syntax", + ); expect(stdoutFromOption).toBe(stdoutFromCommandSyntax); - expect(normalizeStdout(stdoutFromOption)).toMatchSnapshot('stdout from option'); - expect(normalizeStdout(stdoutFromCommandSyntax)).toMatchSnapshot('stdout from command sytnax'); + expect(normalizeStdout(stdoutFromOption)).toMatchSnapshot("stdout from option"); + expect(normalizeStdout(stdoutFromCommandSyntax)).toMatchSnapshot( + "stdout from command sytnax", + ); }); it('should show help information and respect the "--color" flag using the "--help" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help', '--color'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).toContain('\x1b[1m'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).toContain("\x1b[1m"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information and respect the "--no-color" flag using the "--help" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help', '--no-color'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help", "--no-color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); const commands = [ { - name: 'init', - alias: ['create', 'new', 'c', 'n'], + name: "init", + alias: ["create", "new", "c", "n"], }, { - name: 'info', - alias: 'i', + name: "info", + alias: "i", }, { - name: 'loader', - alias: 'l', + name: "loader", + alias: "l", }, { - name: 'migrate', - alias: 'm', + name: "migrate", + alias: "m", }, { - name: 'plugin', - alias: 'p', + name: "plugin", + alias: "p", }, { - name: 'configtest', - alias: 't', + name: "configtest", + alias: "t", }, { - name: 'watch', - alias: 'w', + name: "watch", + alias: "w", }, { - name: 'serve', - alias: ['server', 's'], + name: "serve", + alias: ["server", "s"], }, { - name: 'build', - alias: 'b', + name: "build", + alias: "b", }, ]; commands.forEach(({ name, alias }) => { it(`should show help information for '${name}' command using the "--help" option`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [name, '--help']); + const { exitCode, stderr, stdout } = await run(__dirname, [name, "--help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it.skip(`should show help information for '${name}' command using the "--help verbose" option`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [name, '--help', 'verbose']); + const { exitCode, stderr, stdout } = await run(__dirname, [name, "--help", "verbose"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it(`should show help information for '${name}' command using command syntax`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', name]); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", name]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it(`should show help information for '${name}' and respect the "--color" flag using the "--help" option`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [name, '--help', '--color'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, [name, "--help", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).toContain('\x1b[1m'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).toContain("\x1b[1m"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it(`should show help information for '${name}' and respect the "--no-color" flag using the "--help" option`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [name, '--help', '--no-color'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run( + __dirname, + [name, "--help", "--no-color"], + { env: { FORCE_COLOR: true } }, + ); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).not.toContain('\x1b[1m'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).not.toContain("\x1b[1m"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); const alises = Array.isArray(alias) ? alias : [alias]; alises.forEach((alias) => { it(`should show help information for '${alias}' command using the "--help" option`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [alias, '--help']); + const { exitCode, stderr, stdout } = await run(__dirname, [alias, "--help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it.skip(`should show help information for '${alias}' command using the "--help verbose" option`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [alias, '--help', 'verbose']); + const { exitCode, stderr, stdout } = await run(__dirname, [ + alias, + "--help", + "verbose", + ]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it(`should show help information for '${alias}' command using command syntax`, async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', alias]); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", alias]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); }); - it('should show help information with options for sub commands', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--help']); + it("should show help information with options for sub commands", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information and taking precedence when "--help" and "--version" option using together', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help', '--version']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --mode" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--mode']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--mode"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --target" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--target']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--target"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --stats" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--stats']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--stats"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --no-stats" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--no-stats']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--no-stats"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --mode" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--mode']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--mode"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help serve --mode" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'serve', '--mode']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "serve", "--mode"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --color" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--color'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).toContain('\x1b[1m'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).toContain("\x1b[1m"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --no-color" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--no-color'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--no-color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help serve --color" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'serve', '--color'], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "serve", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).toContain('\x1b[1m'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).toContain("\x1b[1m"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help serve --no-color" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'serve', '--no-color']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "serve", "--no-color"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help --version" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--version']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should show help information using the "help -v" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '-v']); + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "-v"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log error for invalid command using the "--help" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help', 'myCommand']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help", "myCommand"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log error for invalid command using the "--help" option #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--flag', '--help']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--flag", "--help"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log error for invalid command using the "--help" option #3', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--flag', '--help']); + const { exitCode, stderr, stdout } = await run(__dirname, ["serve", "--flag", "--help"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error for unknown command using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'myCommand']); + it("should log error for unknown command using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "myCommand"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error for unknown command using command syntax #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'verbose']); + it("should log error for unknown command using command syntax #2", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "verbose"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error for unknown option using command syntax #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--made']); + it("should log error for unknown option using command syntax #2", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--made"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error for unknown option using command syntax #3', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'serve', '--made']); + it("should log error for unknown option using command syntax #3", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "serve", "--made"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error for unknown option using command syntax #4', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'bui', '--mode']); + it("should log error for unknown option using command syntax #4", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "bui", "--mode"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error for invalid command using command syntax #3', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', '--mode', 'serve']); + it("should log error for invalid command using command syntax #3", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--mode", "serve"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error for invalid command using command syntax #4', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['help', 'serve', '--mode', '--mode']); + it("should log error for invalid command using command syntax #4", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "help", + "serve", + "--mode", + "--mode", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log error for invalid flag with the "--help" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help', '--my-flag']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help", "--my-flag"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log error for invalid flag with the "--help" option #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help', 'init', 'info']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help", "init", "info"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log error for invalid flag with the "--help" option #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--help=']); + const { exitCode, stderr, stdout } = await run(__dirname, ["--help="]); expect(exitCode).toBe(2); expect(stderr).toMatchSnapshot(); diff --git a/test/info/info-output.test.js b/test/info/info-output.test.js index 6039a3bcbc4..ddc1b083af5 100644 --- a/test/info/info-output.test.js +++ b/test/info/info-output.test.js @@ -1,35 +1,35 @@ -'use strict'; +"use strict"; -const { join } = require('path'); -const { run } = require('../utils/test-utils'); +const { join } = require("path"); +const { run } = require("../utils/test-utils"); -describe('basic info usage', () => { - it('gets info without flags', async () => { - const { exitCode, stdout, stderr } = await run(__dirname, ['info']); +describe("basic info usage", () => { + it("gets info without flags", async () => { + const { exitCode, stdout, stderr } = await run(__dirname, ["info"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('System:'); - expect(stdout).toContain('Node'); - expect(stdout).toContain('npm'); - expect(stdout).toContain('Yarn'); + expect(stdout).toContain("System:"); + expect(stdout).toContain("Node"); + expect(stdout).toContain("npm"); + expect(stdout).toContain("Yarn"); }); - it('gets more info in project root', async () => { - const { exitCode, stderr, stdout } = await run(join(__dirname, '../../'), ['info']); + it("gets more info in project root", async () => { + const { exitCode, stderr, stdout } = await run(join(__dirname, "../../"), ["info"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('System:'); - expect(stdout).toContain('Monorepos:'); - expect(stdout).toContain('Packages:'); - expect(stdout).toContain('Node'); - expect(stdout).toContain('npm'); - expect(stdout).toContain('Yarn'); + expect(stdout).toContain("System:"); + expect(stdout).toContain("Monorepos:"); + expect(stdout).toContain("Packages:"); + expect(stdout).toContain("Node"); + expect(stdout).toContain("npm"); + expect(stdout).toContain("Yarn"); }); - it('gets info as json', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--output=json']); + it("gets info as json", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--output=json"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -37,25 +37,25 @@ describe('basic info usage', () => { const parse = () => { const output = JSON.parse(stdout); - expect(output['System']).toBeTruthy(); - expect(output['Binaries']).toBeTruthy(); - expect(output['System']['OS']).toBeTruthy(); - expect(output['System']['CPU']).toBeTruthy(); + expect(output["System"]).toBeTruthy(); + expect(output["Binaries"]).toBeTruthy(); + expect(output["System"]["OS"]).toBeTruthy(); + expect(output["System"]["CPU"]).toBeTruthy(); }; expect(parse).not.toThrow(); }); - it('gets info as markdown', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--output', 'markdown']); + it("gets info as markdown", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--output", "markdown"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('## System:'); + expect(stdout).toContain("## System:"); }); - it('shows a warning if an invalid value is supplied', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--output', 'unknown']); + it("shows a warning if an invalid value is supplied", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--output", "unknown"]); expect(exitCode).toBe(2); expect(stderr).toContain(`'unknown' is not a valid value for output`); @@ -63,10 +63,10 @@ describe('basic info usage', () => { }); it("recognizes '-o' as an alias for '--output'", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '-o', 'markdown']); + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "-o", "markdown"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toContain('## System:'); + expect(stdout).toContain("## System:"); }); }); diff --git a/test/info/info-unknown.test.js b/test/info/info-unknown.test.js index 2599a8083f2..81f3be30819 100644 --- a/test/info/info-unknown.test.js +++ b/test/info/info-unknown.test.js @@ -1,8 +1,8 @@ -const { run } = require('../utils/test-utils'); +const { run } = require("../utils/test-utils"); -describe('should handle unknown args', () => { - it('shows an appropriate warning on supplying unknown args', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--unknown']); +describe("should handle unknown args", () => { + it("shows an appropriate warning on supplying unknown args", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--unknown"]); expect(exitCode).toBe(2); expect(stderr).toContain("Error: Unknown option '--unknown'"); diff --git a/test/init/init.test.js b/test/init/init.test.js index 20b9967b84e..ef75f160e59 100644 --- a/test/init/init.test.js +++ b/test/init/init.test.js @@ -1,44 +1,49 @@ -const os = require('os'); -const path = require('path'); -const { mkdirSync, existsSync, readFileSync } = require('fs'); -const { join, resolve } = require('path'); -const { isWindows, run, runPromptWithAnswers, uniqueDirectoryForTest } = require('../utils/test-utils'); +const os = require("os"); +const path = require("path"); +const { mkdirSync, existsSync, readFileSync } = require("fs"); +const { join, resolve } = require("path"); +const { + isWindows, + run, + runPromptWithAnswers, + uniqueDirectoryForTest, +} = require("../utils/test-utils"); jest.setTimeout(480000); -const ENTER = '\x0D'; -const DOWN = '\x1B\x5B\x42'; +const ENTER = "\x0D"; +const DOWN = "\x1B\x5B\x42"; // Helper to read from package.json in a given path const readFromPkgJSON = (path) => { - const pkgJSONPath = join(path, 'package.json'); + const pkgJSONPath = join(path, "package.json"); if (!existsSync(pkgJSONPath)) { return {}; } - const pkgJSON = JSON.parse(readFileSync(pkgJSONPath, 'utf8')); + const pkgJSON = JSON.parse(readFileSync(pkgJSONPath, "utf8")); const { devDependencies: devDeps } = pkgJSON; // Update devDeps versions to be x.x.x to prevent frequent snapshot updates - Object.keys(devDeps).forEach((dep) => (devDeps[dep] = 'x.x.x')); + Object.keys(devDeps).forEach((dep) => (devDeps[dep] = "x.x.x")); return { ...pkgJSON, devDependencies: devDeps }; }; // Helper to read from webpack.config.js in a given path -const readFromWebpackConfig = (path) => readFileSync(join(path, 'webpack.config.js'), 'utf8'); +const readFromWebpackConfig = (path) => readFileSync(join(path, "webpack.config.js"), "utf8"); -describe('init command', () => { - it('should generate default project when nothing is passed', async () => { +describe("init command", () => { + it("should generate default project when nothing is passed", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(assetsPath, ['init', '--force']); + const { stdout, stderr } = await run(assetsPath, ["init", "--force"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -48,15 +53,15 @@ describe('init command', () => { expect(readFromPkgJSON(assetsPath)).toMatchSnapshot(); }); - it('should generate project when generationPath is supplied', async () => { + it("should generate project when generationPath is supplied", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(__dirname, ['init', assetsPath, '--force']); + const { stdout, stderr } = await run(__dirname, ["init", assetsPath, "--force"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -66,16 +71,18 @@ describe('init command', () => { expect(readFromPkgJSON(assetsPath)).toMatchSnapshot(); }); - it('should generate folders if non existing generation path is given', async () => { + it("should generate folders if non existing generation path is given", async () => { const assetsPath = path.resolve(os.tmpdir(), Date.now().toString()); - const { stdout, stderr } = await run(__dirname, ['init', assetsPath, '--force']); + const { stdout, stderr } = await run(__dirname, ["init", assetsPath, "--force"]); - expect(stdout).toContain("generation path doesn't exist, required folders will be created."); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain( + "generation path doesn't exist, required folders will be created.", + ); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -85,16 +92,18 @@ describe('init command', () => { expect(readFromPkgJSON(assetsPath)).toMatchSnapshot(); }); - it('should configure assets modules by default', async () => { + it("should configure assets modules by default", async () => { const assetsPath = path.resolve(os.tmpdir(), Date.now().toString()); - const { stdout, stderr } = await run(__dirname, ['init', assetsPath, '--force']); + const { stdout, stderr } = await run(__dirname, ["init", assetsPath, "--force"]); - expect(stdout).toContain("generation path doesn't exist, required folders will be created."); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain( + "generation path doesn't exist, required folders will be created.", + ); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -107,16 +116,20 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should ask question when wrong template is supplied', async () => { + it("should ask question when wrong template is supplied", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ['init', '--force', '--template=apple'], [`${ENTER}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["init", "--force", "--template=apple"], + [`${ENTER}`], + ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('apple is not a valid template, please select one from below'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("apple is not a valid template, please select one from below"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -126,20 +139,20 @@ describe('init command', () => { expect(readFromPkgJSON(assetsPath)).toMatchSnapshot(); }); - it('should generate typescript project correctly', async () => { + it("should generate typescript project correctly", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], + ["init"], [`${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); - expect(stderr).toContain('tsconfig.json'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); + expect(stderr).toContain("tsconfig.json"); // Test files - const files = ['package.json', 'src', 'src/index.ts', 'webpack.config.js', 'tsconfig.json']; + const files = ["package.json", "src", "src/index.ts", "webpack.config.js", "tsconfig.json"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -152,20 +165,20 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should generate ES6 project correctly', async () => { + it("should generate ES6 project correctly", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], + ["init"], [`${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); - expect(stderr).toContain('.babelrc'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); + expect(stderr).toContain(".babelrc"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js', '.babelrc']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js", ".babelrc"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -178,19 +191,27 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should use sass in project when selected', async () => { + it("should use sass in project when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], - [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `n${ENTER}`], + ["init"], + [ + `${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `${DOWN}${DOWN}${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + ], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -203,19 +224,33 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should use sass with postcss in project when selected', async () => { + it("should use sass with postcss in project when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], - [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `y${ENTER}`, `n${ENTER}`], + ["init"], + [ + `${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `${DOWN}${DOWN}${ENTER}`, + `n${ENTER}`, + `y${ENTER}`, + `n${ENTER}`, + ], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js', 'postcss.config.js']; + const files = [ + "package.json", + "src", + "src/index.js", + "webpack.config.js", + "postcss.config.js", + ]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -228,19 +263,27 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should use mini-css-extract-plugin when selected', async () => { + it("should use mini-css-extract-plugin when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], - [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `y${ENTER}`], + ["init"], + [ + `${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `${DOWN}${DOWN}${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `y${ENTER}`, + ], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -253,19 +296,33 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should use sass and css with postcss in project when selected', async () => { + it("should use sass and css with postcss in project when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], - [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${DOWN}${ENTER}`, `y${ENTER}`, `y${ENTER}`, `n${ENTER}`], + ["init"], + [ + `${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `${DOWN}${DOWN}${ENTER}`, + `y${ENTER}`, + `y${ENTER}`, + `n${ENTER}`, + ], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js', 'postcss.config.js']; + const files = [ + "package.json", + "src", + "src/index.js", + "webpack.config.js", + "postcss.config.js", + ]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -278,19 +335,27 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should use less in project when selected', async () => { + it("should use less in project when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], - [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `n${ENTER}`], + ["init"], + [ + `${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `${DOWN}${DOWN}${DOWN}${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + ], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -303,19 +368,27 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should use stylus in project when selected', async () => { + it("should use stylus in project when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], - [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${DOWN}${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `n${ENTER}`], + ["init"], + [ + `${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `${DOWN}${DOWN}${DOWN}${DOWN}${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + `n${ENTER}`, + ], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -328,16 +401,20 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should configure WDS as opted', async () => { + it("should configure WDS as opted", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ['init'], [ENTER, ENTER, `n${ENTER}`, ENTER]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["init"], + [ENTER, ENTER, `n${ENTER}`, ENTER], + ); - expect(stdout).toContain('Do you want to use webpack-dev-server?'); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Do you want to use webpack-dev-server?"); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); }); @@ -349,19 +426,25 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should use postcss in project when selected', async () => { + it("should use postcss in project when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); const { stdout, stderr } = await runPromptWithAnswers( assetsPath, - ['init'], + ["init"], [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${ENTER}`, ENTER, `n${ENTER}`], ); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js', 'postcss.config.js']; + const files = [ + "package.json", + "src", + "src/index.js", + "webpack.config.js", + "postcss.config.js", + ]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -374,16 +457,22 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should configure html-webpack-plugin as opted', async () => { + it("should configure html-webpack-plugin as opted", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ['init'], [ENTER, `n${ENTER}`, ENTER, ENTER]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["init"], + [ENTER, `n${ENTER}`, ENTER, ENTER], + ); - expect(stdout).toContain('Do you want to simplify the creation of HTML files for your bundle?'); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain( + "Do you want to simplify the creation of HTML files for your bundle?", + ); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -396,31 +485,31 @@ describe('init command', () => { expect(readFromWebpackConfig(assetsPath)).toMatchSnapshot(); }); - it('should throw if the current path is not writable', async () => { + it("should throw if the current path is not writable", async () => { if (isWindows) { return; } const assetsPath = await uniqueDirectoryForTest(); - const projectPath = join(assetsPath, 'non-writable-path'); + const projectPath = join(assetsPath, "non-writable-path"); mkdirSync(projectPath, 0o500); - const { exitCode, stderr } = await run(projectPath, ['init', 'my-app'], { reject: false }); + const { exitCode, stderr } = await run(projectPath, ["init", "my-app"], { reject: false }); expect(exitCode).toBe(2); - expect(stderr).toContain('Failed to create directory'); + expect(stderr).toContain("Failed to create directory"); }); it("should work with 'new' alias", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(assetsPath, ['new', '--force']); + const { stdout, stderr } = await run(assetsPath, ["new", "--force"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -432,13 +521,13 @@ describe('init command', () => { it("should work with 'create' alias", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(assetsPath, ['create', '--force']); + const { stdout, stderr } = await run(assetsPath, ["create", "--force"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -450,13 +539,13 @@ describe('init command', () => { it("should work with 'c' alias", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(assetsPath, ['c', '--force']); + const { stdout, stderr } = await run(assetsPath, ["c", "--force"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -468,13 +557,13 @@ describe('init command', () => { it("should work with 'n' alias", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(assetsPath, ['n', '--force']); + const { stdout, stderr } = await run(assetsPath, ["n", "--force"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -486,13 +575,13 @@ describe('init command', () => { it("recognizes '-t' as an alias for '--template'", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(assetsPath, ['init', '-t', 'default', '--force']); + const { stdout, stderr } = await run(assetsPath, ["init", "-t", "default", "--force"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); @@ -504,13 +593,13 @@ describe('init command', () => { it("recognizes '-f' as an alias for '--force'", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await run(assetsPath, ['init', '-f']); + const { stdout, stderr } = await run(assetsPath, ["init", "-f"]); - expect(stdout).toContain('Project has been initialised with webpack!'); - expect(stderr).toContain('webpack.config.js'); + expect(stdout).toContain("Project has been initialised with webpack!"); + expect(stderr).toContain("webpack.config.js"); // Test files - const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js']; + const files = ["package.json", "src", "src/index.js", "webpack.config.js"]; files.forEach((file) => { expect(existsSync(resolve(assetsPath, file))).toBeTruthy(); diff --git a/test/loader/error-test/loader-error.test.js b/test/loader/error-test/loader-error.test.js index 36b700de781..80c402a27cf 100644 --- a/test/loader/error-test/loader-error.test.js +++ b/test/loader/error-test/loader-error.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; // eslint-disable-next-line node/no-unpublished-require -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('loader error regression test for #1581', () => { +describe("loader error regression test for #1581", () => { it(`should not ignore loader's error produce a failing build`, async () => { // Ignoring assertion on stderr because ts-loader is producing depreciation warnings // with webpack@v5.0.0-beta.24 -> https://github.com/TypeStrong/ts-loader/issues/1169 const { stdout, exitCode } = await run(__dirname, []); expect(exitCode).not.toEqual(0); - expect(stdout).toContain('[1 error]'); + expect(stdout).toContain("[1 error]"); expect(stdout).toContain(`Cannot assign to 'foobar' because it is a constant`); }); }); diff --git a/test/loader/error-test/src/index.ts b/test/loader/error-test/src/index.ts index 39967926fa2..f7c6b335f8e 100644 --- a/test/loader/error-test/src/index.ts +++ b/test/loader/error-test/src/index.ts @@ -1,4 +1,4 @@ -const foobar = 'foobar'; +const foobar = "foobar"; // eslint-disable-next-line no-const-assign -foobar = 'barbaz'; // Error! +foobar = "barbaz"; // Error! console.log(foobar); diff --git a/test/loader/error-test/webpack.config.js b/test/loader/error-test/webpack.config.js index 5aca8bbcd77..8c50d352ad7 100644 --- a/test/loader/error-test/webpack.config.js +++ b/test/loader/error-test/webpack.config.js @@ -1,23 +1,23 @@ -const path = require('path'); +const path = require("path"); module.exports = { - mode: 'development', + mode: "development", entry: { - bundle: './src/index.ts', + bundle: "./src/index.ts", }, output: { - path: path.resolve(__dirname, 'dist'), - filename: '[name].js', + path: path.resolve(__dirname, "dist"), + filename: "[name].js", }, module: { rules: [ { test: /.(ts|tsx)?$/, - loader: 'ts-loader', - include: [path.resolve(__dirname, 'src')], + loader: "ts-loader", + include: [path.resolve(__dirname, "src")], exclude: [/node_modules/], }, ], diff --git a/test/loader/loader.test.js b/test/loader/loader.test.js index 4c9391aae2a..0656845c50a 100644 --- a/test/loader/loader.test.js +++ b/test/loader/loader.test.js @@ -1,38 +1,43 @@ -'use strict'; - -const { existsSync } = require('fs'); -const { join, resolve } = require('path'); -const { run, runPromptWithAnswers, uniqueDirectoryForTest, normalizeStdout } = require('../utils/test-utils'); - -const firstPrompt = '? Loader name (my-loader)'; -const ENTER = '\x0D'; +"use strict"; + +const { existsSync } = require("fs"); +const { join, resolve } = require("path"); +const { + run, + runPromptWithAnswers, + uniqueDirectoryForTest, + normalizeStdout, +} = require("../utils/test-utils"); + +const firstPrompt = "? Loader name (my-loader)"; +const ENTER = "\x0D"; const dataForTests = (rootAssetsPath) => ({ - loaderName: 'test-loader', - loaderPath: join(rootAssetsPath, 'test-loader'), - defaultLoaderPath: join(rootAssetsPath, 'my-loader'), - genPath: join(rootAssetsPath, 'test-assets'), - customLoaderPath: join(rootAssetsPath, 'test-assets', 'loaderName'), + loaderName: "test-loader", + loaderPath: join(rootAssetsPath, "test-loader"), + defaultLoaderPath: join(rootAssetsPath, "my-loader"), + genPath: join(rootAssetsPath, "test-assets"), + customLoaderPath: join(rootAssetsPath, "test-assets", "loaderName"), }); -describe('loader command', () => { - it('should ask the loader name when invoked', async () => { +describe("loader command", () => { + it("should ask the loader name when invoked", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ['loader']); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["loader"]); expect(stdout).toBeTruthy(); expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain(firstPrompt); }); - it('should scaffold loader with default name if no loader name provided', async () => { + it("should scaffold loader with default name if no loader name provided", async () => { const assetsPath = await uniqueDirectoryForTest(); const { defaultLoaderPath } = dataForTests(assetsPath); - let { stdout } = await runPromptWithAnswers(assetsPath, ['loader'], [`${ENTER}`]); + let { stdout } = await runPromptWithAnswers(assetsPath, ["loader"], [`${ENTER}`]); expect(normalizeStdout(stdout)).toContain(firstPrompt); // Skip test in case installation fails - if (!existsSync(resolve(defaultLoaderPath, './yarn.lock'))) { + if (!existsSync(resolve(defaultLoaderPath, "./yarn.lock"))) { return; } @@ -40,29 +45,40 @@ describe('loader command', () => { expect(existsSync(defaultLoaderPath)).toBeTruthy(); // All test files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(defaultLoaderPath, file)).toBeTruthy(); }); // Check if the the generated loader works successfully - const path = resolve(__dirname, './my-loader/examples/simple/'); + const path = resolve(__dirname, "./my-loader/examples/simple/"); ({ stdout } = await run(path, [])); - expect(stdout).toContain('my-loader'); + expect(stdout).toContain("my-loader"); }); - it('should scaffold loader template with a given name', async () => { + it("should scaffold loader template with a given name", async () => { const assetsPath = await uniqueDirectoryForTest(); const { loaderName, loaderPath } = dataForTests(assetsPath); - let { stdout } = await runPromptWithAnswers(assetsPath, ['loader'], [`${loaderName}${ENTER}`]); + let { stdout } = await runPromptWithAnswers( + assetsPath, + ["loader"], + [`${loaderName}${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); // Skip test in case installation fails - if (!existsSync(resolve(loaderPath, './yarn.lock'))) { + if (!existsSync(resolve(loaderPath, "./yarn.lock"))) { return; } @@ -70,29 +86,40 @@ describe('loader command', () => { expect(existsSync(loaderPath)).toBeTruthy(); // All test files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(loaderPath, file)).toBeTruthy(); }); // Check if the the generated loader works successfully - const path = resolve(__dirname, './test-loader/examples/simple/'); + const path = resolve(__dirname, "./test-loader/examples/simple/"); ({ stdout } = await run(path, [])); - expect(stdout).toContain('test-loader'); + expect(stdout).toContain("test-loader"); }); - it('should scaffold loader template in the specified path', async () => { + it("should scaffold loader template in the specified path", async () => { const assetsPath = await uniqueDirectoryForTest(); const { loaderName, customLoaderPath } = dataForTests(assetsPath); - let { stdout } = await runPromptWithAnswers(assetsPath, ['loader', 'test-assets'], [`${loaderName}${ENTER}`]); + let { stdout } = await runPromptWithAnswers( + assetsPath, + ["loader", "test-assets"], + [`${loaderName}${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); // Skip test in case installation fails - if (!existsSync(resolve(customLoaderPath, './yarn.lock'))) { + if (!existsSync(resolve(customLoaderPath, "./yarn.lock"))) { return; } @@ -100,30 +127,41 @@ describe('loader command', () => { expect(existsSync(customLoaderPath)).toBeTruthy(); // All test files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(customLoaderPath, file)).toBeTruthy(); }); // Check if the the generated loader works successfully - const path = resolve(customLoaderPath, './examples/simple/'); + const path = resolve(customLoaderPath, "./examples/simple/"); ({ stdout } = await run(path, [])); - expect(stdout).toContain('test-loader'); + expect(stdout).toContain("test-loader"); }); - it('should scaffold loader template in the current directory', async () => { + it("should scaffold loader template in the current directory", async () => { const assetsPath = await uniqueDirectoryForTest(); const { loaderName, customLoaderPath } = dataForTests(assetsPath); - let { stdout } = await runPromptWithAnswers(assetsPath, ['loader', './'], [`${loaderName}${ENTER}`]); + let { stdout } = await runPromptWithAnswers( + assetsPath, + ["loader", "./"], + [`${loaderName}${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); // Skip test in case installation fails - if (!existsSync(resolve(customLoaderPath, './yarn.lock'))) { + if (!existsSync(resolve(customLoaderPath, "./yarn.lock"))) { return; } @@ -131,36 +169,47 @@ describe('loader command', () => { expect(existsSync(customLoaderPath)).toBeTruthy(); // All test files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(customLoaderPath, file)).toBeTruthy(); }); // Check if the the generated loader works successfully - const path = resolve(customLoaderPath, './examples/simple/'); + const path = resolve(customLoaderPath, "./examples/simple/"); ({ stdout } = await run(path, [])); - expect(stdout).toContain('test-loader'); + expect(stdout).toContain("test-loader"); }); - it('should prompt on supplying an invalid template', async () => { + it("should prompt on supplying an invalid template", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stderr } = await runPromptWithAnswers(assetsPath, ['loader', '--template=unknown']); + const { stderr } = await runPromptWithAnswers(assetsPath, ["loader", "--template=unknown"]); - expect(stderr).toContain('unknown is not a valid template'); + expect(stderr).toContain("unknown is not a valid template"); }); it("recognizes '-t' as an alias for '--template'", async () => { const assetsPath = await uniqueDirectoryForTest(); const { defaultLoaderPath } = dataForTests(assetsPath); - let { stdout } = await runPromptWithAnswers(assetsPath, ['loader', '-t', 'default'], [`${ENTER}`]); + let { stdout } = await runPromptWithAnswers( + assetsPath, + ["loader", "-t", "default"], + [`${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); // Skip test in case installation fails - if (!existsSync(resolve(defaultLoaderPath, './yarn.lock'))) { + if (!existsSync(resolve(defaultLoaderPath, "./yarn.lock"))) { return; } @@ -168,17 +217,24 @@ describe('loader command', () => { expect(existsSync(defaultLoaderPath)).toBeTruthy(); // All test files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(defaultLoaderPath, file)).toBeTruthy(); }); // Check if the the generated loader works successfully - const path = resolve(__dirname, './my-loader/examples/simple/'); + const path = resolve(__dirname, "./my-loader/examples/simple/"); ({ stdout } = await run(path, [])); - expect(stdout).toContain('my-loader'); + expect(stdout).toContain("my-loader"); }); }); diff --git a/test/loader/warning-test/loader-warning.test.js b/test/loader/warning-test/loader-warning.test.js index 317eadb8005..30da26499aa 100644 --- a/test/loader/warning-test/loader-warning.test.js +++ b/test/loader/warning-test/loader-warning.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { run } = require('../../utils/test-utils'); +const { run } = require("../../utils/test-utils"); -describe('loader warning test', () => { +describe("loader warning test", () => { it(`should not ignore loader's warning and exit with a non zero exit code`, async () => { const { stdout, exitCode } = await run(__dirname, [], false); - expect(stdout).toContain('[1 warning]'); - expect(stdout).toContain('This is a warning'); + expect(stdout).toContain("[1 warning]"); + expect(stdout).toContain("This is a warning"); expect(exitCode).toEqual(0); }); }); diff --git a/test/loader/warning-test/my-loader.js b/test/loader/warning-test/my-loader.js index 042520fc4a4..d9b32f45457 100644 --- a/test/loader/warning-test/my-loader.js +++ b/test/loader/warning-test/my-loader.js @@ -1,5 +1,5 @@ module.exports = function loader(source) { const { emitWarning } = this; - emitWarning('This is a warning'); + emitWarning("This is a warning"); return source; }; diff --git a/test/loader/warning-test/src/main.js b/test/loader/warning-test/src/main.js index fbcad03c6af..d89f4de2697 100644 --- a/test/loader/warning-test/src/main.js +++ b/test/loader/warning-test/src/main.js @@ -1,2 +1,2 @@ -require('../my-loader'); -console.log('loader warning test'); +require("../my-loader"); +console.log("loader warning test"); diff --git a/test/loader/warning-test/webpack.config.js b/test/loader/warning-test/webpack.config.js index 15f03beb9c8..f66fba9b0c2 100644 --- a/test/loader/warning-test/webpack.config.js +++ b/test/loader/warning-test/webpack.config.js @@ -1,33 +1,33 @@ -const path = require('path'); +const path = require("path"); module.exports = { - mode: 'development', + mode: "development", entry: { - bundle: './src/main.js', + bundle: "./src/main.js", }, output: { - path: path.resolve(__dirname, 'dist'), - filename: '[name].js', + path: path.resolve(__dirname, "dist"), + filename: "[name].js", }, module: { rules: [ { test: /.(js|jsx)?$/, - loader: 'my-loader', - include: [path.resolve(__dirname, 'src')], + loader: "my-loader", + include: [path.resolve(__dirname, "src")], exclude: [/node_modules/], }, ], }, resolveLoader: { alias: { - 'my-loader': require.resolve('./my-loader'), + "my-loader": require.resolve("./my-loader"), }, }, performance: { - hints: 'warning', + hints: "warning", }, }; diff --git a/test/plugin/plugin.test.js b/test/plugin/plugin.test.js index eca5c35190b..62dcb5023ca 100644 --- a/test/plugin/plugin.test.js +++ b/test/plugin/plugin.test.js @@ -1,30 +1,35 @@ -const { existsSync, mkdirSync } = require('fs'); -const { join, resolve } = require('path'); -const { run, runPromptWithAnswers, uniqueDirectoryForTest, normalizeStdout } = require('../utils/test-utils'); - -const ENTER = '\x0D'; - -const firstPrompt = '? Plugin name'; +const { existsSync, mkdirSync } = require("fs"); +const { join, resolve } = require("path"); +const { + run, + runPromptWithAnswers, + uniqueDirectoryForTest, + normalizeStdout, +} = require("../utils/test-utils"); + +const ENTER = "\x0D"; + +const firstPrompt = "? Plugin name"; const dataForTests = (rootAssetsPath) => ({ - pluginName: 'test-plugin', - pluginPath: join(rootAssetsPath, 'test-plugin'), - defaultPluginPath: join(rootAssetsPath, 'my-webpack-plugin'), - genPath: join(rootAssetsPath, 'test-assets'), - customPluginPath: join(rootAssetsPath, 'test-assets', 'test-plugin'), + pluginName: "test-plugin", + pluginPath: join(rootAssetsPath, "test-plugin"), + defaultPluginPath: join(rootAssetsPath, "my-webpack-plugin"), + genPath: join(rootAssetsPath, "test-assets"), + customPluginPath: join(rootAssetsPath, "test-assets", "test-plugin"), }); -describe('plugin command', () => { - it('should ask the plugin name when invoked', async () => { - const { stdout, stderr } = await runPromptWithAnswers(__dirname, ['plugin']); +describe("plugin command", () => { + it("should ask the plugin name when invoked", async () => { + const { stdout, stderr } = await runPromptWithAnswers(__dirname, ["plugin"]); expect(stdout).toBeTruthy(); expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain(firstPrompt); }); - it('should scaffold plugin with default name if no plugin name provided', async () => { + it("should scaffold plugin with default name if no plugin name provided", async () => { const assetsPath = await uniqueDirectoryForTest(); const { defaultPluginPath } = dataForTests(assetsPath); - const { stdout } = await runPromptWithAnswers(assetsPath, ['plugin'], [`${ENTER}`]); + const { stdout } = await runPromptWithAnswers(assetsPath, ["plugin"], [`${ENTER}`]); expect(normalizeStdout(stdout)).toContain(firstPrompt); @@ -32,26 +37,40 @@ describe('plugin command', () => { expect(existsSync(defaultPluginPath)).toBeTruthy(); // Skip test in case installation fails - if (!existsSync(resolve(defaultPluginPath, './yarn.lock'))) { + if (!existsSync(resolve(defaultPluginPath, "./yarn.lock"))) { return; } // Test regressively files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(join(defaultPluginPath, file))).toBeTruthy(); }); // Check if the the generated plugin works successfully - const { stdout: stdout2 } = await run(__dirname, ['--config', './my-webpack-plugin/examples/simple/webpack.config.js']); - expect(normalizeStdout(stdout2)).toContain('Hello World!'); + const { stdout: stdout2 } = await run(__dirname, [ + "--config", + "./my-webpack-plugin/examples/simple/webpack.config.js", + ]); + expect(normalizeStdout(stdout2)).toContain("Hello World!"); }); - it('should scaffold plugin template with a given name', async () => { + it("should scaffold plugin template with a given name", async () => { const assetsPath = await uniqueDirectoryForTest(); const { pluginName, pluginPath } = dataForTests(assetsPath); - const { stdout } = await runPromptWithAnswers(assetsPath, ['plugin'], [`${pluginName}${ENTER}`]); + const { stdout } = await runPromptWithAnswers( + assetsPath, + ["plugin"], + [`${pluginName}${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); @@ -59,26 +78,40 @@ describe('plugin command', () => { expect(existsSync(pluginPath)).toBeTruthy(); // Skip test in case installation fails - if (!existsSync(resolve(pluginPath, './yarn.lock'))) { + if (!existsSync(resolve(pluginPath, "./yarn.lock"))) { return; } // Test regressively files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(join(pluginPath, file))).toBeTruthy(); }); // Check if the the generated plugin works successfully - const { stdout: stdout2 } = await run(__dirname, ['--config', './test-plugin/examples/simple/webpack.config.js']); - expect(normalizeStdout(stdout2)).toContain('Hello World!'); + const { stdout: stdout2 } = await run(__dirname, [ + "--config", + "./test-plugin/examples/simple/webpack.config.js", + ]); + expect(normalizeStdout(stdout2)).toContain("Hello World!"); }); - it('should scaffold plugin template in the specified path', async () => { + it("should scaffold plugin template in the specified path", async () => { const assetsPath = await uniqueDirectoryForTest(); const { pluginName, customPluginPath } = dataForTests(assetsPath); - const { stdout } = await runPromptWithAnswers(assetsPath, ['plugin', 'test-assets'], [`${pluginName}${ENTER}`]); + const { stdout } = await runPromptWithAnswers( + assetsPath, + ["plugin", "test-assets"], + [`${pluginName}${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); @@ -86,23 +119,33 @@ describe('plugin command', () => { expect(existsSync(customPluginPath)).toBeTruthy(); // Skip test in case installation fails - if (!existsSync(resolve(customPluginPath, './yarn.lock'))) { + if (!existsSync(resolve(customPluginPath, "./yarn.lock"))) { return; } // Test regressively files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(join(customPluginPath, file))).toBeTruthy(); }); // Check if the the generated plugin works successfully - const { stdout: stdout2 } = await run(customPluginPath, ['--config', './examples/simple/webpack.config.js']); - expect(normalizeStdout(stdout2)).toContain('Hello World!'); + const { stdout: stdout2 } = await run(customPluginPath, [ + "--config", + "./examples/simple/webpack.config.js", + ]); + expect(normalizeStdout(stdout2)).toContain("Hello World!"); }); - it('should scaffold plugin template in the current directory', async () => { + it("should scaffold plugin template in the current directory", async () => { const assetsPath = await uniqueDirectoryForTest(); const { genPath, customPluginPath, pluginName } = dataForTests(assetsPath); @@ -110,7 +153,11 @@ describe('plugin command', () => { mkdirSync(genPath); } - let { stdout } = await runPromptWithAnswers(genPath, ['plugin', './'], [`${pluginName}${ENTER}`]); + let { stdout } = await runPromptWithAnswers( + genPath, + ["plugin", "./"], + [`${pluginName}${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); @@ -118,47 +165,71 @@ describe('plugin command', () => { expect(existsSync(customPluginPath)).toBeTruthy(); // Skip test in case installation fails - if (!existsSync(resolve(customPluginPath, './yarn.lock'))) { + if (!existsSync(resolve(customPluginPath, "./yarn.lock"))) { return; } // Test regressively files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(join(customPluginPath, file))).toBeTruthy(); }); // Check if the the generated plugin works successfully - const { stdout: stdout2 } = await run(customPluginPath, ['--config', './examples/simple/webpack.config.js']); - expect(normalizeStdout(stdout2)).toContain('Hello World!'); + const { stdout: stdout2 } = await run(customPluginPath, [ + "--config", + "./examples/simple/webpack.config.js", + ]); + expect(normalizeStdout(stdout2)).toContain("Hello World!"); }); - it('should prompt on supplying an invalid template', async () => { + it("should prompt on supplying an invalid template", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stderr } = await runPromptWithAnswers(assetsPath, ['plugin', '--template=unknown']); + const { stderr } = await runPromptWithAnswers(assetsPath, ["plugin", "--template=unknown"]); - expect(stderr).toContain('unknown is not a valid template'); + expect(stderr).toContain("unknown is not a valid template"); }); it("recognizes '-t' as an alias for '--template'", async () => { const assetsPath = await uniqueDirectoryForTest(); const { defaultPluginPath } = dataForTests(assetsPath); - const { stdout } = await runPromptWithAnswers(assetsPath, ['plugin', '-t', 'default'], [`${ENTER}`]); + const { stdout } = await runPromptWithAnswers( + assetsPath, + ["plugin", "-t", "default"], + [`${ENTER}`], + ); expect(normalizeStdout(stdout)).toContain(firstPrompt); // Check if the output directory exists with the appropriate plugin name expect(existsSync(defaultPluginPath)).toBeTruthy(); // Skip test in case installation fails - if (!existsSync(resolve(defaultPluginPath, './yarn.lock'))) { + if (!existsSync(resolve(defaultPluginPath, "./yarn.lock"))) { return; } // Test regressively files are scaffolded - const files = ['package.json', 'examples', 'src', 'test', 'src/index.js', 'examples/simple/webpack.config.js']; + const files = [ + "package.json", + "examples", + "src", + "test", + "src/index.js", + "examples/simple/webpack.config.js", + ]; files.forEach((file) => { expect(existsSync(join(defaultPluginPath, file))).toBeTruthy(); }); // Check if the the generated plugin works successfully - const { stdout: stdout2 } = await run(__dirname, ['--config', './my-webpack-plugin/examples/simple/webpack.config.js']); - expect(normalizeStdout(stdout2)).toContain('Hello World!'); + const { stdout: stdout2 } = await run(__dirname, [ + "--config", + "./my-webpack-plugin/examples/simple/webpack.config.js", + ]); + expect(normalizeStdout(stdout2)).toContain("Hello World!"); }); }); diff --git a/test/serve/basic/dev-server-output-public-path.config.js b/test/serve/basic/dev-server-output-public-path.config.js index d6d09b622ac..dc00230f01c 100644 --- a/test/serve/basic/dev-server-output-public-path.config.js +++ b/test/serve/basic/dev-server-output-public-path.config.js @@ -1,12 +1,12 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { devServerConfig } = require('./helper/base-dev-server.config'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { devServerConfig } = require("./helper/base-dev-server.config"); module.exports = { - mode: 'development', + mode: "development", devtool: false, output: { - publicPath: '/my-public-path/', + publicPath: "/my-public-path/", }, devServer: devServerConfig, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false, "hooks.compilation.taps")], }; diff --git a/test/serve/basic/function-with-argv.config.js b/test/serve/basic/function-with-argv.config.js index ee0cfeb8d15..8102f9ccaf2 100644 --- a/test/serve/basic/function-with-argv.config.js +++ b/test/serve/basic/function-with-argv.config.js @@ -1,17 +1,17 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = (env, argv) => { console.log(argv); return { - mode: 'development', + mode: "development", devtool: false, - plugins: [new WebpackCLITestPlugin(['mode'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode"], false, "hooks.compilation.taps")], devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, diff --git a/test/serve/basic/function-with-env.config.js b/test/serve/basic/function-with-env.config.js index fa2a37578a3..43b163e1231 100644 --- a/test/serve/basic/function-with-env.config.js +++ b/test/serve/basic/function-with-env.config.js @@ -1,17 +1,17 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = (env) => { console.log(env); return { - mode: 'development', + mode: "development", devtool: false, - plugins: [new WebpackCLITestPlugin(['mode'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode"], false, "hooks.compilation.taps")], devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, diff --git a/test/serve/basic/helper/base-dev-server.config.js b/test/serve/basic/helper/base-dev-server.config.js index 25c04c49759..617f1522a02 100644 --- a/test/serve/basic/helper/base-dev-server.config.js +++ b/test/serve/basic/helper/base-dev-server.config.js @@ -1,19 +1,19 @@ -const { isDevServer4 } = require('../../../utils/test-utils'); +const { isDevServer4 } = require("../../../utils/test-utils"); let devServerConfig = {}; if (isDevServer4) { devServerConfig = { devMiddleware: { - publicPath: '/dev-server-my-public-path/', + publicPath: "/dev-server-my-public-path/", }, client: { - logging: 'info', + logging: "info", }, }; } else { devServerConfig = { - publicPath: '/dev-server-my-public-path/', + publicPath: "/dev-server-my-public-path/", }; } diff --git a/test/serve/basic/log.config.js b/test/serve/basic/log.config.js index 49fd55ddff3..9384297c7eb 100644 --- a/test/serve/basic/log.config.js +++ b/test/serve/basic/log.config.js @@ -1,14 +1,14 @@ -const { isDevServer4 } = require('../../utils/test-utils'); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = { - mode: 'development', + mode: "development", infrastructureLogging: { - level: 'log', + level: "log", }, devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, diff --git a/test/serve/basic/multi-dev-server-output-public-path.config.js b/test/serve/basic/multi-dev-server-output-public-path.config.js index 181683f0133..e1098ce284c 100644 --- a/test/serve/basic/multi-dev-server-output-public-path.config.js +++ b/test/serve/basic/multi-dev-server-output-public-path.config.js @@ -1,34 +1,34 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { devServerConfig } = require('./helper/base-dev-server.config'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { devServerConfig } = require("./helper/base-dev-server.config"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = [ { - name: 'one', - mode: 'development', + name: "one", + mode: "development", devtool: false, - entry: './src/other.js', + entry: "./src/other.js", output: { - filename: 'first-output/[name].js', + filename: "first-output/[name].js", }, devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, }, { - name: 'two', - mode: 'development', + name: "two", + mode: "development", devtool: false, - stats: 'detailed', + stats: "detailed", output: { - publicPath: '/my-public-path/', - filename: 'second-output/[name].js', + publicPath: "/my-public-path/", + filename: "second-output/[name].js", }, devServer: devServerConfig, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false, "hooks.compilation.taps")], }, ]; diff --git a/test/serve/basic/multi-dev-server.config.js b/test/serve/basic/multi-dev-server.config.js index 211aaef13e5..41afff3d1c7 100644 --- a/test/serve/basic/multi-dev-server.config.js +++ b/test/serve/basic/multi-dev-server.config.js @@ -1,30 +1,30 @@ // eslint-disable-next-line node/no-unpublished-require -const getPort = require('get-port'); +const getPort = require("get-port"); -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { devServerConfig } = require('./helper/base-dev-server.config'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { devServerConfig } = require("./helper/base-dev-server.config"); module.exports = async () => [ { - name: 'one', - mode: 'development', + name: "one", + mode: "development", devtool: false, output: { - filename: 'first-output/[name].js', + filename: "first-output/[name].js", }, devServer: { ...devServerConfig, port: await getPort(), }, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false, "hooks.compilation.taps")], }, { - name: 'two', - mode: 'development', + name: "two", + mode: "development", devtool: false, - entry: './src/other.js', + entry: "./src/other.js", output: { - filename: 'second-output/[name].js', + filename: "second-output/[name].js", }, devServer: { ...devServerConfig, diff --git a/test/serve/basic/multi-output-public-path.config.js b/test/serve/basic/multi-output-public-path.config.js index 6dcf228efd2..5058d96ceb7 100644 --- a/test/serve/basic/multi-output-public-path.config.js +++ b/test/serve/basic/multi-output-public-path.config.js @@ -1,31 +1,31 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = [ { - name: 'one', - mode: 'development', + name: "one", + mode: "development", devtool: false, output: { - publicPath: '/my-public-path/', - filename: 'first-output/[name].js', + publicPath: "/my-public-path/", + filename: "first-output/[name].js", }, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false, "hooks.compilation.taps")], devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, }, { - name: 'two', - mode: 'development', + name: "two", + mode: "development", devtool: false, - entry: './src/other.js', + entry: "./src/other.js", output: { - filename: 'second-output/[name].js', + filename: "second-output/[name].js", }, }, ]; diff --git a/test/serve/basic/multi.config.js b/test/serve/basic/multi.config.js index e8134f9b209..190d78bdc34 100644 --- a/test/serve/basic/multi.config.js +++ b/test/serve/basic/multi.config.js @@ -1,24 +1,24 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { devServerConfig } = require('./helper/base-dev-server.config'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { devServerConfig } = require("./helper/base-dev-server.config"); module.exports = [ { - name: 'one', - mode: 'development', + name: "one", + mode: "development", devtool: false, output: { - filename: 'first-output/[name].js', + filename: "first-output/[name].js", }, devServer: devServerConfig, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false, "hooks.compilation.taps")], }, { - name: 'two', - mode: 'development', + name: "two", + mode: "development", devtool: false, - entry: './src/other.js', + entry: "./src/other.js", output: { - filename: 'second-output/[name].js', + filename: "second-output/[name].js", }, }, ]; diff --git a/test/serve/basic/multiple-dev-server.config.js b/test/serve/basic/multiple-dev-server.config.js index 8c72527829a..f43310fe3cc 100644 --- a/test/serve/basic/multiple-dev-server.config.js +++ b/test/serve/basic/multiple-dev-server.config.js @@ -1,26 +1,26 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { devServerConfig } = require('./helper/base-dev-server.config'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { devServerConfig } = require("./helper/base-dev-server.config"); module.exports = [ { - name: 'one', - mode: 'development', + name: "one", + mode: "development", devtool: false, output: { - filename: 'first-output/[name].js', + filename: "first-output/[name].js", }, devServer: devServerConfig, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false)], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false)], }, { - name: 'two', - mode: 'development', + name: "two", + mode: "development", devtool: false, - entry: './src/other.js', + entry: "./src/other.js", output: { - filename: 'first-output/[name].js', + filename: "first-output/[name].js", }, devServer: devServerConfig, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false)], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false)], }, ]; diff --git a/test/serve/basic/output-public-path.config.js b/test/serve/basic/output-public-path.config.js index e5c37b210cb..0c09899f5ee 100644 --- a/test/serve/basic/output-public-path.config.js +++ b/test/serve/basic/output-public-path.config.js @@ -1,17 +1,17 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = { - mode: 'development', + mode: "development", devtool: false, output: { - publicPath: '/my-public-path/', + publicPath: "/my-public-path/", }, - plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode", "output"], false, "hooks.compilation.taps")], devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, diff --git a/test/serve/basic/same-ports-dev-serever.config.js b/test/serve/basic/same-ports-dev-serever.config.js index d85e05a7341..d0c061494e7 100644 --- a/test/serve/basic/same-ports-dev-serever.config.js +++ b/test/serve/basic/same-ports-dev-serever.config.js @@ -1,22 +1,22 @@ module.exports = [ { - name: 'one', - mode: 'development', + name: "one", + mode: "development", devtool: false, output: { - filename: 'first-output/[name].js', + filename: "first-output/[name].js", }, devServer: { port: 8081, }, }, { - name: 'two', - mode: 'development', + name: "two", + mode: "development", devtool: false, - entry: './src/other.js', + entry: "./src/other.js", output: { - filename: 'second-output/[name].js', + filename: "second-output/[name].js", }, devServer: { port: 8081, diff --git a/test/serve/basic/serve-basic.test.js b/test/serve/basic/serve-basic.test.js index 8d296a2aced..d714dc0db8e 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -1,523 +1,610 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const getPort = require('get-port'); -const { runWatch, isWebpack5, normalizeStderr, normalizeStdout, isDevServer4 } = require('../../utils/test-utils'); +const getPort = require("get-port"); +const { + runWatch, + isWebpack5, + normalizeStderr, + normalizeStdout, + isDevServer4, +} = require("../../utils/test-utils"); const testPath = path.resolve(__dirname); -describe('basic serve usage', () => { +describe("basic serve usage", () => { let port; beforeEach(async () => { port = await getPort(); }); - it('should work', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve']); + it("should work", async () => { + const { stderr, stdout } = await runWatch(__dirname, ["serve"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--config" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'serve.config.js', '--port', port]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "serve.config.js", + "--port", + port, + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--config" and "--env" options', async () => { const { stderr, stdout } = await runWatch(__dirname, [ - 'serve', - '--config', - 'function-with-env.config.js', - '--env', - 'foo=bar', - '--port', + "serve", + "--config", + "function-with-env.config.js", + "--env", + "foo=bar", + "--port", port, ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('WEBPACK_SERVE: true'); + expect(stdout).toContain("WEBPACK_SERVE: true"); expect(stdout).toContain("foo: 'bar'"); - expect(stdout).toContain('development'); + expect(stdout).toContain("development"); }); it('should work with the "--config" and "--env" options and expose dev server options', async () => { const { stderr, stdout } = await runWatch(__dirname, [ - 'serve', - '--config', - 'function-with-argv.config.js', - '--env', - 'foo=bar', - '--hot', - '--port', + "serve", + "--config", + "function-with-argv.config.js", + "--env", + "foo=bar", + "--hot", + "--port", port, ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('hot: true'); - expect(stdout).toContain('WEBPACK_SERVE: true'); + expect(stdout).toContain("hot: true"); + expect(stdout).toContain("WEBPACK_SERVE: true"); expect(stdout).toContain("foo: 'bar'"); - expect(stdout).toContain('development'); + expect(stdout).toContain("development"); }); - it('should work in multi compiler mode', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'multi.config.js', '--port', port]); + it("should work in multi compiler mode", async () => { + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "multi.config.js", + "--port", + port, + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('one'); - expect(stdout).toContain('first-output/main.js'); - expect(stdout).toContain('two'); - expect(stdout).toContain('second-output/main.js'); + expect(stdout).toContain("one"); + expect(stdout).toContain("first-output/main.js"); + expect(stdout).toContain("two"); + expect(stdout).toContain("second-output/main.js"); }); // TODO need fix in future, edge case - it.skip('should work in multi compiler mode with multiple dev servers', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'multi-dev-server.config.js']); + it.skip("should work in multi compiler mode with multiple dev servers", async () => { + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "multi-dev-server.config.js", + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('one'); - expect(stdout).toContain('first-output/main.js'); - expect(stdout).toContain('two'); - expect(stdout).toContain('second-output/main.js'); + expect(stdout).toContain("one"); + expect(stdout).toContain("first-output/main.js"); + expect(stdout).toContain("two"); + expect(stdout).toContain("second-output/main.js"); }); it('should work with the "--mode" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve']); + const { stderr, stdout } = await runWatch(__dirname, ["serve"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('development'); - expect(stdout).toContain('main.js'); + expect(stdout).toContain("development"); + expect(stdout).toContain("main.js"); }); it('should work with the "--stats" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--stats']); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--stats"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain(isWebpack5 ? 'compiled successfully' : 'Version: webpack'); + expect(stdout).toContain(isWebpack5 ? "compiled successfully" : "Version: webpack"); }); it('should work with the "--stats verbose" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--stats', 'verbose']); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--stats", "verbose"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain(isWebpack5 ? 'from webpack.Compiler' : 'webpack.buildChunkGraph.visitModules'); - expect(stdout).toContain('main.js'); + expect(stdout).toContain( + isWebpack5 ? "from webpack.Compiler" : "webpack.buildChunkGraph.visitModules", + ); + expect(stdout).toContain("main.js"); }); it('should work with the "--mode" option #2', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--mode', 'production']); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--mode", "production"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('production'); - expect(stdout).toContain('main.js'); + expect(stdout).toContain("production"); + expect(stdout).toContain("main.js"); }); it('should work with the "--mode" option #3', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--mode', 'development']); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--mode", "development"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('development'); - expect(stdout).toContain('main.js'); + expect(stdout).toContain("development"); + expect(stdout).toContain("main.js"); }); it('should work with the "--progress" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--progress']); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--progress"]); - expect(stderr).toContain('webpack.Progress'); + expect(stderr).toContain("webpack.Progress"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--progress" option using the "profile" value', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--progress', 'profile']); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--progress", "profile"]); - expect(stderr).toContain('webpack.Progress'); + expect(stderr).toContain("webpack.Progress"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--client-log-level" option', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', isDevServer4 ? '--client-logging' : '--client-log-level', 'info']); + const { stdout, stderr } = await runWatch(testPath, [ + "serve", + isDevServer4 ? "--client-logging" : "--client-log-level", + "info", + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--port" option', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port]); + const { stdout, stderr } = await runWatch(testPath, ["serve", "--port", port]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--hot" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--hot']); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--hot"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--no-hot" option', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port, '--no-hot']); + const { stdout, stderr } = await runWatch(testPath, ["serve", "--port", port, "--no-hot"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stdout).toContain('main.js'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); + expect(stdout).toContain("main.js"); }); it('should work with the "--hot" option using the "only" value', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port, isDevServer4 ? '--hot=only' : '--hot-only']); + const { stdout, stderr } = await runWatch(testPath, [ + "serve", + "--port", + port, + isDevServer4 ? "--hot=only" : "--hot-only", + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).toContain('HotModuleReplacementPlugin'); - expect(stdout).toContain('main.js'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).toContain("HotModuleReplacementPlugin"); + expect(stdout).toContain("main.js"); }); it('should work with "--hot" and "--port" options', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port, '--hot']); + const { stdout, stderr } = await runWatch(testPath, ["serve", "--port", port, "--hot"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).toContain('HotModuleReplacementPlugin'); - expect(stdout).toContain('main.js'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).toContain("HotModuleReplacementPlugin"); + expect(stdout).toContain("main.js"); }); it('should work with the "--hot" and "--progress" options', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port, '--hot', '--progress']); + const { stdout, stderr } = await runWatch(testPath, [ + "serve", + "--port", + port, + "--hot", + "--progress", + ]); - expect(stderr).toContain('webpack.Progress'); - expect(stdout).toContain('HotModuleReplacementPlugin'); - expect(stdout).toContain('main.js'); + expect(stderr).toContain("webpack.Progress"); + expect(stdout).toContain("HotModuleReplacementPlugin"); + expect(stdout).toContain("main.js"); }); it('should work with the default "publicPath" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve']); + const { stderr, stdout } = await runWatch(__dirname, ["serve"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); // TODO bug on webpack-dev-server side, need respect `output.publicPath` too it('should work with the "--output-public-path" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--output-public-path', '/my-public-path/']); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--output-public-path", + "/my-public-path/", + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isWebpack5) { if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).toContain('/my-public-path/'); - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("/my-public-path/"); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); } else { - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); } }); it('should respect the "publicPath" option from configuration', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'output-public-path.config.js']); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "output-public-path.config.js", + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); - expect(stdout).toContain('/my-public-path/'); + expect(stdout).toContain("main.js"); + expect(stdout).toContain("/my-public-path/"); }); it('should respect the "publicPath" option from configuration using multi compiler mode', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'multi-output-public-path.config.js', '--port', port]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "multi-output-public-path.config.js", + "--port", + port, + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('one'); - expect(stdout).toContain('first-output/main.js'); - expect(stdout).toContain('two'); - expect(stdout).toContain('second-output/main.js'); - expect(stdout).toContain('/my-public-path/'); + expect(stdout).toContain("one"); + expect(stdout).toContain("first-output/main.js"); + expect(stdout).toContain("two"); + expect(stdout).toContain("second-output/main.js"); + expect(stdout).toContain("/my-public-path/"); }); it('should respect the "publicPath" option from configuration (from the "devServer" options)', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'dev-server-output-public-path.config.js']); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "dev-server-output-public-path.config.js", + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should work with the "--open" option', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--open', '--port', port]); + const { stdout, stderr } = await runWatch(testPath, ["serve", "--open", "--port", port]); if (isDevServer4) { let normalizedStderr = normalizeStderr(stderr); if (/wait until bundle finished/.test(normalizedStderr)) { - normalizedStderr = normalizedStderr.split('\n'); + normalizedStderr = normalizedStderr.split("\n"); - const waitIndex = normalizedStderr.findIndex((item) => /wait until bundle finished/.test(item)); + const waitIndex = normalizedStderr.findIndex((item) => + /wait until bundle finished/.test(item), + ); if (waitIndex !== -1) { normalizedStderr.splice(waitIndex, 1); } - normalizedStderr = normalizedStderr.join('\n'); + normalizedStderr = normalizedStderr.join("\n"); } - expect(normalizedStderr).toMatchSnapshot('stderr'); - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(normalizedStderr).toMatchSnapshot("stderr"); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); it('should respect the "publicPath" option from configuration using multi compiler mode (from the "devServer" options)', async () => { const { stderr, stdout } = await runWatch(__dirname, [ - 'serve', - '--config', - 'multi-dev-server-output-public-path.config.js', - '--port', + "serve", + "--config", + "multi-dev-server-output-public-path.config.js", + "--port", port, ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('one'); - expect(stdout).toContain('first-output/main.js'); - expect(stdout).toContain('two'); - expect(stdout).toContain('second-output/main.js'); + expect(stdout).toContain("one"); + expect(stdout).toContain("first-output/main.js"); + expect(stdout).toContain("two"); + expect(stdout).toContain("second-output/main.js"); }); - it('should work with entries syntax', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', './src/entry.js', '--port', port]); + it("should work with entries syntax", async () => { + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "./src/entry.js", + "--port", + port, + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('development'); + expect(stdout).toContain("development"); }); - it('should work and log warning on the `watch option in a configuration', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', './watch.config.js', '--port', port]); + it("should work and log warning on the `watch option in a configuration", async () => { + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "./watch.config.js", + "--port", + port, + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('development'); + expect(stdout).toContain("development"); }); - it('should shoe help information for serve', async () => { - const { exitCode, stderr, stdout } = await runWatch(__dirname, ['serve', '--help']); + it("should shoe help information for serve", async () => { + const { exitCode, stderr, stdout } = await runWatch(__dirname, ["serve", "--help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log used supplied config with serve', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'log.config.js', '--port', port], { - killString: /Compiler is watching files for updates\.\.\./, - }); + it("should log used supplied config with serve", async () => { + const { stderr, stdout } = await runWatch( + __dirname, + ["serve", "--config", "log.config.js", "--port", port], + { + killString: /Compiler is watching files for updates\.\.\./, + }, + ); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); expect(stdout).toBeTruthy(); }); it("should log error on using '--watch' flag with serve", async () => { - const { exitCode, stdout, stderr } = await runWatch(testPath, ['serve', '--watch']); + const { exitCode, stdout, stderr } = await runWatch(testPath, ["serve", "--watch"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it("should log error on using '-w' alias with serve", async () => { - const { exitCode, stdout, stderr } = await runWatch(testPath, ['serve', '-w']); + const { exitCode, stdout, stderr } = await runWatch(testPath, ["serve", "-w"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error on unknown flag', async () => { - const { exitCode, stdout, stderr } = await runWatch(testPath, ['serve', '--port', port, '--unknown-flag']); + it("should log an error on unknown flag", async () => { + const { exitCode, stdout, stderr } = await runWatch(testPath, [ + "serve", + "--port", + port, + "--unknown-flag", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should work with the "stats" option in config', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'stats.config.js'], { - killString: /Compiled successfully|modules/i, - }); - - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).toContain(isWebpack5 ? 'compiled successfully' : 'modules'); + const { stderr, stdout } = await runWatch( + __dirname, + ["serve", "--config", "stats.config.js"], + { + killString: /Compiled successfully|modules/i, + }, + ); + + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).toContain(isWebpack5 ? "compiled successfully" : "modules"); expect(stdout.match(/HotModuleReplacementPlugin/g)).toBeNull(); }); - it('should throw error when same ports in multicompiler', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['serve', '--config', 'same-ports-dev-serever.config.js']); + it("should throw error when same ports in multicompiler", async () => { + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "same-ports-dev-serever.config.js", + ]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/serve/basic/serve.config.js b/test/serve/basic/serve.config.js index c39ce7e347d..abc3475ef45 100644 --- a/test/serve/basic/serve.config.js +++ b/test/serve/basic/serve.config.js @@ -1,14 +1,14 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = { - mode: 'development', + mode: "development", devtool: false, - plugins: [new WebpackCLITestPlugin(['mode'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode"], false, "hooks.compilation.taps")], devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, diff --git a/test/serve/basic/src/entry.js b/test/serve/basic/src/entry.js index a136806e8f1..79f3f155834 100644 --- a/test/serve/basic/src/entry.js +++ b/test/serve/basic/src/entry.js @@ -1 +1 @@ -console.log('Entry'); +console.log("Entry"); diff --git a/test/serve/basic/src/other.js b/test/serve/basic/src/other.js index 2457f618e17..a2831caa096 100644 --- a/test/serve/basic/src/other.js +++ b/test/serve/basic/src/other.js @@ -1 +1 @@ -console.log('HERE'); +console.log("HERE"); diff --git a/test/serve/basic/stats.config.js b/test/serve/basic/stats.config.js index db5d1a85434..f01f9035323 100644 --- a/test/serve/basic/stats.config.js +++ b/test/serve/basic/stats.config.js @@ -1,18 +1,18 @@ -const { isDevServer4 } = require('../../utils/test-utils'); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = { - mode: 'development', + mode: "development", devtool: false, devServer: isDevServer4 ? { devMiddleware: { - stats: 'minimal', + stats: "minimal", }, client: { - logging: 'info', + logging: "info", }, } : { - stats: 'minimal', + stats: "minimal", }, }; diff --git a/test/serve/basic/watch.config.js b/test/serve/basic/watch.config.js index ccd8f2c2a55..f0e1746a6b2 100644 --- a/test/serve/basic/watch.config.js +++ b/test/serve/basic/watch.config.js @@ -1,15 +1,15 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = { - mode: 'development', + mode: "development", devtool: false, - plugins: [new WebpackCLITestPlugin(['mode'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode"], false, "hooks.compilation.taps")], watch: true, devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, diff --git a/test/serve/basic/webpack.config.js b/test/serve/basic/webpack.config.js index c39ce7e347d..abc3475ef45 100644 --- a/test/serve/basic/webpack.config.js +++ b/test/serve/basic/webpack.config.js @@ -1,14 +1,14 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); -const { isDevServer4 } = require('../../utils/test-utils'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); +const { isDevServer4 } = require("../../utils/test-utils"); module.exports = { - mode: 'development', + mode: "development", devtool: false, - plugins: [new WebpackCLITestPlugin(['mode'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode"], false, "hooks.compilation.taps")], devServer: isDevServer4 ? { client: { - logging: 'info', + logging: "info", }, } : {}, diff --git a/test/serve/invalid-schema/invalid-schema.test.js b/test/serve/invalid-schema/invalid-schema.test.js index 95030317d64..81aede987c5 100644 --- a/test/serve/invalid-schema/invalid-schema.test.js +++ b/test/serve/invalid-schema/invalid-schema.test.js @@ -1,37 +1,45 @@ -'use strict'; -const { run, normalizeStderr, normalizeStdout } = require('../../utils/test-utils'); +"use strict"; +const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-utils"); -describe('invalid schema', () => { - it('should log webpack error and exit process on invalid config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--config', './webpack.config.mock.js']); +describe("invalid schema", () => { + it("should log webpack error and exit process on invalid config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "serve", + "--config", + "./webpack.config.mock.js", + ]); expect(exitCode).toEqual(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log webpack error and exit process on invalid flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--mode', 'Yukihira']); + it("should log webpack error and exit process on invalid flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["serve", "--mode", "Yukihira"]); expect(exitCode).toEqual(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); // TODO need fix on webpack-dev-server side - it.skip('should log webpack-dev-server error and exit process on invalid flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--port', '-1']); + it.skip("should log webpack-dev-server error and exit process on invalid flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["serve", "--port", "-1"]); expect(exitCode).toEqual(2); - expect(normalizeStderr(stderr).replace('Port', 'options.port')).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr).replace("Port", "options.port")).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log webpack-dev-server error and exit process on invalid config', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--config', './webpack-dev-server.config.mock.js']); + it("should log webpack-dev-server error and exit process on invalid config", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "serve", + "--config", + "./webpack-dev-server.config.mock.js", + ]); expect(exitCode).toEqual(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/serve/invalid-schema/webpack-dev-server.config.mock.js b/test/serve/invalid-schema/webpack-dev-server.config.mock.js index 37e88e65591..59dfc1d6c0b 100644 --- a/test/serve/invalid-schema/webpack-dev-server.config.mock.js +++ b/test/serve/invalid-schema/webpack-dev-server.config.mock.js @@ -1,6 +1,6 @@ module.exports = { - mode: 'development', + mode: "development", devServer: { - bonjour: '', + bonjour: "", }, }; diff --git a/test/serve/invalid-schema/webpack.config.mock.js b/test/serve/invalid-schema/webpack.config.mock.js index f6d8ff0ce80..d436ef9ecc5 100644 --- a/test/serve/invalid-schema/webpack.config.mock.js +++ b/test/serve/invalid-schema/webpack.config.mock.js @@ -1,3 +1,3 @@ module.exports = { - mode: 'Nishinoya Yuu', + mode: "Nishinoya Yuu", }; diff --git a/test/serve/serve-variable/serve-basic.test.js b/test/serve/serve-variable/serve-basic.test.js index ba6c28d2326..3ae3600b041 100644 --- a/test/serve/serve-variable/serve-basic.test.js +++ b/test/serve/serve-variable/serve-basic.test.js @@ -1,31 +1,31 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const getPort = require('get-port'); -const { runWatch, normalizeStderr, isDevServer4 } = require('../../utils/test-utils'); +const getPort = require("get-port"); +const { runWatch, normalizeStderr, isDevServer4 } = require("../../utils/test-utils"); const testPath = path.resolve(__dirname); -describe('serve variable', () => { +describe("serve variable", () => { let port; beforeEach(async () => { port = await getPort(); }); - it('compiles without flags and export variable', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port]); + it("compiles without flags and export variable", async () => { + const { stdout, stderr } = await runWatch(testPath, ["serve", "--port", port]); expect(normalizeStderr(stderr)).toMatchSnapshot(); - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); if (isDevServer4) { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain('PASS'); + expect(stdout).toContain("PASS"); }); }); diff --git a/test/serve/serve-variable/webpack.config.js b/test/serve/serve-variable/webpack.config.js index 435b8b21190..302e781c333 100644 --- a/test/serve/serve-variable/webpack.config.js +++ b/test/serve/serve-variable/webpack.config.js @@ -5,11 +5,11 @@ class CustomTestPlugin { this.isInEnvironment = isInEnvironment; } apply(compiler) { - compiler.hooks.done.tap('testPlugin', () => { + compiler.hooks.done.tap("testPlugin", () => { if (!isInProcess && this.isInEnvironment) { - console.log('PASS'); + console.log("PASS"); } else { - console.log('FAIL'); + console.log("FAIL"); } }); } @@ -17,7 +17,7 @@ class CustomTestPlugin { module.exports = (env) => { return { - mode: 'development', + mode: "development", devtool: false, plugins: [new CustomTestPlugin(env.WEBPACK_SERVE)], }; 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 6808e94b1b8..085759b6148 100644 --- a/test/serve/with-custom-port/serve-custom-config.test.js +++ b/test/serve/with-custom-port/serve-custom-config.test.js @@ -1,75 +1,75 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // eslint-disable-next-line node/no-unpublished-require -const getPort = require('get-port'); -const { runWatch, normalizeStderr, isDevServer4 } = require('../../utils/test-utils'); +const getPort = require("get-port"); +const { runWatch, normalizeStderr, isDevServer4 } = require("../../utils/test-utils"); const testPath = path.resolve(__dirname); -describe('serve with devServer in config', () => { +describe("serve with devServer in config", () => { let port; beforeEach(async () => { port = await getPort(); }); - it('Should pick up the host and port from config', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve']); + it("Should pick up the host and port from config", async () => { + const { stdout, stderr } = await runWatch(testPath, ["serve"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); - expect(stdout).toContain('http://0.0.0.0:1234'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); + expect(stdout).toContain("http://0.0.0.0:1234"); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); - it('Port flag should override the config port', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port]); + it("Port flag should override the config port", async () => { + const { stdout, stderr } = await runWatch(testPath, ["serve", "--port", port]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); expect(stdout).toContain(`http://0.0.0.0:${port}`); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); - it('Passing hot flag works alongside other server config', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port, '--hot']); + it("Passing hot flag works alongside other server config", async () => { + const { stdout, stderr } = await runWatch(testPath, ["serve", "--port", port, "--hot"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); if (isDevServer4) { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); } else { - expect(stdout).toContain('HotModuleReplacementPlugin'); + expect(stdout).toContain("HotModuleReplacementPlugin"); expect(stdout).toContain(`http://0.0.0.0:${port}`); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); - it('works fine when no-hot flag is passed alongside other server config', async () => { - const { stdout, stderr } = await runWatch(testPath, ['serve', '--port', port, '--no-hot']); + it("works fine when no-hot flag is passed alongside other server config", async () => { + const { stdout, stderr } = await runWatch(testPath, ["serve", "--port", port, "--no-hot"]); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(stdout).not.toContain('HotModuleReplacementPlugin'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(stdout).not.toContain("HotModuleReplacementPlugin"); if (!isDevServer4) { // Runs at correct host and port expect(stdout).toContain(`http://0.0.0.0:${port}`); } - expect(stdout).toContain('main.js'); + expect(stdout).toContain("main.js"); }); }); diff --git a/test/serve/with-custom-port/webpack.config.js b/test/serve/with-custom-port/webpack.config.js index c0a8ac96ef6..54496f35346 100644 --- a/test/serve/with-custom-port/webpack.config.js +++ b/test/serve/with-custom-port/webpack.config.js @@ -1,12 +1,12 @@ -const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin'); +const WebpackCLITestPlugin = require("../../utils/webpack-cli-test-plugin"); module.exports = { - mode: 'development', + mode: "development", devtool: false, - stats: 'detailed', + stats: "detailed", devServer: { port: 1234, - host: '0.0.0.0', + host: "0.0.0.0", }, - plugins: [new WebpackCLITestPlugin(['mode'], false, 'hooks.compilation.taps')], + plugins: [new WebpackCLITestPlugin(["mode"], false, "hooks.compilation.taps")], }; diff --git a/test/utils/cli-plugin-test/main.js b/test/utils/cli-plugin-test/main.js index 3451e9b7ed7..accefceba62 100644 --- a/test/utils/cli-plugin-test/main.js +++ b/test/utils/cli-plugin-test/main.js @@ -1 +1 @@ -console.log('Hello World'); +console.log("Hello World"); diff --git a/test/utils/cli-plugin-test/plugin.test.js b/test/utils/cli-plugin-test/plugin.test.js index c7510abe361..280a6a9b152 100644 --- a/test/utils/cli-plugin-test/plugin.test.js +++ b/test/utils/cli-plugin-test/plugin.test.js @@ -1,19 +1,19 @@ -'use strict'; -const { cli } = require('webpack'); -const { run } = require('../test-utils'); +"use strict"; +const { cli } = require("webpack"); +const { run } = require("../test-utils"); -describe('webpack-cli-test-plugin Test', () => { - it('should log the webpack configuration', async () => { +describe("webpack-cli-test-plugin Test", () => { + it("should log the webpack configuration", async () => { const { exitCode, stderr, stdout } = await run(__dirname); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toContain(`target: 'node'`); - if (typeof cli !== 'undefined') { + if (typeof cli !== "undefined") { expect(stdout).toContain(`alias: { alias: [ 'alias1', 'alias2' ] }`); } - expect(stdout).toContain('WebpackCLITestPlugin'); + expect(stdout).toContain("WebpackCLITestPlugin"); }); }); diff --git a/test/utils/cli-plugin-test/webpack.config.js b/test/utils/cli-plugin-test/webpack.config.js index fa4684df319..6a777189d65 100644 --- a/test/utils/cli-plugin-test/webpack.config.js +++ b/test/utils/cli-plugin-test/webpack.config.js @@ -1,18 +1,18 @@ // webpack.config.js -const { cli } = require('webpack'); -const WebpackCLITestPlugin = require('../webpack-cli-test-plugin'); +const { cli } = require("webpack"); +const WebpackCLITestPlugin = require("../webpack-cli-test-plugin"); module.exports = { - entry: './main.js', - mode: 'development', - target: 'node', + entry: "./main.js", + mode: "development", + target: "node", resolve: { alias: - typeof cli !== 'undefined' + typeof cli !== "undefined" ? { - alias: ['alias1', 'alias2'], + alias: ["alias1", "alias2"], } : {}, }, - plugins: [new WebpackCLITestPlugin(['resolve'])], + plugins: [new WebpackCLITestPlugin(["resolve"])], }; diff --git a/test/utils/exec-in-directory.js b/test/utils/exec-in-directory.js index 7654c374026..c8a5f4d522f 100644 --- a/test/utils/exec-in-directory.js +++ b/test/utils/exec-in-directory.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; const [, , dir, bin] = process.argv; process.argv.splice(1, 2); diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js index 65a9fce20b7..ed707c23691 100644 --- a/test/utils/test-utils.js +++ b/test/utils/test-utils.js @@ -1,33 +1,33 @@ /* eslint-disable node/no-unpublished-require */ -'use strict'; - -const os = require('os'); -const stripAnsi = require('strip-ansi'); -const path = require('path'); -const fs = require('fs'); -const execa = require('execa'); -const internalIp = require('internal-ip'); -const { exec } = require('child_process'); +"use strict"; + +const os = require("os"); +const stripAnsi = require("strip-ansi"); +const path = require("path"); +const fs = require("fs"); +const execa = require("execa"); +const internalIp = require("internal-ip"); +const { exec } = require("child_process"); const { node: execaNode } = execa; -const { Writable } = require('readable-stream'); -const concat = require('concat-stream'); -const { cli, version } = require('webpack'); -const isWebpack5 = version.startsWith('5'); +const { Writable } = require("readable-stream"); +const concat = require("concat-stream"); +const { cli, version } = require("webpack"); +const isWebpack5 = version.startsWith("5"); let devServerVersion; try { - devServerVersion = require('webpack-dev-server/package.json').version; + devServerVersion = require("webpack-dev-server/package.json").version; } catch (error) { // Nothing } -const isDevServer4 = devServerVersion && devServerVersion.startsWith('4'); +const isDevServer4 = devServerVersion && devServerVersion.startsWith("4"); -const WEBPACK_PATH = path.resolve(__dirname, '../../packages/webpack-cli/bin/cli.js'); +const WEBPACK_PATH = path.resolve(__dirname, "../../packages/webpack-cli/bin/cli.js"); const ENABLE_LOG_COMPILATION = process.env.ENABLE_PIPE || false; -const isWindows = process.platform === 'win32'; +const isWindows = process.platform === "win32"; const hyphenToUpperCase = (name) => { if (!name) { @@ -41,7 +41,7 @@ const hyphenToUpperCase = (name) => { const processKill = (process) => { if (isWindows) { - exec('taskkill /pid ' + process.pid + ' /T /F'); + exec("taskkill /pid " + process.pid + " /T /F"); } else { process.kill(); } @@ -62,7 +62,7 @@ const createProcess = (cwd, args, options) => { return processExecutor(WEBPACK_PATH, args, { cwd: path.resolve(cwd), reject: false, - stdio: ENABLE_LOG_COMPILATION ? 'inherit' : 'pipe', + stdio: ENABLE_LOG_COMPILATION ? "inherit" : "pipe", maxBuffer: Infinity, env: { WEBPACK_CLI_HELP_WIDTH: 1024 }, ...options, @@ -109,7 +109,7 @@ const runWatch = (cwd, args = [], options = {}) => { process.stdout.pipe( new Writable({ write(chunk, encoding, callback) { - const output = stripAnsi(chunk.toString('utf8')); + const output = stripAnsi(chunk.toString("utf8")); if (outputKillStr.test(output)) { processKill(process); @@ -123,7 +123,7 @@ const runWatch = (cwd, args = [], options = {}) => { process.stderr.pipe( new Writable({ write(chunk, encoding, callback) { - const output = stripAnsi(chunk.toString('utf8')); + const output = stripAnsi(chunk.toString("utf8")); if (outputKillStr.test(output)) { processKill(process); @@ -153,7 +153,7 @@ const runWatch = (cwd, args = [], options = {}) => { const runPromptWithAnswers = (location, args, answers) => { const process = runAndGetProcess(location, args); - process.stdin.setDefaultEncoding('utf-8'); + process.stdin.setDefaultEncoding("utf-8"); const delay = 2000; let outputTimeout; @@ -176,7 +176,7 @@ const runPromptWithAnswers = (location, args, answers) => { process.stdout.pipe( new Writable({ write(chunk, encoding, callback) { - const output = chunk.toString('utf8'); + const output = chunk.toString("utf8"); if (output) { if (outputTimeout) { @@ -207,7 +207,7 @@ const runPromptWithAnswers = (location, args, answers) => { } if (stdoutDone && stderrDone) { - process.kill('SIGKILL'); + process.kill("SIGKILL"); resolve(obj); } }; @@ -235,20 +235,24 @@ const runPromptWithAnswers = (location, args, answers) => { const normalizeVersions = (output) => { return output.replace( /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/gi, - 'x.x.x', + "x.x.x", ); }; const normalizeCwd = (output) => { - return output.replace(/\\/g, '/').replace(new RegExp(process.cwd().replace(/\\/g, '/'), 'g'), ''); + return output + .replace(/\\/g, "/") + .replace(new RegExp(process.cwd().replace(/\\/g, "/"), "g"), ""); }; const normalizeError = (output) => { - return output.replace(/SyntaxError: .+/, 'SyntaxError: ').replace(/\s+at .+(}|\)|\d)/gs, '\n at stack'); + return output + .replace(/SyntaxError: .+/, "SyntaxError: ") + .replace(/\s+at .+(}|\)|\d)/gs, "\n at stack"); }; const normalizeStdout = (stdout) => { - if (typeof stdout !== 'string') { + if (typeof stdout !== "string") { return stdout; } @@ -265,7 +269,7 @@ const normalizeStdout = (stdout) => { }; const normalizeStderr = (stderr) => { - if (typeof stderr !== 'string') { + if (typeof stderr !== "string") { return stderr; } @@ -279,32 +283,40 @@ const normalizeStderr = (stderr) => { const networkIPv4 = internalIp.v4.sync(); if (networkIPv4) { - normalizedStderr = normalizedStderr.replace(new RegExp(networkIPv4, 'g'), ''); + normalizedStderr = normalizedStderr.replace( + new RegExp(networkIPv4, "g"), + "", + ); } const networkIPv6 = internalIp.v6.sync(); if (networkIPv6) { - normalizedStderr = normalizedStderr.replace(new RegExp(networkIPv6, 'g'), ''); + normalizedStderr = normalizedStderr.replace( + new RegExp(networkIPv6, "g"), + "", + ); } - normalizedStderr = normalizedStderr.replace(/:[0-9]+\//g, ':/'); + normalizedStderr = normalizedStderr.replace(/:[0-9]+\//g, ":/"); if (!/On Your Network \(IPv6\)/.test(stderr)) { // Github Actions doesnt' support IPv6 on ubuntu in some cases - normalizedStderr = normalizedStderr.split('\n'); + normalizedStderr = normalizedStderr.split("\n"); - const ipv4MessageIndex = normalizedStderr.findIndex((item) => /On Your Network \(IPv4\)/.test(item)); + const ipv4MessageIndex = normalizedStderr.findIndex((item) => + /On Your Network \(IPv4\)/.test(item), + ); if (ipv4MessageIndex !== -1) { normalizedStderr.splice( ipv4MessageIndex + 1, 0, - ' [webpack-dev-server] On Your Network (IPv6): http://[]:/', + " [webpack-dev-server] On Your Network (IPv6): http://[]:/", ); } - normalizedStderr = normalizedStderr.join('\n'); + normalizedStderr = normalizedStderr.join("\n"); } normalizedStderr = normalizeVersions(normalizedStderr); @@ -314,7 +326,7 @@ const normalizeStderr = (stderr) => { }; const getWebpackCliArguments = (startWith) => { - if (typeof startWith === 'undefined') { + if (typeof startWith === "undefined") { return cli.getArguments(); } diff --git a/test/utils/test-utils.test.js b/test/utils/test-utils.test.js index 5f16439d554..efe183b6a78 100644 --- a/test/utils/test-utils.test.js +++ b/test/utils/test-utils.test.js @@ -1,81 +1,94 @@ -'use strict'; +"use strict"; -const { run, runAndGetProcess, hyphenToUpperCase, uniqueDirectoryForTest } = require('./test-utils'); +const { + run, + runAndGetProcess, + hyphenToUpperCase, + uniqueDirectoryForTest, +} = require("./test-utils"); -const ENTER = '\x0D'; +const ENTER = "\x0D"; -describe('run function', () => { - it('should work correctly by default', async () => { +describe("run function", () => { + it("should work correctly by default", async () => { const { command, stdout, stderr } = await run(__dirname); expect(stderr).toBeFalsy(); // Executes the correct command - expect(command).toContain('cli.js'); - expect(command).toContain('bin'); + expect(command).toContain("cli.js"); + expect(command).toContain("bin"); expect(stdout).toBeTruthy(); }); - it('executes cli with passed commands and params', async () => { - const { stdout, stderr, command } = await run(__dirname, ['info', '--output', 'markdown']); + it("executes cli with passed commands and params", async () => { + const { stdout, stderr, command } = await run(__dirname, ["info", "--output", "markdown"]); // execution command contains info command - expect(command).toContain('info'); - expect(command).toContain('--output markdown'); + expect(command).toContain("info"); + expect(command).toContain("--output markdown"); // Contains info command output - expect(stdout).toContain('System:'); - expect(stdout).toContain('Node'); - expect(stdout).toContain('npm'); - expect(stdout).toContain('Yarn'); + expect(stdout).toContain("System:"); + expect(stdout).toContain("Node"); + expect(stdout).toContain("npm"); + expect(stdout).toContain("Yarn"); expect(stderr).toBeFalsy(); }); - it('uses default output when output param is false', async () => { + it("uses default output when output param is false", async () => { const { stdout, stderr, command } = await run(__dirname, []); // execution command contains info command - expect(command).not.toContain('--output-path'); + expect(command).not.toContain("--output-path"); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); }); -describe('runAndGetWatchProc function', () => { - it('should work correctly by default', async () => { +describe("runAndGetWatchProc function", () => { + it("should work correctly by default", async () => { const { command, stdout, stderr } = await runAndGetProcess(__dirname); // Executes the correct command - expect(command).toContain('cli.js'); + expect(command).toContain("cli.js"); // Should use apply a default output dir expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('executes cli with passed commands and params', async () => { - const { stdout, stderr, command } = await runAndGetProcess(__dirname, ['info', '--output', 'markdown']); + it("executes cli with passed commands and params", async () => { + const { stdout, stderr, command } = await runAndGetProcess(__dirname, [ + "info", + "--output", + "markdown", + ]); // execution command contains info command - expect(command).toContain('info'); - expect(command).toContain('--output markdown'); + expect(command).toContain("info"); + expect(command).toContain("--output markdown"); // Contains info command output - expect(stdout).toContain('System:'); - expect(stdout).toContain('Node'); - expect(stdout).toContain('npm'); - expect(stdout).toContain('Yarn'); + expect(stdout).toContain("System:"); + expect(stdout).toContain("Node"); + expect(stdout).toContain("npm"); + expect(stdout).toContain("Yarn"); expect(stderr).toBeFalsy(); }); - it('writes to stdin', async () => { + it("writes to stdin", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout } = await runAndGetProcess(assetsPath, ['init', '--force', '--template=mango'], { input: ENTER }); + const { stdout } = await runAndGetProcess( + assetsPath, + ["init", "--force", "--template=mango"], + { input: ENTER }, + ); - expect(stdout).toContain('Project has been initialised with webpack!'); + expect(stdout).toContain("Project has been initialised with webpack!"); }); }); -describe('hyphenToUpperCase function', () => { - it('changes value from hypen to upperCase', () => { - const result = hyphenToUpperCase('test-value'); +describe("hyphenToUpperCase function", () => { + it("changes value from hypen to upperCase", () => { + const result = hyphenToUpperCase("test-value"); - expect(result).toEqual('testValue'); + expect(result).toEqual("testValue"); }); }); diff --git a/test/utils/webpack-cli-test-plugin.js b/test/utils/webpack-cli-test-plugin.js index 510b5889bea..963ac5ff1cc 100644 --- a/test/utils/webpack-cli-test-plugin.js +++ b/test/utils/webpack-cli-test-plugin.js @@ -6,9 +6,9 @@ class WebpackCLITestPlugin { } apply(compiler) { - compiler.hooks.done.tap('webpack-cli Test Plugin', () => { + compiler.hooks.done.tap("webpack-cli Test Plugin", () => { if (this.showHooks) { - const identifiers = this.showHooks.split('.'); + const identifiers = this.showHooks.split("."); let shown = compiler; diff --git a/test/version/version.test.js b/test/version/version.test.js index 224d79ef21a..5d1416c7e4b 100644 --- a/test/version/version.test.js +++ b/test/version/version.test.js @@ -1,333 +1,342 @@ -'use strict'; +"use strict"; -const { run, normalizeStderr, normalizeStdout } = require('../utils/test-utils'); +const { run, normalizeStderr, normalizeStdout } = require("../utils/test-utils"); -describe('single version flag', () => { - it('outputs versions with command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version']); +describe("single version flag", () => { + it("outputs versions with command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs versions with dashed syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--version']); + it("outputs versions with dashed syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs versions with alias syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-v']); + it("outputs versions with alias syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-v"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with info', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '--version']); + it("outputs version with info", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with info using option alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', '-v']); + it("outputs version with info using option alias", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "-v"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with info using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'info']); + it("outputs version with info using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "info"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with info using command alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['v', 'info']); + it("outputs version with info using command alias", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["v", "info"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with build', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['build', '--version']); + it("outputs version with build", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["build", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with bundle', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', '--version']); + it("outputs version with bundle", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["bundle", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with b', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['b', '--version']); + it("outputs version with b", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["b", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with watch', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['watch', '--version']); + it("outputs version with watch", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["watch", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with w', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['w', '--version']); + it("outputs version with w", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["w", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with plugin', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['plugin', '--version']); + it("outputs version with plugin", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["plugin", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with loader', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['loader', '--version']); + it("outputs version with loader", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["loader", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with init', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['init', '--version']); + it("outputs version with init", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["init", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with serve', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', '--version']); + it("outputs version with serve", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["serve", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with migrate', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['migrate', '--version']); + it("outputs version with migrate", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["migrate", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs version with the alias c for init', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['c', '--version']); + it("outputs version with the alias c for init", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["c", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error when unknown command using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'unknown']); + it("should log error when unknown command using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log version for known command and log error for unknown command using command syntax with multi commands', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'info', 'unknown']); + it("should log version for known command and log error for unknown command using command syntax with multi commands", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "info", "unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should work for multiple commands', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['info', 'serve', '--version']); + it("should work for multiple commands", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["info", "serve", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should output versions for multiple commands using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'info', 'serve']); + it("should output versions for multiple commands using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "info", "serve"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should output versions with help command using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'help']); + it("should output versions with help command using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log version for known command and log error for unknown command using the "--version" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', 'abc', '--version']); + const { exitCode, stderr, stdout } = await run(__dirname, ["serve", "abc", "--version"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should log version for known command and log error for unknown command using the "-v" option', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['serve', 'abc', '-v']); + const { exitCode, stderr, stdout } = await run(__dirname, ["serve", "abc", "-v"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should not output version with help dashed', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', '--help']); + it("should not output version with help dashed", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "--help"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs versions with --color using option syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--version', '--color'], { env: { FORCE_COLOR: true } }); + it("outputs versions with --color using option syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs versions with --no-color using option syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--version', '--no-color'], { env: { FORCE_COLOR: true } }); + it("outputs versions with --no-color using option syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "--no-color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs versions with --color using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', '--color']); + it("outputs versions with --color using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "--color"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('outputs versions with --no-color using command syntax', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', '--no-color']); + it("outputs versions with --no-color using command syntax", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "--no-color"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error when unknown command used', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'abc']); + it("should log error when unknown command used", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "abc"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('throws error if invalid option is passed with version command', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', '--abc']); + it("throws error if invalid option is passed with version command", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "--abc"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error when unknown command used with --version flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--version', 'abc']); + it("should log error when unknown command used with --version flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "abc"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('throws error if invalid option is passed with --version flag', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['--version', '--abc']); + it("throws error if invalid option is passed with --version flag", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "--abc"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log error when unknown command used with -v alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-v', 'abc']); + it("should log error when unknown command used with -v alias", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-v", "abc"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('throws error if invalid option is passed with -v alias', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-v', '--abc']); + it("throws error if invalid option is passed with -v alias", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-v", "--abc"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should work using command syntax with the "version" value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'version']); + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); it('should work using command syntax and the "--version" argument', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', '--version']); + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "--version"]); expect(exitCode).toBe(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error using command syntax with unknown argument', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', '--unknown']); + it("should log an error using command syntax with unknown argument", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error using command syntax with unknown argument #2', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'info', '--unknown']); + it("should log an error using command syntax with unknown argument #2", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["version", "info", "--unknown"]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); - it('should log an error using command syntax with multiple commands with unknown argument', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['version', 'info', 'serve', '--unknown']); + it("should log an error using command syntax with multiple commands with unknown argument", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "version", + "info", + "serve", + "--unknown", + ]); expect(exitCode).toBe(2); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); - expect(normalizeStdout(stdout)).toMatchSnapshot('stdout'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); }); diff --git a/test/watch/analyze/analyze-flag.test.js b/test/watch/analyze/analyze-flag.test.js index 25ef9e24825..cee8687346d 100644 --- a/test/watch/analyze/analyze-flag.test.js +++ b/test/watch/analyze/analyze-flag.test.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const { runWatch } = require('../../utils/test-utils'); +const { runWatch } = require("../../utils/test-utils"); describe('"analyze" option', () => { - it('should load webpack-bundle-analyzer plugin with --analyze flag', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['--analyze'], { + it("should load webpack-bundle-analyzer plugin with --analyze flag", async () => { + const { stderr, stdout } = await runWatch(__dirname, ["--analyze"], { killString: /Webpack Bundle Analyzer is started at/, }); expect(stderr).toBeFalsy(); - expect(stdout).toContain('Webpack Bundle Analyzer is started at'); + expect(stdout).toContain("Webpack Bundle Analyzer is started at"); }); }); diff --git a/test/watch/analyze/analyze.config.js b/test/watch/analyze/analyze.config.js index 71329e267b0..a1671a29911 100644 --- a/test/watch/analyze/analyze.config.js +++ b/test/watch/analyze/analyze.config.js @@ -1,7 +1,12 @@ // eslint-disable-next-line node/no-unpublished-require -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); +const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); module.exports = { - mode: 'development', - plugins: [new BundleAnalyzerPlugin({ analyzerMode: 'static', openAnalyzer: false })], + mode: "development", + plugins: [ + new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + }), + ], }; diff --git a/test/watch/analyze/webpack.config.js b/test/watch/analyze/webpack.config.js index 1bd7a2cee42..bbb2b37c677 100644 --- a/test/watch/analyze/webpack.config.js +++ b/test/watch/analyze/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { - mode: 'development', + mode: "development", plugins: [], }; diff --git a/test/watch/bail/bail-and-watch-webpack.config.js b/test/watch/bail/bail-and-watch-webpack.config.js index 85d95542909..e29774ed94d 100644 --- a/test/watch/bail/bail-and-watch-webpack.config.js +++ b/test/watch/bail/bail-and-watch-webpack.config.js @@ -1,7 +1,7 @@ module.exports = { - entry: './src/first.js', + entry: "./src/first.js", devtool: false, - mode: 'development', + mode: "development", bail: true, watch: true, }; diff --git a/test/watch/bail/bail-multi-webpack.config.js b/test/watch/bail/bail-multi-webpack.config.js index d36a8ba9fe3..c2890ba9fff 100644 --- a/test/watch/bail/bail-multi-webpack.config.js +++ b/test/watch/bail/bail-multi-webpack.config.js @@ -2,20 +2,20 @@ module.exports = [ { devtool: false, output: { - filename: './dist-first.js', + filename: "./dist-first.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', + name: "first", + entry: "./src/first.js", + mode: "development", bail: true, }, { devtool: false, output: { - filename: './dist-second.js', + filename: "./dist-second.js", }, - name: 'second', - entry: './src/second.js', - mode: 'development', + name: "second", + entry: "./src/second.js", + mode: "development", }, ]; diff --git a/test/watch/bail/bail-webpack.config.js b/test/watch/bail/bail-webpack.config.js index d3f445c8782..67c7bb44a8f 100644 --- a/test/watch/bail/bail-webpack.config.js +++ b/test/watch/bail/bail-webpack.config.js @@ -1,6 +1,6 @@ module.exports = { devtool: false, - entry: './src/first.js', - mode: 'development', + entry: "./src/first.js", + mode: "development", bail: true, }; diff --git a/test/watch/bail/bail.test.js b/test/watch/bail/bail.test.js index 2d6bd82c1fb..ba351e6c71d 100644 --- a/test/watch/bail/bail.test.js +++ b/test/watch/bail/bail.test.js @@ -1,47 +1,68 @@ -'use strict'; +"use strict"; -const { runWatch } = require('../../utils/test-utils'); +const { runWatch } = require("../../utils/test-utils"); describe('"bail" option', () => { it('should not log warning in not watch mode without the "watch" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'watch-webpack.config.js']); + const { stderr, stdout } = await runWatch(__dirname, ["-c", "watch-webpack.config.js"]); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); it('should not log warning without the "bail" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); + const { stderr, stdout } = await runWatch(__dirname, [ + "-c", + "no-bail-webpack.config.js", + "--watch", + ]); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); it('should not log warning without the "bail" option', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']); + const { stderr, stdout } = await runWatch(__dirname, [ + "-c", + "no-bail-webpack.config.js", + "--watch", + ]); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should log warning in watch mode', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-webpack.config.js', '--watch']); + it("should log warning in watch mode", async () => { + const { stderr, stdout } = await runWatch(__dirname, [ + "-c", + "bail-webpack.config.js", + "--watch", + ]); - expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); + expect(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 watch mode', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-and-watch-webpack.config.js']); + it("should log warning in watch mode", async () => { + const { stderr, stdout } = await runWatch(__dirname, [ + "-c", + "bail-and-watch-webpack.config.js", + ]); - expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); + expect(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']); + it("should log warning in case of multiple compilers", async () => { + const { stderr, stdout } = await runWatch(__dirname, ["-c", "multi-webpack.config.js"]); - expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`); + expect(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/watch/bail/multi-webpack.config.js b/test/watch/bail/multi-webpack.config.js index b36638f118f..9fe0cb532f1 100644 --- a/test/watch/bail/multi-webpack.config.js +++ b/test/watch/bail/multi-webpack.config.js @@ -2,21 +2,21 @@ module.exports = [ { devtool: false, output: { - filename: './dist-first.js', + filename: "./dist-first.js", }, - name: 'first', - entry: './src/first.js', - mode: 'development', + name: "first", + entry: "./src/first.js", + mode: "development", bail: true, watch: true, }, { devtool: false, output: { - filename: './dist-second.js', + filename: "./dist-second.js", }, - name: 'second', - entry: './src/second.js', - mode: 'development', + name: "second", + entry: "./src/second.js", + mode: "development", }, ]; diff --git a/test/watch/bail/no-bail-webpack.config.js b/test/watch/bail/no-bail-webpack.config.js index 8cf031757bd..b55c39fc397 100644 --- a/test/watch/bail/no-bail-webpack.config.js +++ b/test/watch/bail/no-bail-webpack.config.js @@ -1,5 +1,5 @@ module.exports = { devtool: false, - entry: './src/first.js', - mode: 'development', + entry: "./src/first.js", + mode: "development", }; diff --git a/test/watch/bail/src/first.js b/test/watch/bail/src/first.js index fb7e56835c4..6566b640f0b 100644 --- a/test/watch/bail/src/first.js +++ b/test/watch/bail/src/first.js @@ -1 +1 @@ -console.log('bail and watch warning test first'); +console.log("bail and watch warning test first"); diff --git a/test/watch/bail/src/second.js b/test/watch/bail/src/second.js index 5b277372189..aebac93b7f8 100644 --- a/test/watch/bail/src/second.js +++ b/test/watch/bail/src/second.js @@ -1 +1 @@ -console.log('bail and watch warning test second'); +console.log("bail and watch warning test second"); diff --git a/test/watch/bail/watch-webpack.config.js b/test/watch/bail/watch-webpack.config.js index fa93f3f225b..bf6be48c2c7 100644 --- a/test/watch/bail/watch-webpack.config.js +++ b/test/watch/bail/watch-webpack.config.js @@ -1,6 +1,6 @@ module.exports = { devtool: false, - entry: './src/first.js', - mode: 'development', + entry: "./src/first.js", + mode: "development", watch: true, }; diff --git a/test/watch/basic/basic.test.js b/test/watch/basic/basic.test.js index ed0fd817749..a414b432f40 100644 --- a/test/watch/basic/basic.test.js +++ b/test/watch/basic/basic.test.js @@ -1,30 +1,34 @@ -'use strict'; +"use strict"; -const { run, runAndGetProcess, isWebpack5, processKill } = require('../../utils/test-utils'); -const { writeFileSync } = require('fs'); -const { resolve } = require('path'); +const { run, runAndGetProcess, isWebpack5, processKill } = require("../../utils/test-utils"); +const { writeFileSync } = require("fs"); +const { resolve } = require("path"); -const wordsInStatsv4 = ['Hash', 'Built at:', 'main.js']; -const wordsInStatsv5 = ['asset', 'index.js', 'compiled successfully']; +const wordsInStatsv4 = ["Hash", "Built at:", "main.js"]; +const wordsInStatsv5 = ["asset", "index.js", "compiled successfully"]; -describe('basic', () => { - it('should work with negative value', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './watch.config.js', '--no-watch']); +describe("basic", () => { + it("should work with negative value", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./watch.config.js", + "--no-watch", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - it('should recompile upon file change using the `--watch` option', (done) => { - const proc = runAndGetProcess(__dirname, ['--watch', '--mode', 'development']); + it("should recompile upon file change using the `--watch` option", (done) => { + const proc = runAndGetProcess(__dirname, ["--watch", "--mode", "development"]); let modified = false; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { const data = chunk.toString(); - if (data.includes('index.js')) { + if (data.includes("index.js")) { if (isWebpack5) { for (const word of wordsInStatsv5) { expect(data).toContain(word); @@ -37,7 +41,10 @@ describe('basic', () => { if (!modified) { process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');\n`); + writeFileSync( + resolve(__dirname, "./src/index.js"), + `console.log('watch flag test');\n`, + ); }); modified = true; @@ -49,15 +56,15 @@ describe('basic', () => { }); }); - it('should recompile upon file change using the `watch` command', (done) => { - const proc = runAndGetProcess(__dirname, ['watch', '--mode', 'development']); + it("should recompile upon file change using the `watch` command", (done) => { + const proc = runAndGetProcess(__dirname, ["watch", "--mode", "development"]); let modified = false; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { const data = chunk.toString(); - if (data.includes('index.js')) { + if (data.includes("index.js")) { if (isWebpack5) { for (const word of wordsInStatsv5) { expect(data).toContain(word); @@ -70,7 +77,10 @@ describe('basic', () => { if (!modified) { process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');\n`); + writeFileSync( + resolve(__dirname, "./src/index.js"), + `console.log('watch flag test');\n`, + ); }); modified = true; @@ -82,17 +92,22 @@ describe('basic', () => { }); }); - it('should recompile upon file change using the `watch` command and entries syntax', (done) => { - const proc = runAndGetProcess(__dirname, ['watch', './src/entry.js', '--mode', 'development']); + it("should recompile upon file change using the `watch` command and entries syntax", (done) => { + const proc = runAndGetProcess(__dirname, [ + "watch", + "./src/entry.js", + "--mode", + "development", + ]); let modified = false; - const wordsInStatsv5Entries = ['asset', 'entry.js', 'compiled successfully']; + const wordsInStatsv5Entries = ["asset", "entry.js", "compiled successfully"]; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { const data = chunk.toString(); - if (data.includes('entry.js')) { + if (data.includes("entry.js")) { if (isWebpack5) { for (const word of wordsInStatsv5Entries) { expect(data).toContain(word); @@ -105,7 +120,10 @@ describe('basic', () => { if (!modified) { process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/entry.js'), `console.log('watch flag test');\n`); + writeFileSync( + resolve(__dirname, "./src/entry.js"), + `console.log('watch flag test');\n`, + ); }); modified = true; @@ -117,15 +135,21 @@ describe('basic', () => { }); }); - it('should log warning about the `watch` option in the configuration and recompile upon file change using the `watch` command', (done) => { - const proc = runAndGetProcess(__dirname, ['--watch', '--mode', 'development', '--config', './watch.config.js']); + it("should log warning about the `watch` option in the configuration and recompile upon file change using the `watch` command", (done) => { + const proc = runAndGetProcess(__dirname, [ + "--watch", + "--mode", + "development", + "--config", + "./watch.config.js", + ]); let modified = false; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { const data = chunk.toString(); - if (data.includes('index.js')) { + if (data.includes("index.js")) { if (isWebpack5) { for (const word of wordsInStatsv5) { expect(data).toContain(word); @@ -138,7 +162,10 @@ describe('basic', () => { if (!modified) { process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');\n`); + writeFileSync( + resolve(__dirname, "./src/index.js"), + `console.log('watch flag test');\n`, + ); }); modified = true; @@ -149,7 +176,7 @@ describe('basic', () => { } }); - proc.stderr.on('data', (chunk) => { + proc.stderr.on("data", (chunk) => { const data = chunk.toString(); expect(data).toContain( @@ -158,21 +185,21 @@ describe('basic', () => { }); }); - it('should log supplied config with watch', (done) => { - const proc = runAndGetProcess(__dirname, ['watch', '--config', 'log.config.js']); - const configPath = resolve(__dirname, './log.config.js'); + it("should log supplied config with watch", (done) => { + const proc = runAndGetProcess(__dirname, ["watch", "--config", "log.config.js"]); + const configPath = resolve(__dirname, "./log.config.js"); - let stderr = ''; + let stderr = ""; - proc.stderr.on('data', (chunk) => { + proc.stderr.on("data", (chunk) => { const data = chunk.toString(); stderr += data; if (/Compiler finished/.test(data)) { - expect(stderr).toContain('Compiler starting...'); + expect(stderr).toContain("Compiler starting..."); expect(stderr).toContain(`Compiler is using config: '${configPath}'`); - expect(stderr).toContain('Compiler finished'); + expect(stderr).toContain("Compiler finished"); processKill(proc); done(); @@ -180,8 +207,13 @@ describe('basic', () => { }); }); - it('should recompile upon file change using the `command` option and the `--watch` option and log warning', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['watch', '--watch', '--mode', 'development']); + it("should recompile upon file change using the `command` option and the `--watch` option and log warning", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "watch", + "--watch", + "--mode", + "development", + ]); expect(exitCode).toBe(2); expect(stderr).toContain("Error: Unknown option '--watch'"); @@ -189,8 +221,13 @@ describe('basic', () => { expect(stdout).toBeFalsy(); }); - it('should recompile upon file change using the `command` option and the `--no-watch` option and log warning', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ['watch', '--no-watch', '--mode', 'development']); + it("should recompile upon file change using the `command` option and the `--no-watch` option and log warning", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "watch", + "--no-watch", + "--mode", + "development", + ]); expect(exitCode).toBe(2); expect(stderr).toContain("Error: Unknown option '--no-watch'"); diff --git a/test/watch/basic/log.config.js b/test/watch/basic/log.config.js index 70619a29563..5906a9bce94 100644 --- a/test/watch/basic/log.config.js +++ b/test/watch/basic/log.config.js @@ -1,6 +1,6 @@ module.exports = { - mode: 'development', + mode: "development", infrastructureLogging: { - level: 'log', + level: "log", }, }; diff --git a/test/watch/basic/src/entry.js b/test/watch/basic/src/entry.js index 1d8734ee1c8..923312d065f 100644 --- a/test/watch/basic/src/entry.js +++ b/test/watch/basic/src/entry.js @@ -1 +1 @@ -console.log('watch flag test'); +console.log("watch flag test"); diff --git a/test/watch/stats/multi-webpack.config.js b/test/watch/stats/multi-webpack.config.js index 2d865091b99..ac39ad32ead 100644 --- a/test/watch/stats/multi-webpack.config.js +++ b/test/watch/stats/multi-webpack.config.js @@ -1,32 +1,38 @@ -const webpack = require('webpack'); +const webpack = require("webpack"); module.exports = [ { - name: 'first', - mode: 'development', + name: "first", + mode: "development", watch: true, - stats: 'none', + stats: "none", plugins: [ { apply(compiler) { - (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap('webpack-cli-test', () => { - console.log(`webpack ${webpack.version}`); - }); + (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap( + "webpack-cli-test", + () => { + console.log(`webpack ${webpack.version}`); + }, + ); }, }, ], }, { - name: 'two', - mode: 'development', + name: "two", + mode: "development", watch: true, - stats: 'none', + stats: "none", plugins: [ { apply(compiler) { - (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap('webpack-cli-test', () => { - console.log(`webpack ${webpack.version}`); - }); + (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap( + "webpack-cli-test", + () => { + console.log(`webpack ${webpack.version}`); + }, + ); }, }, ], diff --git a/test/watch/stats/stats-and-watch.test.js b/test/watch/stats/stats-and-watch.test.js index 6b34d69ef6f..b2c3beee283 100644 --- a/test/watch/stats/stats-and-watch.test.js +++ b/test/watch/stats/stats-and-watch.test.js @@ -1,24 +1,29 @@ -'use strict'; +"use strict"; -const { runWatch } = require('../../utils/test-utils'); +const { runWatch } = require("../../utils/test-utils"); -describe('stats and watch', () => { +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']); + const { stderr, stdout } = await runWatch(__dirname, ["-c", "./webpack.config.js"]); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); 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']); + const { stderr, stdout } = await runWatch(__dirname, ["-c", "./multi-webpack.config.js"]); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); it('should log stats with the "normal" value in arguments', async () => { - const { stderr, stdout } = await runWatch(__dirname, ['-c', './webpack.config.js', '--stats', 'normal']); + const { stderr, stdout } = await runWatch(__dirname, [ + "-c", + "./webpack.config.js", + "--stats", + "normal", + ]); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); diff --git a/test/watch/stats/webpack.config.js b/test/watch/stats/webpack.config.js index d98762eafc4..c8bf98e63b8 100644 --- a/test/watch/stats/webpack.config.js +++ b/test/watch/stats/webpack.config.js @@ -1,15 +1,18 @@ -const webpack = require('webpack'); +const webpack = require("webpack"); module.exports = { watch: true, - stats: 'none', - mode: 'development', + stats: "none", + mode: "development", plugins: [ { apply(compiler) { - (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap('webpack-cli-test', () => { - console.log(`webpack ${webpack.version}`); - }); + (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap( + "webpack-cli-test", + () => { + console.log(`webpack ${webpack.version}`); + }, + ); }, }, ], diff --git a/test/watch/stdin/multi-serve.config.js b/test/watch/stdin/multi-serve.config.js index ff242580667..9f20565e307 100644 --- a/test/watch/stdin/multi-serve.config.js +++ b/test/watch/stdin/multi-serve.config.js @@ -1,6 +1,6 @@ module.exports = [ { - entry: './src/second.js', + entry: "./src/second.js", }, { watchOptions: { diff --git a/test/watch/stdin/multi-watch.config.js b/test/watch/stdin/multi-watch.config.js index d722eda347a..8c659dd6a5e 100644 --- a/test/watch/stdin/multi-watch.config.js +++ b/test/watch/stdin/multi-watch.config.js @@ -1,6 +1,6 @@ module.exports = [ { - entry: './src/second.js', + entry: "./src/second.js", }, { watch: true, diff --git a/test/watch/stdin/src/second.js b/test/watch/stdin/src/second.js index 1d8734ee1c8..923312d065f 100644 --- a/test/watch/stdin/src/second.js +++ b/test/watch/stdin/src/second.js @@ -1 +1 @@ -console.log('watch flag test'); +console.log("watch flag test"); diff --git a/test/watch/stdin/stdin.test.js b/test/watch/stdin/stdin.test.js index fe22ebf15d8..cf7aa960c4f 100644 --- a/test/watch/stdin/stdin.test.js +++ b/test/watch/stdin/stdin.test.js @@ -1,12 +1,12 @@ -const { runAndGetProcess, processKill } = require('../../utils/test-utils'); +const { runAndGetProcess, processKill } = require("../../utils/test-utils"); -describe('--watch-options-stdin', () => { +describe("--watch-options-stdin", () => { it('should stop the process when stdin ends using "--watch" and "--watch-options-stdin" options', (done) => { - const proc = runAndGetProcess(__dirname, ['--watch', '--watch-options-stdin']); + const proc = runAndGetProcess(__dirname, ["--watch", "--watch-options-stdin"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); @@ -20,11 +20,11 @@ describe('--watch-options-stdin', () => { }); it('should stop the process when stdin ends using the "watch" command and the "--watch-options-stdin" option', (done) => { - const proc = runAndGetProcess(__dirname, ['watch', '--watch-options-stdin']); + const proc = runAndGetProcess(__dirname, ["watch", "--watch-options-stdin"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); @@ -37,12 +37,12 @@ describe('--watch-options-stdin', () => { }); }); - it('should stop the process when stdin ends using the config file', (done) => { - const proc = runAndGetProcess(__dirname, ['--config', './watch.config.js']); + it("should stop the process when stdin ends using the config file", (done) => { + const proc = runAndGetProcess(__dirname, ["--config", "./watch.config.js"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); @@ -55,12 +55,12 @@ describe('--watch-options-stdin', () => { }); }); - it('should stop the process when stdin ends using the config file in multi compiler mode', (done) => { - const proc = runAndGetProcess(__dirname, ['--config', './multi-watch.config.js']); + it("should stop the process when stdin ends using the config file in multi compiler mode", (done) => { + const proc = runAndGetProcess(__dirname, ["--config", "./multi-watch.config.js"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); @@ -74,11 +74,11 @@ describe('--watch-options-stdin', () => { }); it('should stop the process when stdin ends using the "serve" command and the "--watch-options-stdin" option', (done) => { - const proc = runAndGetProcess(__dirname, ['serve', '--watch-options-stdin']); + const proc = runAndGetProcess(__dirname, ["serve", "--watch-options-stdin"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); done(); @@ -90,11 +90,11 @@ describe('--watch-options-stdin', () => { }); it('should stop the process when stdin ends using the "serve" command and the "--stdin" option', (done) => { - const proc = runAndGetProcess(__dirname, ['serve', '--stdin']); + const proc = runAndGetProcess(__dirname, ["serve", "--stdin"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); done(); @@ -106,11 +106,11 @@ describe('--watch-options-stdin', () => { }); it('should stop the process when stdin ends using the "serve" command and configuration', (done) => { - const proc = runAndGetProcess(__dirname, ['serve', '--config', './serve.config.js']); + const proc = runAndGetProcess(__dirname, ["serve", "--config", "./serve.config.js"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); done(); @@ -122,11 +122,11 @@ describe('--watch-options-stdin', () => { }); it('should stop the process when stdin ends using the "serve" command and the config file in multi compiler mode', (done) => { - const proc = runAndGetProcess(__dirname, ['--config', './multi-watch.config.js']); + const proc = runAndGetProcess(__dirname, ["--config", "./multi-watch.config.js"]); let semaphore = false; - proc.on('exit', () => { + proc.on("exit", () => { expect(semaphore).toBe(true); processKill(proc); diff --git a/test/watch/watch-variable/watch-variable.test.js b/test/watch/watch-variable/watch-variable.test.js index 19f35f13411..dc79871fdcc 100644 --- a/test/watch/watch-variable/watch-variable.test.js +++ b/test/watch/watch-variable/watch-variable.test.js @@ -1,24 +1,24 @@ -'use strict'; +"use strict"; -const { runAndGetProcess, isWebpack5, processKill } = require('../../utils/test-utils'); -const { writeFileSync } = require('fs'); -const { resolve } = require('path'); +const { runAndGetProcess, isWebpack5, processKill } = require("../../utils/test-utils"); +const { writeFileSync } = require("fs"); +const { resolve } = require("path"); -const wordsInStatsv4 = ['Hash', 'Built at:', 'main.js']; -const wordsInStatsv5 = ['asset', 'index.js', 'compiled successfully']; +const wordsInStatsv4 = ["Hash", "Built at:", "main.js"]; +const wordsInStatsv5 = ["asset", "index.js", "compiled successfully"]; -describe('watch variable', () => { - it('should pass `WEBPACK_WATCH` env variable and recompile upon file change using the `watch` command', (done) => { - const proc = runAndGetProcess(__dirname, ['watch', '--mode', 'development']); +describe("watch variable", () => { + it("should pass `WEBPACK_WATCH` env variable and recompile upon file change using the `watch` command", (done) => { + const proc = runAndGetProcess(__dirname, ["watch", "--mode", "development"]); let modified = false; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { const data = chunk.toString(); - expect(data).not.toContain('FAIL'); + expect(data).not.toContain("FAIL"); - if (data.includes('index.js')) { + if (data.includes("index.js")) { if (isWebpack5) { for (const word of wordsInStatsv5) { expect(data).toContain(word); @@ -31,7 +31,10 @@ describe('watch variable', () => { if (!modified) { process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');`); + writeFileSync( + resolve(__dirname, "./src/index.js"), + `console.log('watch flag test');`, + ); }); modified = true; @@ -43,17 +46,17 @@ describe('watch variable', () => { }); }); - it.only('should pass `WEBPACK_WATCH` env variable and recompile upon file change using the `--watch` option', (done) => { - const proc = runAndGetProcess(__dirname, ['--watch', '--mode', 'development']); + it.only("should pass `WEBPACK_WATCH` env variable and recompile upon file change using the `--watch` option", (done) => { + const proc = runAndGetProcess(__dirname, ["--watch", "--mode", "development"]); let modified = false; - proc.stdout.on('data', (chunk) => { + proc.stdout.on("data", (chunk) => { const data = chunk.toString(); - expect(data).not.toContain('FAIL'); + expect(data).not.toContain("FAIL"); - if (data.includes('index.js')) { + if (data.includes("index.js")) { if (isWebpack5) { for (const word of wordsInStatsv5) { expect(data).toContain(word); @@ -66,7 +69,10 @@ describe('watch variable', () => { if (!modified) { process.nextTick(() => { - writeFileSync(resolve(__dirname, './src/index.js'), `console.log('watch flag test');`); + writeFileSync( + resolve(__dirname, "./src/index.js"), + `console.log('watch flag test');`, + ); }); modified = true; diff --git a/test/watch/watch-variable/webpack.config.js b/test/watch/watch-variable/webpack.config.js index a177e2cf731..1cc1d2ce126 100644 --- a/test/watch/watch-variable/webpack.config.js +++ b/test/watch/watch-variable/webpack.config.js @@ -5,11 +5,11 @@ class CustomTestPlugin { this.isInEnvironment = isInEnvironment; } apply(compiler) { - compiler.hooks.done.tap('testPlugin', () => { + compiler.hooks.done.tap("testPlugin", () => { if (!isInProcess && this.isInEnvironment) { - console.log('PASS'); + console.log("PASS"); } else { - console.log('FAIL'); + console.log("FAIL"); } }); } @@ -17,7 +17,7 @@ class CustomTestPlugin { module.exports = (env) => { return { - mode: 'development', + mode: "development", devtool: false, plugins: [new CustomTestPlugin(env.WEBPACK_WATCH)], };