From 56a765abc1a32532288e07ee3d58ca97120ccf5e Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 15 May 2021 18:07:46 +0530 Subject: [PATCH 1/3] fix: prettier config --- .codecov.yml | 4 +- .eslintrc.js | 33 +- .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 | 31 +- lint-staged.config.js | 4 +- open-bot.yml | 124 +-- packages/configtest/src/index.ts | 14 +- packages/generators/README.md | 2 +- .../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 | 35 +- packages/generators/src/handlers.ts | 2 +- packages/generators/src/handlers/default.ts | 126 ++- packages/generators/src/index.ts | 98 +-- packages/generators/src/init-generator.ts | 51 +- packages/generators/src/loader-generator.ts | 18 +- packages/generators/src/plugin-generator.ts | 16 +- 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 | 28 +- packages/info/src/index.ts | 57 +- packages/serve/src/index.ts | 27 +- packages/serve/src/startDevServer.ts | 24 +- packages/serve/src/types.ts | 14 +- packages/webpack-cli/bin/cli.js | 24 +- packages/webpack-cli/lib/bootstrap.js | 4 +- packages/webpack-cli/lib/index.js | 4 +- packages/webpack-cli/lib/plugins/CLIPlugin.js | 28 +- .../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 | 12 +- 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 | 711 +++++++---------- prettier.config.js | 4 +- scripts/cleanupTest.js | 19 +- scripts/globalSetup.js | 2 +- scripts/prepareSuite.js | 16 +- scripts/setupBuild.js | 6 +- scripts/snapshotResolver.js | 18 +- scripts/updateDocs.js | 18 +- scripts/utils.js | 8 +- setupTest.js | 2 +- smoketests/helpers.js | 64 +- smoketests/index.js | 16 +- .../configtest.test.js | 12 +- .../generator.test.js | 12 +- .../missing-command-packages/info.test.js | 12 +- .../missing-command-packages/serve.test.js | 12 +- smoketests/missing-packages/prettier.test.js | 28 +- .../webpack-bundle-analyzer.test.js | 12 +- .../webpack-dev-server.test.js | 14 +- smoketests/missing-packages/webpack.test.js | 10 +- test/api/CLI.test.js | 722 +++++++++--------- test/api/capitalizeFirstLetter.test.js | 12 +- test/api/get-package-manager.test.js | 88 +-- test/api/prompt-installation.test.js | 92 +-- test/api/prompt.test.js | 38 +- test/api/resolveConfig/env.webpack.config.cjs | 2 +- test/api/resolveConfig/resolveConfig.test.js | 54 +- 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 | 72 +- test/build/analyze/analyze-flag.test.js | 10 +- test/build/analyze/analyze.config.js | 6 +- 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 | 12 +- 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 | 64 +- 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 | 32 +- .../build-variable/build-variable.test.js | 10 +- test/build/build-variable/webpack.config.js | 8 +- test/build/build-warnings/warnings.test.js | 36 +- .../bundle-variable/bundle-variable.test.js | 10 +- test/build/bundle-variable/webpack.config.js | 8 +- test/build/cache/cache.test.js | 130 ++-- 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 | 74 +- 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 | 14 +- 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 | 16 +- 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 | 14 +- .../config-lookup/relative/webpack.config.js | 8 +- test/build/config-name/config-name.test.js | 94 +-- 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 | 14 +- .../config/absent/webpack.config-absent.js | 8 +- test/build/config/basic/a.js | 2 +- test/build/config/basic/basic-config.test.js | 17 +- 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 | 24 +- .../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 | 12 +- .../empty-function/empty-function.test.js | 12 +- .../empty-promise/empty-promise.test.js | 12 +- test/build/config/empty/empty.test.js | 12 +- .../error-array/config-array-error.test.js | 12 +- .../error-commonjs/config-error.test.js | 20 +- .../config/error-commonjs/webpack.config.js | 6 +- .../config/error-mjs/config-error.test.js | 20 +- .../build/config/error-mjs/webpack.config.mjs | 6 +- .../config/function/functional-config.test.js | 30 +- .../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 | 14 +- .../config/invalid-export/webpack.config.js | 2 +- test/build/config/invalid-path/a.js | 2 +- .../config/invalid-path/invalid-path.test.js | 14 +- .../config/invalid-path/webpack.config.js | 8 +- .../config/multiple-with-one-compilation/a.js | 2 +- .../multiple-with-one-compilation.test.js | 17 +- .../webpack.config.js | 8 +- test/build/config/multiple/init.js | 2 +- .../config/multiple/multiple-config.test.js | 14 +- test/build/config/multiple/webpack1.config.js | 12 +- test/build/config/multiple/webpack2.config.js | 12 +- .../no-config-array/no-config-array.test.js | 12 +- test/build/config/no-config-object/a.js | 2 +- .../no-config-object/no-config-object.test.js | 12 +- .../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 | 18 +- 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 | 26 +- .../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 | 18 +- .../type/function-array/webpack.config.js | 16 +- test/build/config/type/function-async/a.js | 2 +- .../function-async/function-async.test.js | 16 +- .../type/function-async/webpack.config.js | 6 +- test/build/config/type/function-promise/a.js | 2 +- .../function-promise/function-promise.test.js | 16 +- .../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 | 130 ++-- .../type/function-with-env/webpack.config.js | 30 +- .../function-with-env/webpack.env.config.js | 14 +- test/build/config/type/function/a.js | 2 +- .../config/type/function/function.test.js | 16 +- .../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 | 211 ++--- test/build/core-flags/context-flag.test.js | 20 +- .../core-flags/dependencies-flag.test.js | 16 +- test/build/core-flags/devtool-flag.test.js | 20 +- .../build/core-flags/entry-reset-flag.test.js | 20 +- .../build/core-flags/experiments-flag.test.js | 22 +- test/build/core-flags/externals-flags.test.js | 26 +- .../ignore-warnings-flag.test.js | 26 +- .../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 | 18 +- test/build/core-flags/invalid-flag.test.js | 10 +- test/build/core-flags/mock/mock.js | 2 +- test/build/core-flags/module-flags.test.js | 119 ++- test/build/core-flags/node-flags.test.js | 20 +- .../core-flags/optimization-flags.test.js | 66 +- test/build/core-flags/output-flags.test.js | 128 ++-- .../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 | 24 +- test/build/core-flags/resolve-flags.test.js | 98 ++- test/build/core-flags/snapshot-flags.test.js | 26 +- test/build/core-flags/src/entry.js | 2 +- test/build/core-flags/src/main.js | 2 +- test/build/core-flags/stats-flags.test.js | 46 +- test/build/core-flags/watch-flags.test.js | 30 +- 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 | 18 +- test/build/custom-webpack/webpack.config.js | 2 +- test/build/defaults/a.js | 2 +- test/build/defaults/output-defaults.test.js | 28 +- .../devtool/array/source-map-array.test.js | 18 +- test/build/devtool/array/webpack.config.js | 28 +- .../devtool/object/source-map-object.test.js | 44 +- .../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 | 32 +- test/build/entry/flag-entry/src/a.js | 2 +- test/build/entry/flag-entry/src/index.cjs | 2 +- .../multiple-entries/multi-entries.test.js | 22 +- 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 | 60 +- .../invalid-schema/webpack.mock.config.js | 2 +- .../webpack.plugin-mock.config.js | 6 +- test/build/hot/hot-flag.test.js | 42 +- test/build/hot/webpack.config.js | 4 +- test/build/import-local/import-local.test.js | 10 +- test/build/json/json.test.js | 112 +-- test/build/json/logging.config.js | 2 +- test/build/merge/config-absent/1.js | 2 +- .../config-absent/merge-config-absent.test.js | 14 +- 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 | 40 +- test/build/merge/config/second-entry.js | 2 +- test/build/merge/config/third-entry.js | 2 +- .../mode-single-arg/mode-single-arg.test.js | 30 +- .../mode/mode-single-arg/webpack.config.js | 4 +- .../mode-with-config/mode-with-config.test.js | 55 +- .../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 | 18 +- 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 | 38 +- 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 | 44 +- 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 | 28 +- test/build/prefetch/src/p.js | 4 +- test/build/progress/progress-flag.test.js | 32 +- .../build/progress/webpack.progress.config.js | 4 +- .../start-finish-force-log.test.js | 36 +- .../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 | 68 +- test/build/stats/flags/webpack.config.js | 6 +- .../target/flag-test/target-flag.test.js | 52 +- 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 | 170 ++--- .../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 | 42 +- .../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 | 328 ++++---- test/info/info-output.test.js | 62 +- test/info/info-unknown.test.js | 8 +- test/init/init.test.js | 286 +++---- 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 | 92 +-- .../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 | 90 +-- .../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 | 429 +++++------ 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 | 38 +- .../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 | 79 +- test/utils/test-utils.test.js | 70 +- test/utils/webpack-cli-test-plugin.js | 4 +- test/version/version.test.js | 326 ++++---- test/watch/analyze/analyze-flag.test.js | 10 +- test/watch/analyze/analyze.config.js | 6 +- 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 | 22 +- 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 | 88 ++- test/watch/basic/log.config.js | 4 +- test/watch/basic/src/entry.js | 2 +- test/watch/stats/multi-webpack.config.js | 18 +- test/watch/stats/stats-and-watch.test.js | 12 +- test/watch/stats/webpack.config.js | 8 +- 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 | 38 +- test/watch/watch-variable/webpack.config.js | 8 +- 458 files changed, 4938 insertions(+), 5489 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..474502795fd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,12 +1,12 @@ 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 +15,26 @@ 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..3574c711f1b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,25 +1,24 @@ -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']; +const ignorePattern = 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..cb1e3b16ddf 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,7 @@ 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..6dd959946b2 100644 --- a/packages/generators/README.md +++ b/packages/generators/README.md @@ -19,7 +19,7 @@ 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..586fd129656 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 @@ -59,14 +59,7 @@ const addonGenerator = ( if (!this.supportedTemplates.includes(this.template)) { 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:', - this.supportedTemplates, - 'default', - false, - ); + const { selectedTemplate } = await List(this, "selectedTemplate", "Select a valid template from below:", this.supportedTemplates, "default", false); this.template = selectedTemplate; } @@ -88,7 +81,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 +89,9 @@ const addonGenerator = ( } public writing(): void { - const packageJsonTemplatePath = '../addon-template/package.json.js'; + 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)); + this.fs.extendJSON(this.destinationPath("package.json"), require(packageJsonTemplatePath)(this.props.name)); let files = []; try { @@ -110,20 +103,20 @@ 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 +125,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..3b67e66d4a4 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); }; @@ -15,104 +15,68 @@ const resolveFile = (file: string): string => { // eslint-disable-next-line @typescript-eslint/no-explicit-any export async function questions(self: CustomGenerator, 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', - self.force, - ); + const { langType } = await Question.List(self, "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?', - true, - self.force, - ); + const { htmlWebpackPlugin } = await Question.Confirm(self, "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 self.answers = { ...self.answers, langType, devServer, htmlWebpackPlugin }; // Handle CSS solutions - const { cssType } = await Question.List( - self, - 'cssType', - 'Which of the following CSS solutions do you want to use?', - ['none', 'CSS only', 'SASS', 'LESS', 'Stylus'], - 'none', - self.force, - ); + const { cssType } = await Question.List(self, "cssType", "Which of the following CSS solutions do you want to use?", ["none", "CSS only", "SASS", "LESS", "Stylus"], "none", self.force); - if (cssType == 'none') { - self.answers = { ...self.answers, cssType, isCSS: false, isPostCSS: false, extractPlugin: 'No' }; + if (cssType == "none") { + self.answers = { ...self.answers, cssType, isCSS: false, isPostCSS: false, extractPlugin: "No" }; return; } - const { isCSS } = - cssType != 'CSS only' - ? await Question.Confirm(self, 'isCSS', `Will you be using CSS styles along with ${cssType} in your project?`, true, self.force) - : { isCSS: true }; - - const { isPostCSS } = await Question.Confirm( - self, - 'isPostCSS', - 'Will you be using PostCSS in your project?', - cssType == 'CSS only', - self.force, - ); + const { isCSS } = cssType != "CSS only" ? await Question.Confirm(self, "isCSS", `Will you be using CSS styles along with ${cssType} in your project?`, true, self.force) : { isCSS: true }; - const { extractPlugin } = await Question.List( - self, - 'extractPlugin', - 'Do you want to extract CSS for every file?', - ['No', 'Only for Production', 'Yes'], - 'No', - self.force, - ); + const { isPostCSS } = await Question.Confirm(self, "isPostCSS", "Will you be using PostCSS in your project?", cssType == "CSS only", self.force); + + const { extractPlugin } = await Question.List(self, "extractPlugin", "Do you want to extract CSS for every file?", ["No", "Only for Production", "Yes"], "No", self.force); switch (cssType) { - case 'SASS': - self.dependencies = [...self.dependencies, 'sass-loader', 'sass']; + case "SASS": + self.dependencies = [...self.dependencies, "sass-loader", "sass"]; break; - case 'LESS': - self.dependencies = [...self.dependencies, 'less-loader', 'less']; + case "LESS": + self.dependencies = [...self.dependencies, "less-loader", "less"]; break; - case 'Stylus': - self.dependencies = [...self.dependencies, 'stylus-loader', 'stylus']; + case "Stylus": + self.dependencies = [...self.dependencies, "stylus-loader", "stylus"]; break; } if (isCSS) { - self.dependencies = [...self.dependencies, 'style-loader', 'css-loader']; + self.dependencies = [...self.dependencies, "style-loader", "css-loader"]; } if (isPostCSS) { - self.dependencies = [...self.dependencies, 'postcss-loader', 'postcss', 'autoprefixer']; + self.dependencies = [...self.dependencies, "postcss-loader", "postcss", "autoprefixer"]; } - if (extractPlugin !== 'No') { - self.dependencies = [...self.dependencies, 'mini-css-extract-plugin']; + if (extractPlugin !== "No") { + self.dependencies = [...self.dependencies, "mini-css-extract-plugin"]; } self.answers = { ...self.answers, cssType, isCSS, isPostCSS, extractPlugin }; @@ -124,42 +88,42 @@ 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 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..55920dbcd28 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,7 @@ 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) { @@ -60,14 +60,7 @@ 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`); - const { selectedTemplate } = await Question.List( - this, - 'selectedTemplate', - 'Select a valid template from below:', - this.supportedTemplates, - 'default', - false, - ); + const { selectedTemplate } = await Question.List(this, "selectedTemplate", "Select a valid template from below:", this.supportedTemplates, "default", false); this.template = selectedTemplate; } @@ -77,18 +70,12 @@ 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?', - true, - false, - ); + const { installPrettier } = await Question.Confirm(this, "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 +84,14 @@ 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 }); } 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,9 +99,9 @@ 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.`)}`); 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..1c8243b681f 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,15 +13,15 @@ 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'), + path.resolve(__dirname, "../plugin-template"), (gen): Record => ({ name: toUpperCamelCase(gen.props.name) }), ); 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..fd556a3fa5e 100644 --- a/packages/generators/src/utils/scaffold-utils.ts +++ b/packages/generators/src/utils/scaffold-utils.ts @@ -1,23 +1,16 @@ -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 }>; /* eslint-disable @typescript-eslint/no-explicit-any */ -export function List( - self: Generator, - name: string, - message: string, - choices: string[], - defaultChoice?: string, - skip = false, -): CustomGeneratorStringPrompt { +export function List(self: Generator, name: string, message: string, choices: string[], defaultChoice?: string, skip = false): CustomGeneratorStringPrompt { if (skip) { 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 { @@ -25,22 +18,15 @@ export function Input(self: Generator, name: string, message: string, defaultCho return { [name]: defaultChoice }; } - return self.prompt([{ default: defaultChoice, message, name, type: 'input' }]); + return self.prompt([{ default: defaultChoice, message, name, type: "input" }]); } -export function InputValidate( - self: Generator, - name: string, - message: string, - cb?: (input: string) => string | boolean, - defaultChoice?: string, - skip = false, -): Record | any { +export function InputValidate(self: Generator, name: string, message: string, cb?: (input: string) => string | boolean, defaultChoice?: string, skip = false): Record | any { if (skip) { 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; @@ -54,5 +40,5 @@ export function Confirm(self: Generator, name: string, message: string, defaultC 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..3fa2c092bd9 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,12 @@ interface Information { } const DEFAULT_DETAILS: Information = { - Binaries: ['Node', 'Yarn', 'npm'], - Browsers: [ - '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*', + Binaries: ["Node", "Yarn", "npm"], + Browsers: ["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*", }; class InfoCommand { @@ -36,22 +25,22 @@ 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 +50,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 +67,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..8232be361cb 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 = []; @@ -43,7 +43,7 @@ class ServeCommand { process.exit(2); } - const builtInOptions = cli.getBuiltInOptions().filter((option) => option.name !== 'watch'); + const builtInOptions = cli.getBuiltInOptions().filter((option) => option.name !== "watch"); return [...builtInOptions, ...devServerFlags]; }, @@ -68,15 +68,12 @@ class ServeCommand { for (const optionName in options) { 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); + const isBuiltInOption = 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, - ); + const needToProcess = devServerFlags.find((devServerOption) => devServerOption.name === kebabedOption && devServerOption.processor); if (needToProcess) { processors.push(needToProcess.processor); @@ -112,7 +109,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..0f2b68814af 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"; /** * @@ -15,19 +15,14 @@ import { devServerOptionsType } from './types'; * @returns {Object[]} array of resulting servers */ -export default async function startDevServer( - compiler: any, - devServerCliOptions: any, - cliOptions: any, - logger: any, -): Promise[]> { +export default async function startDevServer(compiler: any, devServerCliOptions: any, cliOptions: any, logger: any): Promise[]> { let devServerVersion, Server; 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}`); process.exit(2); @@ -62,7 +57,7 @@ export default async function startDevServer( compilersWithDevServerOption = [compiler]; } - const isDevServer4 = devServerVersion.startsWith('4'); + const isDevServer4 = devServerVersion.startsWith("4"); const usedPorts = []; const devServersOptions = []; @@ -71,8 +66,7 @@ export default async function startDevServer( if (!isDevServer4) { const getPublicPathOption = (): string => { - const normalizePublicPath = (publicPath): string => - typeof publicPath === 'undefined' || publicPath === 'auto' ? '/' : publicPath; + const normalizePublicPath = (publicPath): string => (typeof publicPath === "undefined" || publicPath === "auto" ? "/" : publicPath); if (cliOptions.outputPublicPath) { return normalizePublicPath(compilerWithDevServerOption.options.output.publicPath); @@ -97,7 +91,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(); @@ -107,9 +101,7 @@ export default async function startDevServer( const portNumber = Number(options.port); 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.', - ); + 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."); } usedPorts.push(portNumber); 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..8d86a1ffb63 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,23 @@ 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..57d8333d5e9 100644 --- a/packages/webpack-cli/lib/plugins/CLIPlugin.js +++ b/packages/webpack-cli/lib/plugins/CLIPlugin.js @@ -4,7 +4,7 @@ class CLIPlugin { } setupHotPlugin(compiler) { - const { HotModuleReplacementPlugin } = compiler.webpack || require('webpack'); + const { HotModuleReplacementPlugin } = compiler.webpack || require("webpack"); const hotModuleReplacementPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin)); if (!hotModuleReplacementPlugin) { @@ -13,14 +13,14 @@ 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 } = require("webpack-bundle-analyzer"); const bundleAnalyzerPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof BundleAnalyzerPlugin)); if (!bundleAnalyzerPlugin) { @@ -29,17 +29,17 @@ class CLIPlugin { } setupProgressPlugin(compiler) { - const { ProgressPlugin } = compiler.webpack || require('webpack'); + 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 +53,10 @@ 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}'`); } }); @@ -69,10 +69,10 @@ class CLIPlugin { 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 +86,18 @@ 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..8b8df03a015 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,15 @@ 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..e2fed178b7d 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -1,31 +1,29 @@ -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), - ); + const alreadyLoaded = this.program.commands.find((command) => command.name() === commandOptions.name.split(" ")[0] || command.aliases().includes(commandOptions.alias)); if (alreadyLoaded) { return; @@ -54,7 +52,7 @@ class WebpackCLI { if (commandOptions.pkg) { command.pkg = commandOptions.pkg; } else { - command.pkg = 'webpack-cli'; + command.pkg = "webpack-cli"; } const { forHelp } = this.program; @@ -76,23 +74,15 @@ class WebpackCLI { const { promptInstallation, colors } = this.utils; await promptInstallation(dependency, () => { - this.logger.error( - `For using '${colors.green(commandOptions.name.split(' ')[0])}' command you need to install: '${colors.green( - dependency, - )}' package`, - ); + this.logger.error(`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 - .map((dependency) => `'${dependency}'`) - .join(',')}.`, - ); + command.description(`${commandOptions.description} To see all available options you need to install ${commandOptions.dependencies.map((dependency) => `'${dependency}'`).join(",")}.`); options = []; } else { options = options(); @@ -120,36 +110,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 +161,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, @@ -187,7 +177,7 @@ class WebpackCLI { mainOption = { flags: option.alias ? `-${option.alias}, --${option.name}` : `--${option.name}`, // TODO `describe` used by `webpack-dev-server@3` - description: option.description || option.describe || '', + 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, @@ -202,9 +192,9 @@ class WebpackCLI { } 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) { @@ -249,9 +239,7 @@ class WebpackCLI { command.addOption(optionForCommand); } else { - const optionForCommand = new Option(mainOption.flags, mainOption.description) - .argParser(Array.from(mainOption.type)[0]) - .default(mainOption.defaultValue); + const optionForCommand = new Option(mainOption.flags, mainOption.description).argParser(Array.from(mainOption.type)[0]).default(mainOption.defaultValue); optionForCommand.helpLevel = option.helpLevel; @@ -310,54 +298,37 @@ class WebpackCLI { return this.builtInOptionsCache; } - const minimumHelpFlags = [ - 'config', - 'config-name', - 'merge', - 'env', - 'mode', - 'watch', - 'watch-options-stdin', - 'stats', - 'devtool', - 'entry', - 'target', - 'progress', - 'json', - 'name', - 'output-path', - 'node-env', - ]; + const minimumHelpFlags = ["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 +336,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 +354,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 +372,187 @@ 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,10 +563,10 @@ 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" }; }) : []; @@ -603,7 +574,7 @@ class WebpackCLI { .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 +585,7 @@ class WebpackCLI { } applyNodeEnv(options) { - if (typeof options.nodeEnv === 'string') { + if (typeof options.nodeEnv === "string") { process.env.NODE_ENV = options.nodeEnv; } } @@ -622,80 +593,69 @@ 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', + 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", }, ]; - const knownCommands = [ - buildCommandOptions, - watchCommandOptions, - versionCommandOptions, - helpCommandOptions, - ...externalBuiltInCommandsInfo, - ]; - 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), - ); + const knownCommands = [buildCommandOptions, watchCommandOptions, versionCommandOptions, helpCommandOptions, ...externalBuiltInCommandsInfo]; + 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)); const isCommand = (input, commandOptions) => { const longName = getCommandName(commandOptions.name); @@ -713,16 +673,9 @@ class WebpackCLI { return false; }; - const findCommandByName = (name) => - 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'; + const findCommandByName = (name) => 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"; const loadCommandByName = async (commandName, allowToInstall = false) => { const isBuildCommandUsed = isCommand(commandName, buildCommandOptions); @@ -731,17 +684,13 @@ class WebpackCLI { if (isBuildCommandUsed || isWatchCommandUsed) { const options = this.getBuiltInOptions(); - await this.makeCommand( - isBuildCommandUsed ? buildCommandOptions : watchCommandOptions, - isWatchCommandUsed ? options.filter((option) => option.name !== 'watch') : options, - async (entries, options) => { - if (entries.length > 0) { - options.entry = [...entries, ...(options.entry || [])]; - } + await this.makeCommand(isBuildCommandUsed ? buildCommandOptions : watchCommandOptions, isWatchCommandUsed ? options.filter((option) => option.name !== "watch") : options, async (entries, options) => { + if (entries.length > 0) { + options.entry = [...entries, ...(options.entry || [])]; + } - await this.buildCommand(options, isWatchCommandUsed); - }, - ); + await this.buildCommand(options, isWatchCommandUsed); + }); } else if (isCommand(commandName, helpCommandOptions)) { // Stub for the `help` command this.makeCommand(helpCommandOptions, [], () => {}); @@ -752,9 +701,7 @@ class WebpackCLI { const builtInExternalCommandInfo = externalBuiltInCommandsInfo.find( (externalBuiltInCommandInfo) => getCommandName(externalBuiltInCommandInfo.name) === commandName || - (Array.isArray(externalBuiltInCommandInfo.alias) - ? externalBuiltInCommandInfo.alias.includes(commandName) - : externalBuiltInCommandInfo.alias === commandName), + (Array.isArray(externalBuiltInCommandInfo.alias) ? externalBuiltInCommandInfo.alias.includes(commandName) : externalBuiltInCommandInfo.alias === commandName), ); let pkg; @@ -765,7 +712,7 @@ class WebpackCLI { pkg = commandName; } - if (pkg !== 'webpack-cli' && !this.utils.packageExists(pkg)) { + if (pkg !== "webpack-cli" && !this.utils.packageExists(pkg)) { if (!allowToInstall) { return; } @@ -811,26 +758,26 @@ 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); @@ -862,15 +809,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; @@ -882,11 +829,7 @@ class WebpackCLI { const outputVersion = async (options) => { // Filter `bundle`, `watch`, `version` and `help` commands const possibleCommandNames = options.filter( - (option) => - !isCommand(option, buildCommandOptions) && - !isCommand(option, watchCommandOptions) && - !isCommand(option, versionCommandOptions) && - !isCommand(option, helpCommandOptions), + (option) => !isCommand(option, buildCommandOptions) && !isCommand(option, watchCommandOptions) && !isCommand(option, versionCommandOptions) && !isCommand(option, helpCommandOptions), ); possibleCommandNames.forEach((possibleCommandName) => { @@ -922,30 +865,27 @@ class WebpackCLI { } } - 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}`); } process.exit(0); }; - this.program.option( - '-v, --version', - "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", - ); + this.program.option("-v, --version", "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands."); const outputHelp = async (options, isVerbose, isHelpCommandSyntax, program) => { const { bold } = this.utils.colors; const outputIncorrectUsageOfHelp = () => { - this.logger.error('Incorrect use of 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 +899,28 @@ class WebpackCLI { sortSubcommands: true, // Support multiple aliases commandUsage: (command) => { - let parentCmdNames = ''; + let parentCmdNames = ""; 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:', - )} ${parentCmdNames}[command] [options]`; + return `${parentCmdNames}${command.usage()}\n${this.utils.colors.bold("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 +929,9 @@ class WebpackCLI { } switch (option.helpLevel) { - case 'verbose': + case "verbose": return isVerbose; - case 'minimum': + case "minimum": default: return true; } @@ -1026,57 +962,47 @@ class WebpackCLI { 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.' - : helper.commandDescription(command); + const commandDescription = isGlobalHelp ? "The build tool for modern web applications." : helper.commandDescription(command); if (commandDescription.length > 0) { - output = output.concat([commandDescription, '']); + output = output.concat([commandDescription, ""]); } // Arguments - const argumentList = helper - .visibleArguments(command) - .map((argument) => formatItem(argument.term, argument.description)); + const argumentList = helper.visibleArguments(command).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))); + const optionList = helper.visibleOptions(command).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 - const globalOptionList = program.options.map((option) => - formatItem(helper.optionTerm(option), helper.optionDescription(option)), - ); + const globalOptionList = program.options.map((option) => formatItem(helper.optionTerm(option), helper.optionDescription(option))); 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))); + const commandList = helper.visibleCommands(isGlobalHelp ? program : 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"); }, }); @@ -1098,10 +1024,8 @@ class WebpackCLI { const command = findCommandByName(name); if (!command) { - const builtInCommandUsed = externalBuiltInCommandsInfo.find( - (command) => command.name.includes(name) || name === command.alias, - ); - if (typeof builtInCommandUsed !== 'undefined') { + 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`); } else { this.logger.error(`Can't find and load command '${name}'`); @@ -1149,31 +1073,24 @@ class WebpackCLI { process.exit(2); } - const nameOutput = - option.flags.replace(/^.+[[<]/, '').replace(/(\.\.\.)?[\]>].*$/, '') + (option.variadic === true ? '...' : ''); - const value = option.required ? '<' + nameOutput + '>' : option.optional ? '[' + nameOutput + ']' : ''; + const 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}` : ''}`, - ); + this.logger.raw(`${bold("Usage")}: webpack${isCommandSpecified ? ` ${commandName}` : ""} ${option.long}${value ? ` ${value}` : ""}`); if (option.short) { - this.logger.raw( - `${bold('Short:')} webpack${isCommandSpecified ? ` ${commandName}` : ''} ${option.short}${ - value ? ` ${value}` : '' - }`, - ); + this.logger.raw(`${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'); @@ -1183,42 +1100,42 @@ class WebpackCLI { } 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(`${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') { + 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 +1152,13 @@ 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) { @@ -1269,16 +1186,10 @@ class WebpackCLI { } else { this.logger.error(`Unknown command or entry '${operand}'`); - const found = knownCommands.find( - (commandOptions) => this.utils.levenshtein.distance(operand, getCommandName(commandOptions.name)) < 3, - ); + const found = knownCommands.find((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 - }')?`, - ); + this.logger.error(`Did you mean '${getCommandName(found.name)}' (alias '${Array.isArray(found.alias) ? found.alias.join(", ") : found.alias}')?`); } this.logger.error("Run 'webpack --help' to see available commands and options"); @@ -1286,7 +1197,7 @@ 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); @@ -1311,7 +1222,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); } @@ -1341,11 +1252,7 @@ class WebpackCLI { Module.prototype._compile = previousModuleCompile; } - if ( - (error.code === 'ERR_REQUIRE_ESM' || process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) && - pathToFileURL && - dynamicImportLoader - ) { + if ((error.code === "ERR_REQUIRE_ESM" || process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) && pathToFileURL && dynamicImportLoader) { const urlForConfig = pathToFileURL(configPath); options = await dynamicImportLoader(urlForConfig); @@ -1381,12 +1288,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 +1304,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}'`); @@ -1410,9 +1317,7 @@ class WebpackCLI { let config = { options: {}, path: new WeakMap() }; 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 || {})), - ); + const evaluatedConfigs = await Promise.all(options.config.map(async (value) => evaluateConfig(await loadConfig(path.resolve(value)), options.argv || {}))); config.options = []; @@ -1433,10 +1338,10 @@ 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], @@ -1491,21 +1396,19 @@ class WebpackCLI { }); if (notfoundConfigNames.length > 0) { - this.logger.error( - notfoundConfigNames.map((configName) => `Configuration with the name "${configName}" was not found.`).join(' '), - ); + this.logger.error(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,41 +1431,32 @@ 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') { + 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') { + 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); } const outputHints = (configOptions) => { - if ( - configOptions.watch && - options.argv && - options.argv.env && - (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' - }' command together with '{ watch: true }' configuration, it does not make sense.`, - ); + if (configOptions.watch && options.argv && options.argv.env && (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"}' 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; } } @@ -1570,14 +1464,12 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) - ? config.options.map((options) => outputHints(options)) - : outputHints(config.options); + config.options = Array.isArray(config.options) ? config.options.map((options) => outputHints(options)) : outputHints(config.options); 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 +1477,7 @@ class WebpackCLI { }, {}); const values = Object.keys(options).reduce((accumulator, name) => { - if (name === 'argv') { + if (name === "argv") { return accumulator; } @@ -1608,16 +1500,16 @@ 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) { @@ -1632,13 +1524,11 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) - ? config.options.map((options) => processArguments(options)) - : processArguments(config.options); + config.options = Array.isArray(config.options) ? config.options.map((options) => processArguments(options)) : processArguments(config.options); 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) { @@ -1663,9 +1553,7 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) - ? config.options.map((options) => setupDefaultOptions(options)) - : setupDefaultOptions(config.options); + config.options = Array.isArray(config.options) ? config.options.map((options) => setupDefaultOptions(options)) : setupDefaultOptions(config.options); } // Logic for webpack@4 @@ -1686,18 +1574,13 @@ class WebpackCLI { configOptions.target = options.target; } - if (typeof options.devtool !== 'undefined') { + if (typeof options.devtool !== "undefined") { configOptions.devtool = options.devtool; } if (options.mode) { configOptions.mode = options.mode; - } else if ( - !configOptions.mode && - process.env && - process.env.NODE_ENV && - (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'none') - ) { + } else if (!configOptions.mode && process.env && process.env.NODE_ENV && (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "production" || process.env.NODE_ENV === "none")) { configOptions.mode = process.env.NODE_ENV; } @@ -1705,15 +1588,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 }, @@ -1723,9 +1606,7 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) - ? config.options.map((options) => processLegacyArguments(options)) - : processLegacyArguments(config.options); + config.options = Array.isArray(config.options) ? config.options.map((options) => processLegacyArguments(options)) : processLegacyArguments(config.options); // Apply `stats` and `stats.colors` options const applyStatsColors = (configOptions) => { @@ -1733,17 +1614,17 @@ 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 +1632,11 @@ 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 +1644,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 @@ -1780,9 +1661,7 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) - ? config.options.map((options) => applyStatsColors(options)) - : applyStatsColors(config.options); + config.options = Array.isArray(config.options) ? config.options.map((options) => applyStatsColors(options)) : applyStatsColors(config.options); return config; } @@ -1793,7 +1672,7 @@ class WebpackCLI { configOptions.plugins = []; } - const CLIPlugin = require('./plugins/CLIPlugin'); + const CLIPlugin = require("./plugins/CLIPlugin"); configOptions.plugins.unshift( new CLIPlugin({ @@ -1808,9 +1687,7 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) - ? config.options.map((options) => addCLIPlugin(options)) - : addCLIPlugin(config.options); + config.options = Array.isArray(config.options) ? config.options.map((options) => addCLIPlugin(options)) : addCLIPlugin(config.options); return config; } @@ -1828,7 +1705,7 @@ class WebpackCLI { // https://github.com/webpack/webpack/blob/v4.44.2/lib/webpack.js#L90 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) { @@ -1890,11 +1767,7 @@ class WebpackCLI { return; } - const statsOptions = compiler.compilers - ? { children: compiler.compilers.map((compiler) => (compiler.options ? compiler.options.stats : undefined)) } - : compiler.options - ? compiler.options.stats - : undefined; + const statsOptions = compiler.compilers ? { children: compiler.compilers.map((compiler) => (compiler.options ? compiler.options.stats : undefined)) } : compiler.options ? compiler.options.stats : undefined; // TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats const statsForWebpack4 = this.webpack.Stats && this.webpack.Stats.presetToOptions; @@ -1904,7 +1777,7 @@ 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,21 +1785,17 @@ 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', () => - process.stderr.write( - `[webpack-cli] ${this.utils.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`, - ), - ); + .on("close", () => process.stderr.write(`[webpack-cli] ${this.utils.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`)); } } else { const printedStats = stats.toString(statsOptions); @@ -1938,10 +1807,7 @@ class WebpackCLI { } }; - const env = - isWatchCommand || options.watch - ? { WEBPACK_WATCH: true, ...options.env } - : { WEBPACK_BUNDLE: true, WEBPACK_BUILD: true, ...options.env }; + const env = isWatchCommand || options.watch ? { WEBPACK_WATCH: true, ...options.env } : { WEBPACK_BUNDLE: true, WEBPACK_BUILD: true, ...options.env }; options.argv = { ...options, env }; @@ -1955,11 +1821,10 @@ class WebpackCLI { return; } - const isWatch = (compiler) => - compiler.compilers ? compiler.compilers.some((compiler) => compiler.options.watch) : compiler.options.watch; + const isWatch = (compiler) => (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..b483f6430df 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,5 +1,3 @@ module.exports = { - singleQuote: true, - trailingComma: 'all', - printWidth: 140, + trailingComma: "all", }; diff --git a/scripts/cleanupTest.js b/scripts/cleanupTest.js index 0f1638df0cf..8723591c2f0 100644 --- a/scripts/cleanupTest.js +++ b/scripts/cleanupTest.js @@ -1,20 +1,9 @@ // 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', -]; +const outputDirectories = ["bin", "binary", "dist", "test", "test-assets", "test-plugin", "test-loader", "test-cache-path", "test-locate-cache", "stats.json"]; const folderStrategy = (stats, file) => { return stats.isDirectory() && outputDirectories.includes(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..b51a8790cdc 100644 --- a/scripts/snapshotResolver.js +++ b/scripts/snapshotResolver.js @@ -1,24 +1,24 @@ -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..67aecdf33c5 100644 --- a/scripts/updateDocs.js +++ b/scripts/updateDocs.js @@ -1,31 +1,31 @@ //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'], { + 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'], { + 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..20165154af7 100644 --- a/smoketests/helpers.js +++ b/smoketests/helpers.js @@ -1,11 +1,11 @@ /* 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 +14,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 +29,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 +64,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 +86,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 +106,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); @@ -133,17 +133,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 +159,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 +186,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 +204,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 +222,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..950504e28bf 100644 --- a/smoketests/missing-command-packages/configtest.test.js +++ b/smoketests/missing-command-packages/configtest.test.js @@ -1,23 +1,23 @@ -'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 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 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..4b8c3590d01 100644 --- a/smoketests/missing-command-packages/generator.test.js +++ b/smoketests/missing-command-packages/generator.test.js @@ -1,23 +1,23 @@ -'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 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 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..d305d5d61db 100644 --- a/smoketests/missing-packages/prettier.test.js +++ b/smoketests/missing-packages/prettier.test.js @@ -1,32 +1,32 @@ -'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 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..ba4f1572f05 100644 --- a/smoketests/missing-packages/webpack-dev-server.test.js +++ b/smoketests/missing-packages/webpack-dev-server.test.js @@ -1,22 +1,22 @@ -'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 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..c28953f0370 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,139 @@ 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 +287,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 +316,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 +341,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 +366,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 +391,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 +498,139 @@ 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 +640,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 +665,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 +690,22 @@ 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 +716,22 @@ 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 +742,103 @@ 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 +850,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 +873,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 +909,45 @@ 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 +958,46 @@ 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 +1008,46 @@ 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 +1058,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 +1082,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 +1106,21 @@ 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,21 +1130,21 @@ 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) => { @@ -1154,21 +1154,21 @@ describe('CLI API', () => { }, ); - 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 +1178,96 @@ 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,46 +1277,46 @@ 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, }, ], @@ -1327,46 +1327,46 @@ describe('CLI API', () => { }, ); - 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, }, ], @@ -1377,125 +1377,125 @@ 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 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) => { @@ -1505,57 +1505,57 @@ 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 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..d7c660a5d0b 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,87 +28,79 @@ 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); expect(prompt.mock.calls.length).toEqual(1); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( - "Would you like to install 'test-package' package? (That will run 'npm install -D test-package')", - ); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'npm install -D test-package')"); // 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); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( - "Would you like to install 'test-package' package? (That will run 'yarn add -D test-package')", - ); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'yarn add -D test-package')"); // 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); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( - "Would you like to install 'test-package' package? (That will run 'pnpm install -D test-package')", - ); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'pnpm install -D test-package')"); // 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); expect(prompt.mock.calls.length).toEqual(1); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( - "Would you like to install 'test-package' package? (That will run 'npm install -D test-package')", - ); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'npm install -D test-package')"); // 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..ee92ae1ad9b 100644 --- a/test/api/resolveConfig/resolveConfig.test.js +++ b/test/api/resolveConfig/resolveConfig.test.js @@ -1,56 +1,56 @@ -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 +58,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..74305636ba6 100755 --- a/test/api/scaffold-utils.test.js +++ b/test/api/scaffold-utils.test.js @@ -1,7 +1,7 @@ // 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 } = require("../../packages/generators/src/utils/scaffold-utils"); -describe('utils', () => { +describe("utils", () => { let mockSelf; beforeEach(() => { @@ -11,64 +11,64 @@ 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..3cdcac020ca 100644 --- a/test/build/analyze/analyze-flag.test.js +++ b/test/build/analyze/analyze-flag.test.js @@ -1,14 +1,14 @@ -'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)).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..8ea874869d9 100644 --- a/test/build/analyze/analyze.config.js +++ b/test/build/analyze/analyze.config.js @@ -1,7 +1,7 @@ // 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..32315b2ea1d 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,7 @@ 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..ce3fbb85922 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,48 @@ 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 +61,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 +69,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 +77,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 +85,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 +93,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 +101,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 +109,7 @@ 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 +117,7 @@ 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 +125,7 @@ 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 +133,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 +142,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..902e99e84e1 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,23 @@ 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 +47,9 @@ 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..0d4f7a1eee2 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,24 @@ 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 +50,9 @@ 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..a7c11890646 100644 --- a/test/build/cache/cache.test.js +++ b/test/build/cache/cache.test.js @@ -1,15 +1,15 @@ -'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 +20,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 +33,11 @@ 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')); + 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']); + let { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js"]); expect(exitCode).toEqual(0); @@ -48,7 +48,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,17 +61,10 @@ 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', - ]); + let { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js", "--config-name", "cache-test-first", "--name", "cache-test-third"]); expect(exitCode).toEqual(0); @@ -82,14 +75,7 @@ describe('cache', () => { expect(stdout).toBeTruthy(); } - ({ exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '--config-name', - 'cache-test-first', - '--name', - 'cache-test-third', - ])); + ({ exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js", "--config-name", "cache-test-first", "--name", "cache-test-third"])); expect(exitCode).toEqual(0); @@ -102,18 +88,10 @@ 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', - ]); + let { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js", "-c", "./webpack.config.js", "--merge", "--name", "cache-test-fourth"]); expect(exitCode).toEqual(0); @@ -124,15 +102,7 @@ describe('cache', () => { expect(stdout).toBeTruthy(); } - ({ exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './multi.config.js', - '-c', - './webpack.config.js', - '--merge', - '--name', - 'cache-test-fourth', - ])); + ({ exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js", "-c", "./webpack.config.js", "--merge", "--name", "cache-test-fourth"])); expect(exitCode).toEqual(0); @@ -145,21 +115,21 @@ 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 +142,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 +166,10 @@ 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 +180,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..2a390d80d36 100644 --- a/test/build/colors/colors.test.js +++ b/test/build/colors/colors.test.js @@ -1,143 +1,139 @@ -'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 () => { +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')}`], - { env: { FORCE_COLOR: true } }, - ); + const { exitCode, stderr, stdout } = await run(__dirname, ["--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'], { + 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'], { + 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'], { + 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'], { + 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..391a1b8d0f5 100644 --- a/test/build/config-format/failure/failure.test.js +++ b/test/build/config-format/failure/failure.test.js @@ -1,17 +1,17 @@ -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..a0bb7e2c4d8 100644 --- a/test/build/config-lookup/custom-name/custom-name.test.js +++ b/test/build/config-lookup/custom-name/custom-name.test.js @@ -1,19 +1,19 @@ -'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')], { + 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 }, }); 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..557cf53e882 100644 --- a/test/build/config-lookup/relative/basic-config.test.js +++ b/test/build/config-lookup/relative/basic-config.test.js @@ -1,18 +1,18 @@ -'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..521f46ddc51 100644 --- a/test/build/config-name/config-name.test.js +++ b/test/build/config-name/config-name.test.js @@ -1,65 +1,57 @@ -'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 () => { - const { exitCode, stderr, stdout } = await run( - __dirname, - ['-c', './function-config.js', '-c', './single-other-config.js', '--config-name', 'first', '--config-name', 'four'], - false, - ); + 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"], 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 () => { - const { exitCode, stderr, stdout } = await run( - __dirname, - ['--config-name', 'test', '--config-name', 'bar', '-c', 'single-config.js'], - false, - ); + 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"], false); expect(exitCode).toBe(2); expect(stderr).toContain('Configuration with the name "test" was not found.'); @@ -67,44 +59,36 @@ describe('--config-name flag', () => { expect(stdout).toBeFalsy(); }); - 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'], - false, - ); + 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"], false); expect(exitCode).toBe(2); expect(stderr).toContain('Configuration with the name "bar" was not found.'); 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 () => { - const { exitCode, stderr, stdout } = await run( - __dirname, - ['--config', 'function-config.js', '--config-name', 'first', '--config-name', 'third'], - false, - ); + 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"], 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..7ba9ffb514e 100644 --- a/test/build/config/absent/config-absent.test.js +++ b/test/build/config/absent/config-absent.test.js @@ -1,16 +1,16 @@ -'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..5f89f96d1eb 100644 --- a/test/build/config/basic/basic-config.test.js +++ b/test/build/config/basic/basic-config.test.js @@ -1,16 +1,11 @@ -'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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - resolve(__dirname, 'webpack.config.js'), - '--output-path', - './binary', - ]); +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"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); 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..0812b3679b6 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,9 +1,9 @@ -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 () => { +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)) { @@ -13,19 +13,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..d983078c910 100644 --- a/test/build/config/empty-array/empty-array.test.js +++ b/test/build/config/empty-array/empty-array.test.js @@ -1,10 +1,10 @@ -'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..d983078c910 100644 --- a/test/build/config/empty-function/empty-function.test.js +++ b/test/build/config/empty-function/empty-function.test.js @@ -1,10 +1,10 @@ -'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..d983078c910 100644 --- a/test/build/config/empty-promise/empty-promise.test.js +++ b/test/build/config/empty-promise/empty-promise.test.js @@ -1,10 +1,10 @@ -'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..d983078c910 100644 --- a/test/build/config/empty/empty.test.js +++ b/test/build/config/empty/empty.test.js @@ -1,10 +1,10 @@ -'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..6d8bf8d8a6a 100644 --- a/test/build/config/error-commonjs/config-error.test.js +++ b/test/build/config/error-commonjs/config-error.test.js @@ -1,22 +1,22 @@ -'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..f51e0de9d94 100644 --- a/test/build/config/error-mjs/config-error.test.js +++ b/test/build/config/error-mjs/config-error.test.js @@ -1,32 +1,32 @@ -'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.mjs')], { +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')], { + 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..78ff5a88e57 100644 --- a/test/build/config/function/functional-config.test.js +++ b/test/build/config/function/functional-config.test.js @@ -1,27 +1,27 @@ -'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..5f924c1e6b7 100644 --- a/test/build/config/invalid-export/invalid-export.test.js +++ b/test/build/config/invalid-export/invalid-export.test.js @@ -1,13 +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('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..c4a02154e1b 100644 --- a/test/build/config/invalid-path/invalid-path.test.js +++ b/test/build/config/invalid-path/invalid-path.test.js @@ -1,13 +1,13 @@ -'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..5f89f96d1eb 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,16 +1,11 @@ -'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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - resolve(__dirname, 'webpack.config.js'), - '--output-path', - './binary', - ]); +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"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); 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..a36b4722e83 100644 --- a/test/build/config/multiple/multiple-config.test.js +++ b/test/build/config/multiple/multiple-config.test.js @@ -1,16 +1,16 @@ -'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..284c7afcda9 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,11 @@ -'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..574af2b5eb1 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,11 @@ -'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..cbafb50dfd3 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,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', () => { - 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..f2cfb91bb12 100644 --- a/test/build/config/type/array/array.test.js +++ b/test/build/config/type/array/array.test.js @@ -1,27 +1,27 @@ -'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..8c533ad768c 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,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('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..f9fd1ddf7ad 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,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('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..b188d5d8937 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,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('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..8d75bf193f3 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,145 @@ -'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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'environment=production', - '--env', - 'app.title=Luffy', - '-c', - 'webpack.env.config.js', - ]); + 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"]); 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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'file.name.is.this=Atsumu', - '--env', - 'environment=production', - '-c', - 'webpack.env.config.js', - ]); + 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"]); 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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'file=name=is=Eren', - '--env', - 'environment=multipleq', - '-c', - 'webpack.env.config.js', - ]); + 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"]); 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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'name.=Hisoka', - '--env', - 'environment=dot', - '-c', - 'webpack.env.config.js', - ]); + 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"]); 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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'name.', - '--env', - 'environment=dot', - '-c', - 'webpack.env.config.js', - ]); + it("Supports dot at the end", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["--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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '--env', - 'name.=foo', - '--env', - 'name.=baz', - '--env', - 'environment=dot', - '-c', - 'webpack.env.config.js', - ]); + 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"]); 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..f68d8e12cd3 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,45 @@ -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..a6c89fbbb30 100644 --- a/test/build/config/type/function/function.test.js +++ b/test/build/config/type/function/function.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('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..25ead7ae9df 100644 --- a/test/build/core-flags/cache-flags.test.js +++ b/test/build/core-flags/cache-flags.test.js @@ -1,88 +1,74 @@ -'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', - cacheLocation, - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--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', - cacheLocation, - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--cache-type", "filesystem", "--cache-hash-algorithm", "sha256", "--cache-cache-location", cacheLocation]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -90,19 +76,12 @@ 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', - cacheLocation, - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--cache-type", "filesystem", "--cache-name", "cli-test", "--cache-cache-location", cacheLocation]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -110,19 +89,12 @@ 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', - cacheLocation, - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--cache-type", "filesystem", "--cache-store", "pack", "--cache-cache-location", cacheLocation]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -130,19 +102,12 @@ 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', - cacheLocation, - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--cache-type", "filesystem", "--cache-version", "1.1.3", "--cache-cache-location", cacheLocation]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -150,148 +115,118 @@ 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', - cacheLocation, - ]); + let { stderr, stdout, exitCode } = await run(__dirname, ["--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', - cacheLocation, - ])); + ({ exitCode, stderr, stdout } = await run(__dirname, ["--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 () => { - const cacheLocation = path.resolve( - __dirname, - '../../../node_modules/.cache/webpack/cache-core-flag-test-build-dependencies-in-config', - ); + 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"); rimraf.sync(cacheLocation); - let { exitCode, stderr, stdout } = await run(__dirname, [ - '-c', - './webpack.cache.config.js', - '--cache-cache-location', - cacheLocation, - ]); + let { 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("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', - cacheLocation, - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["-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..97953dcb3e9 100644 --- a/test/build/core-flags/context-flag.test.js +++ b/test/build/core-flags/context-flag.test.js @@ -1,25 +1,25 @@ -'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..55321a78abf 100644 --- a/test/build/core-flags/entry-reset-flag.test.js +++ b/test/build/core-flags/entry-reset-flag.test.js @@ -1,22 +1,22 @@ -'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..52ba8c7dbbf 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,28 @@ -'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..44f1babcc22 100644 --- a/test/build/core-flags/infrastructure-logging.test.js +++ b/test/build/core-flags/infrastructure-logging.test.js @@ -1,26 +1,26 @@ -'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..db983ab3bb0 100644 --- a/test/build/core-flags/invalid-flag.test.js +++ b/test/build/core-flags/invalid-flag.test.js @@ -1,10 +1,10 @@ -'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..0174453aec5 100644 --- a/test/build/core-flags/module-flags.test.js +++ b/test/build/core-flags/module-flags.test.js @@ -1,42 +1,35 @@ -'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-') - ) { + if (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-')) { - const { exitCode, stderr, stdout } = await run(__dirname, [ - `--module-generator-asset-emit`, - '--module-generator-asset-resource-emit', - ]); + } else if (name.startsWith("module-generator-")) { + const { exitCode, stderr, stdout } = await run(__dirname, [`--module-generator-asset-emit`, "--module-generator-asset-resource-emit"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -50,17 +43,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`); } @@ -68,40 +61,37 @@ describe('module config related flag', () => { } } - if ( - value.configs.filter((config) => config.type === 'string').length > 0 && - !(name.includes('module-parser-') || name.startsWith('module-generator')) - ) { + if (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,48 +101,43 @@ describe('module config related flag', () => { } } - 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', - ]); + 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"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); 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`); 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..b2d5b34a0c4 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`); } @@ -64,44 +64,40 @@ 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-') - ) { + if (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 +106,14 @@ 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..183f6faa30f 100644 --- a/test/build/core-flags/output-flags.test.js +++ b/test/build/core-flags/output-flags.test.js @@ -1,40 +1,40 @@ -'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 +46,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 +57,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 +67,88 @@ 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 +160,31 @@ 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..34a2562843f 100644 --- a/test/build/core-flags/records-flag.test.js +++ b/test/build/core-flags/records-flag.test.js @@ -1,29 +1,29 @@ -'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..f2f60216710 100644 --- a/test/build/core-flags/resolve-flags.test.js +++ b/test/build/core-flags/resolve-flags.test.js @@ -1,32 +1,28 @@ -'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-') - ) { + if (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}`]); // 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`); @@ -34,48 +30,44 @@ describe('resolve config related flags', () => { }); } - if ( - value.configs.filter((config) => config.type === 'string').length > 0 && - !name.includes('alias-') && - !name.includes('fallback-') - ) { + if (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 +76,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..b1e0fb8f9c9 100644 --- a/test/build/core-flags/snapshot-flags.test.js +++ b/test/build/core-flags/snapshot-flags.test.js @@ -1,39 +1,39 @@ -'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..35ae6503163 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,37 @@ 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..e486f778e95 100644 --- a/test/build/core-flags/watch-flags.test.js +++ b/test/build/core-flags/watch-flags.test.js @@ -1,33 +1,33 @@ -'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 +38,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 +48,16 @@ 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..3a1aad180d8 100644 --- a/test/build/custom-webpack/custom-webpack.test.js +++ b/test/build/custom-webpack/custom-webpack.test.js @@ -1,22 +1,22 @@ -'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..9821f2ccdd8 100644 --- a/test/build/defaults/output-defaults.test.js +++ b/test/build/defaults/output-defaults.test.js @@ -1,32 +1,32 @@ -'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..8e92535083b 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,8 @@ 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 +34,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..5319e16d142 100644 --- a/test/build/devtool/object/source-map-object.test.js +++ b/test/build/devtool/object/source-map-object.test.js @@ -1,11 +1,11 @@ -'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 +14,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 +22,30 @@ 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 () => { - const { exitCode, stderr, stdout } = await run( - __dirname, - ['-c', './webpack.eval.config.js', '--devtool', 'source-map', '-o', './binary'], - false, - ); + 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"], 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 () => { - const { exitCode, stderr, stdout } = await run( - __dirname, - ['-c', './webpack.eval.config.js', '--no-devtool', '-o', './binary'], - false, - ); + it("should override config with devtool false", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["-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..f1aec3de0a8 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,46 @@ -'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..5da315193ec 100644 --- a/test/build/entry/multiple-entries/multi-entries.test.js +++ b/test/build/entry/multiple-entries/multi-entries.test.js @@ -1,27 +1,27 @@ -'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..b400dd1b88e 100644 --- a/test/build/error/invalid-schema/invalid-schema.test.js +++ b/test/build/error/invalid-schema/invalid-schema.test.js @@ -1,41 +1,41 @@ -'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 +43,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 +58,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 +73,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 +88,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 +103,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 +118,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 +133,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 +148,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..d462642fac3 100644 --- a/test/build/hot/hot-flag.test.js +++ b/test/build/hot/hot-flag.test.js @@ -1,41 +1,41 @@ -'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..818c4c84388 100644 --- a/test/build/json/json.test.js +++ b/test/build/json/json.test.js @@ -1,160 +1,160 @@ -'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..25560251bff 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,18 @@ -'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..8b155f57a1f 100644 --- a/test/build/merge/config/merge-config.test.js +++ b/test/build/merge/config/merge-config.test.js @@ -1,45 +1,41 @@ -'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 () => { - const { exitCode, stderr, stdout } = await run( - __dirname, - ['--config', './1.js', '--config', './2.js', '--config', './3.js', '--merge'], - false, - ); + 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"], 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..e3a13a63b18 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,9 +1,9 @@ -'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); @@ -12,40 +12,40 @@ describe('mode flags', () => { 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 +53,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..ba85331552b 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,10 @@ -'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 +12,8 @@ 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 +21,8 @@ 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,8 +31,8 @@ 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); @@ -40,43 +40,36 @@ describe('mode flags with config', () => { 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 () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - '--mode', - 'none', - '-c', - './webpack.config3.js', - '-c', - './webpack.config2.js', - ]); + 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"]); 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'], { + 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', + NODE_ENV: "production", }, }); @@ -84,7 +77,7 @@ describe('mode flags with config', () => { 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..a4ee1cd6ca9 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,7 @@ 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 +36,7 @@ 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 +44,7 @@ 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..5bcd046794e 100644 --- a/test/build/node/node.test.js +++ b/test/build/node/node.test.js @@ -1,40 +1,40 @@ -'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..6d20e9e875b 100644 --- a/test/build/output/output-named-bundles.test.js +++ b/test/build/output/output-named-bundles.test.js @@ -1,58 +1,46 @@ -'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 () => { - const { exitCode, stderr, stdout } = await run( - __dirname, - ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], - false, - ); +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"], false); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - 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'], - false, - ); + 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"], false); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); }); - 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'], - false, - ); + 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"], false); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); 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..f74daa1ea0a 100644 --- a/test/build/prefetch/prefetch.test.js +++ b/test/build/prefetch/prefetch.test.js @@ -1,29 +1,29 @@ -'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 +31,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..e2b0b93435e 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,25 @@ 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(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..9afff54980b 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,43 +1,43 @@ -'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'], { + 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); @@ -45,7 +45,7 @@ describe('start finish force log', () => { 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..77489457554 100644 --- a/test/build/stats/flags/stats.test.js +++ b/test/build/stats/flags/stats.test.js @@ -1,17 +1,17 @@ -'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 +20,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 +53,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 +62,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 +75,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..6c69f0cd0d5 100644 --- a/test/build/target/flag-test/target-flag.test.js +++ b/test/build/target/flag-test/target-flag.test.js @@ -1,12 +1,12 @@ -'use strict'; -const { run, isWebpack5, normalizeStdout, normalizeStderr } = require('../../../utils/test-utils'); +"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']; +const targetValues = ["web", "webworker", "node", "async-node", "node-webkit", "electron-main", "electron-renderer", "electron-preload"]; -describe('--target flag', () => { +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 +19,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 +33,52 @@ 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..f979f628032 100644 --- a/test/build/unknown/unknown.test.js +++ b/test/build/unknown/unknown.test.js @@ -1,189 +1,189 @@ -'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..f82ba61c1c3 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,45 @@ -'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..62d8ff6d168 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -1,397 +1,393 @@ -'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: exitCodeFromCommandSyntax, - stderr: stderrFromCommandSyntax, - stdout: stdoutFromCommandSyntax, - } = 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"]); 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..3d706af7a2c 100644 --- a/test/init/init.test.js +++ b/test/init/init.test.js @@ -1,44 +1,44 @@ -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 +48,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 +66,16 @@ 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("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 +85,16 @@ 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("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 +107,16 @@ 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 +126,16 @@ 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'], - [`${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +148,16 @@ 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'], - [`${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +170,15 @@ 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}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +191,15 @@ 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}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +212,15 @@ 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}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +233,15 @@ 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}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +254,15 @@ 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}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +275,15 @@ 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}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +296,16 @@ 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 +317,15 @@ 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'], - [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${ENTER}`, ENTER, `n${ENTER}`], - ); + const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["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 +338,16 @@ 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 +360,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 +396,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 +414,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 +432,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 +450,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 +468,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..b1ae0a02843 100644 --- a/test/loader/loader.test.js +++ b/test/loader/loader.test.js @@ -1,38 +1,38 @@ -'use strict'; +"use strict"; -const { existsSync } = require('fs'); -const { join, resolve } = require('path'); -const { run, runPromptWithAnswers, uniqueDirectoryForTest, normalizeStdout } = require('../utils/test-utils'); +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 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 +40,29 @@ 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 +70,29 @@ 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 +100,30 @@ 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 +131,36 @@ 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 +168,17 @@ 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..f4e4e5c1125 100644 --- a/test/plugin/plugin.test.js +++ b/test/plugin/plugin.test.js @@ -1,30 +1,30 @@ -const { existsSync, mkdirSync } = require('fs'); -const { join, resolve } = require('path'); -const { run, runPromptWithAnswers, uniqueDirectoryForTest, normalizeStdout } = require('../utils/test-utils'); +const { existsSync, mkdirSync } = require("fs"); +const { join, resolve } = require("path"); +const { run, runPromptWithAnswers, uniqueDirectoryForTest, normalizeStdout } = require("../utils/test-utils"); -const ENTER = '\x0D'; +const ENTER = "\x0D"; -const firstPrompt = '? Plugin name'; +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 +32,26 @@ 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 +59,26 @@ 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 +86,23 @@ 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 +110,7 @@ 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 +118,47 @@ 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..6defecccd50 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -1,397 +1,380 @@ -'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', - port, - ]); - - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--config", "function-with-env.config.js", "--env", "foo=bar", "--port", port]); + + 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', - port, - ]); - - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + const { stderr, stdout } = await runWatch(__dirname, ["serve", "--config", "function-with-argv.config.js", "--env", "foo=bar", "--hot", "--port", port]); + + 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)); @@ -399,125 +382,119 @@ describe('basic serve usage', () => { 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', - port, - ]); + const { stderr, stdout } = await runWatch(__dirname, ["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], { + 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'], { + 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(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..073a4831b00 100644 --- a/test/serve/invalid-schema/invalid-schema.test.js +++ b/test/serve/invalid-schema/invalid-schema.test.js @@ -1,37 +1,37 @@ -'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..066fee5e757 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); } }; @@ -233,22 +233,19 @@ 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', - ); + 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"); }; 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 +262,7 @@ const normalizeStdout = (stdout) => { }; const normalizeStderr = (stderr) => { - if (typeof stderr !== 'string') { + if (typeof stderr !== "string") { return stderr; } @@ -279,32 +276,28 @@ 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)); if (ipv4MessageIndex !== -1) { - normalizedStderr.splice( - ipv4MessageIndex + 1, - 0, - ' [webpack-dev-server] On Your Network (IPv6): http://[]:/', - ); + normalizedStderr.splice(ipv4MessageIndex + 1, 0, " [webpack-dev-server] On Your Network (IPv6): http://[]:/"); } - normalizedStderr = normalizedStderr.join('\n'); + normalizedStderr = normalizedStderr.join("\n"); } normalizedStderr = normalizeVersions(normalizedStderr); @@ -314,7 +307,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..fa698db8354 100644 --- a/test/utils/test-utils.test.js +++ b/test/utils/test-utils.test.js @@ -1,81 +1,81 @@ -'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..5464ff44d11 100644 --- a/test/version/version.test.js +++ b/test/version/version.test.js @@ -1,333 +1,333 @@ -'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..8ea874869d9 100644 --- a/test/watch/analyze/analyze.config.js +++ b/test/watch/analyze/analyze.config.js @@ -1,7 +1,7 @@ // 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..fac087b43a6 100644 --- a/test/watch/bail/bail.test.js +++ b/test/watch/bail/bail.test.js @@ -1,45 +1,45 @@ -'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(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(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(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..732db6a93aa 100644 --- a/test/watch/basic/basic.test.js +++ b/test/watch/basic/basic.test.js @@ -1,30 +1,30 @@ -'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 +37,7 @@ 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 +49,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 +70,7 @@ 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 +82,17 @@ 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 +105,7 @@ 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 +117,15 @@ 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 +138,7 @@ 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,30 +149,28 @@ describe('basic', () => { } }); - proc.stderr.on('data', (chunk) => { + proc.stderr.on("data", (chunk) => { const data = chunk.toString(); - expect(data).toContain( - "No need to use the 'watch' command together with '{ watch: true }' configuration, it does not make sense.", - ); + expect(data).toContain("No need to use the 'watch' command together with '{ watch: true }' configuration, it does not make sense."); }); }); - 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 +178,8 @@ 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 +187,8 @@ 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..80af49b6de3 100644 --- a/test/watch/stats/multi-webpack.config.js +++ b/test/watch/stats/multi-webpack.config.js @@ -1,15 +1,15 @@ -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', () => { + (compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap("webpack-cli-test", () => { console.log(`webpack ${webpack.version}`); }); }, @@ -17,14 +17,14 @@ module.exports = [ ], }, { - 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', () => { + (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..d53f25dd300 100644 --- a/test/watch/stats/stats-and-watch.test.js +++ b/test/watch/stats/stats-and-watch.test.js @@ -1,24 +1,24 @@ -'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..d47bf6c655e 100644 --- a/test/watch/stats/webpack.config.js +++ b/test/watch/stats/webpack.config.js @@ -1,13 +1,13 @@ -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', () => { + (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..9bb90ecc9a1 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,7 @@ 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 +43,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 +66,7 @@ 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)], }; From 0b5ad31aba31256623575e4a02ecff65637d9adf Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 15 May 2021 18:54:49 +0530 Subject: [PATCH 2/3] fix: eslint --- .eslintrc.js | 14 +- jest.config.js | 10 +- packages/configtest/src/index.ts | 4 +- packages/generators/README.md | 7 +- packages/generators/src/addon-generator.ts | 35 +- packages/generators/src/handlers/default.ts | 105 +++- packages/generators/src/index.ts | 4 +- packages/generators/src/init-generator.ts | 47 +- packages/generators/src/plugin-generator.ts | 4 +- .../generators/src/utils/scaffold-utils.ts | 41 +- packages/info/src/index.ts | 16 +- packages/serve/src/index.ts | 24 +- packages/serve/src/startDevServer.ts | 41 +- packages/webpack-cli/bin/cli.js | 6 +- packages/webpack-cli/lib/plugins/CLIPlugin.js | 32 +- .../lib/utils/prompt-installation.js | 12 +- packages/webpack-cli/lib/webpack-cli.js | 546 ++++++++++++++---- prettier.config.js | 1 + scripts/cleanupTest.js | 13 +- scripts/snapshotResolver.js | 15 +- scripts/updateDocs.js | 24 +- smoketests/helpers.js | 12 +- .../configtest.test.js | 6 +- .../generator.test.js | 6 +- smoketests/missing-packages/prettier.test.js | 10 +- .../webpack-dev-server.test.js | 3 +- test/api/CLI.test.js | 164 ++++-- test/api/prompt-installation.test.js | 16 +- test/api/resolveConfig/resolveConfig.test.js | 23 +- test/api/scaffold-utils.test.js | 36 +- test/build/analyze/analyze-flag.test.js | 10 +- test/build/analyze/analyze.config.js | 7 +- test/build/bail/bail.test.js | 5 +- test/build/basic/basic.test.js | 55 +- test/build/build-errors/errors.test.js | 8 +- test/build/build-warnings/warnings.test.js | 8 +- test/build/cache/cache.test.js | 92 ++- test/build/colors/colors.test.js | 82 ++- .../config-format/failure/failure.test.js | 4 +- .../custom-name/custom-name.test.js | 15 +- .../relative/basic-config.test.js | 14 +- test/build/config-name/config-name.test.js | 61 +- .../build/config/absent/config-absent.test.js | 9 +- test/build/config/basic/basic-config.test.js | 7 +- .../mjs-config/default-mjs-config.test.js | 4 +- .../config/empty-array/empty-array.test.js | 5 +- .../empty-function/empty-function.test.js | 5 +- .../empty-promise/empty-promise.test.js | 5 +- test/build/config/empty/empty.test.js | 5 +- .../error-commonjs/config-error.test.js | 10 +- .../config/error-mjs/config-error.test.js | 20 +- .../config/function/functional-config.test.js | 10 +- .../invalid-export/invalid-export.test.js | 9 +- .../config/invalid-path/invalid-path.test.js | 9 +- .../multiple-with-one-compilation.test.js | 7 +- .../config/multiple/multiple-config.test.js | 7 +- .../no-config-array/no-config-array.test.js | 5 +- .../no-config-object/no-config-object.test.js | 7 +- .../array-functions/array-functions.test.js | 5 +- test/build/config/type/array/array.test.js | 5 +- .../function-array/function-array.test.js | 5 +- .../function-async/function-async.test.js | 5 +- .../function-promise/function-promise.test.js | 5 +- .../function-with-env.test.js | 65 ++- .../type/function-with-env/webpack.config.js | 6 +- .../config/type/function/function.test.js | 5 +- test/build/core-flags/cache-flags.test.js | 217 +++++-- test/build/core-flags/context-flag.test.js | 5 +- .../build/core-flags/entry-reset-flag.test.js | 6 +- .../ignore-warnings-flag.test.js | 11 +- .../core-flags/infrastructure-logging.test.js | 14 +- test/build/core-flags/invalid-flag.test.js | 5 +- test/build/core-flags/module-flags.test.js | 65 ++- .../core-flags/optimization-flags.test.js | 41 +- test/build/core-flags/output-flags.test.js | 86 ++- test/build/core-flags/records-flag.test.js | 15 +- test/build/core-flags/resolve-flags.test.js | 12 +- test/build/core-flags/snapshot-flags.test.js | 5 +- test/build/core-flags/stats-flags.test.js | 18 +- test/build/core-flags/watch-flags.test.js | 10 +- .../custom-webpack/custom-webpack.test.js | 4 +- test/build/defaults/output-defaults.test.js | 13 +- .../devtool/array/source-map-array.test.js | 7 +- .../devtool/object/source-map-object.test.js | 22 +- .../entry/flag-entry/entry-with-flag.test.js | 7 +- .../multiple-entries/multi-entries.test.js | 7 +- .../invalid-schema/invalid-schema.test.js | 22 +- test/build/hot/hot-flag.test.js | 12 +- test/build/json/json.test.js | 31 +- .../config-absent/merge-config-absent.test.js | 8 +- test/build/merge/config/merge-config.test.js | 28 +- .../mode-single-arg/mode-single-arg.test.js | 8 +- .../mode-with-config/mode-with-config.test.js | 60 +- test/build/node-env/node-env.test.js | 21 +- test/build/node/node.test.js | 21 +- .../build/output/output-named-bundles.test.js | 23 +- test/build/prefetch/prefetch.test.js | 12 +- test/build/progress/progress-flag.test.js | 10 +- .../start-finish-force-log.test.js | 10 +- test/build/stats/flags/stats.test.js | 10 +- .../target/flag-test/target-flag.test.js | 38 +- test/build/unknown/unknown.test.js | 25 +- .../with-config-path/with-config-path.test.js | 15 +- test/help/help.test.js | 63 +- test/init/init.test.js | 165 +++++- test/loader/loader.test.js | 76 ++- test/plugin/plugin.test.js | 101 +++- test/serve/basic/serve-basic.test.js | 162 +++++- .../invalid-schema/invalid-schema.test.js | 12 +- test/utils/test-utils.js | 33 +- test/utils/test-utils.test.js | 19 +- test/version/version.test.js | 15 +- test/watch/analyze/analyze.config.js | 7 +- test/watch/bail/bail.test.js | 35 +- test/watch/basic/basic.test.js | 59 +- test/watch/stats/multi-webpack.config.js | 18 +- test/watch/stats/stats-and-watch.test.js | 7 +- test/watch/stats/webpack.config.js | 9 +- .../watch-variable/watch-variable.test.js | 10 +- 119 files changed, 2921 insertions(+), 657 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 474502795fd..4b037f778f9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,12 @@ module.exports = { root: true, reportUnusedDisableDirectives: true, - extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended", "prettier"], + extends: [ + "eslint:recommended", + "plugin:node/recommended", + "plugin:prettier/recommended", + "prettier", + ], parserOptions: { ecmaVersion: 2018, sourceType: "script" }, plugins: ["node"], settings: { @@ -30,11 +35,16 @@ module.exports = { }, }, files: ["**/*.ts"], - extends: ["plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"], + 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", + "max-len": [0, 100], }, }, ], diff --git a/jest.config.js b/jest.config.js index 3574c711f1b..af8a0297593 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,10 @@ const { cli } = require("webpack"); // Ignore core-flags test for webpack@4 -const ignorePattern = typeof cli !== "undefined" ? ["/node_modules/"] : ["/node_modules/", "/test/build/core-flags"]; +const ignorePattern = + typeof cli !== "undefined" + ? ["/node_modules/"] + : ["/node_modules/", "/test/build/core-flags"]; module.exports = { testPathIgnorePatterns: ignorePattern, @@ -20,5 +23,8 @@ module.exports = { setupFilesAfterEnv: ["/setupTest.js"], globalTeardown: "/scripts/cleanupTest.js", globalSetup: "/scripts/globalSetup.js", - modulePathIgnorePatterns: ["/test/loader/test-loader", "/test/plugin/test-plugin"], + modulePathIgnorePatterns: [ + "/test/loader/test-loader", + "/test/plugin/test-plugin", + ], }; diff --git a/packages/configtest/src/index.ts b/packages/configtest/src/index.ts index cb1e3b16ddf..025ef647d29 100644 --- a/packages/configtest/src/index.ts +++ b/packages/configtest/src/index.ts @@ -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 6dd959946b2..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/src/addon-generator.ts b/packages/generators/src/addon-generator.ts index 586fd129656..270cdffcbc4 100644 --- a/packages/generators/src/addon-generator.ts +++ b/packages/generators/src/addon-generator.ts @@ -57,9 +57,18 @@ 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`); - - const { selectedTemplate } = await List(this, "selectedTemplate", "Select a valid template from below:", this.supportedTemplates, "default", false); + 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:", + this.supportedTemplates, + "default", + false, + ); this.template = selectedTemplate; } @@ -90,8 +99,11 @@ 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)); + this.fs.extendJSON( + this.destinationPath("package.json"), + // eslint-disable-next-line @typescript-eslint/no-var-requires + require(packageJsonTemplatePath)(this.props.name), + ); let files = []; try { @@ -103,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)); }); } diff --git a/packages/generators/src/handlers/default.ts b/packages/generators/src/handlers/default.ts index 3b67e66d4a4..d34cbf8ba4e 100644 --- a/packages/generators/src/handlers/default.ts +++ b/packages/generators/src/handlers/default.ts @@ -12,14 +12,29 @@ 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", self.force); + const { langType } = await Question.List( + self, + "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"]; + self.dependencies = [ + ...self.dependencies, + "babel-loader", + "@babel/core", + "@babel/preset-env", + ]; break; case "Typescript": self.dependencies = [...self.dependencies, "typescript", "ts-loader"]; @@ -27,13 +42,25 @@ export async function questions(self: CustomGenerator, Question: Record { options.generationPath = generationPath || "."; - const env = yeoman.createEnv([], { cwd: options.generationPath }); + const env = yeoman.createEnv([], { + cwd: options.generationPath, + }); const generatorName = "webpack-init-generator"; env.registerStub(initGenerator, generatorName); diff --git a/packages/generators/src/init-generator.ts b/packages/generators/src/init-generator.ts index 55920dbcd28..1006e2aeb5a 100644 --- a/packages/generators/src/init-generator.ts +++ b/packages/generators/src/init-generator.ts @@ -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,9 +62,18 @@ 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`); - - const { selectedTemplate } = await Question.List(this, "selectedTemplate", "Select a valid template from below:", this.supportedTemplates, "default", false); + 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:", + this.supportedTemplates, + "default", + false, + ); this.template = selectedTemplate; } @@ -72,7 +85,13 @@ export default class InitGenerator extends CustomGenerator { // eslint-disable-next-line node/no-extraneous-require require.resolve("prettier"); } catch (err) { - const { installPrettier } = await Question.Confirm(this, "installPrettier", "Do you like to install prettier to format generated configuration?", true, false); + const { installPrettier } = await Question.Confirm( + this, + "installPrettier", + "Do you like to install prettier to format generated configuration?", + true, + false, + ); if (installPrettier) { this.dependencies.push("prettier"); @@ -87,7 +106,9 @@ export default class InitGenerator extends CustomGenerator { "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 { @@ -100,11 +121,19 @@ export default class InitGenerator extends CustomGenerator { 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 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/plugin-generator.ts b/packages/generators/src/plugin-generator.ts index 1c8243b681f..3cb8e28f7c2 100644 --- a/packages/generators/src/plugin-generator.ts +++ b/packages/generators/src/plugin-generator.ts @@ -22,7 +22,9 @@ export const PluginGenerator = addonGenerator( }, ], path.resolve(__dirname, "../plugin-template"), - (gen): Record => ({ name: toUpperCamelCase(gen.props.name) }), + (gen): Record => ({ + name: toUpperCamelCase(gen.props.name), + }), ); export default PluginGenerator; diff --git a/packages/generators/src/utils/scaffold-utils.ts b/packages/generators/src/utils/scaffold-utils.ts index fd556a3fa5e..08babde5720 100644 --- a/packages/generators/src/utils/scaffold-utils.ts +++ b/packages/generators/src/utils/scaffold-utils.ts @@ -5,7 +5,14 @@ type CustomGeneratorBoolPrompt = { [x: string]: boolean } | Promise<{ [x: string /* eslint-disable @typescript-eslint/no-explicit-any */ -export function List(self: Generator, name: string, message: string, choices: string[], defaultChoice?: string, skip = false): CustomGeneratorStringPrompt { +export function List( + self: Generator, + name: string, + message: string, + choices: string[], + defaultChoice?: string, + skip = false, +): CustomGeneratorStringPrompt { if (skip) { return { [name]: defaultChoice }; } @@ -13,7 +20,13 @@ export function List(self: Generator, name: string, message: string, choices: st 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 }; } @@ -21,12 +34,24 @@ export function Input(self: Generator, name: string, message: string, defaultCho return self.prompt([{ default: defaultChoice, message, name, type: "input" }]); } -export function InputValidate(self: Generator, name: string, message: string, cb?: (input: string) => string | boolean, defaultChoice?: string, skip = false): Record | any { +export function InputValidate( + self: Generator, + name: string, + message: string, + cb?: (input: string) => string | boolean, + defaultChoice?: string, + skip = false, +): Record | any { if (skip) { 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; @@ -35,7 +60,13 @@ export function InputValidate(self: Generator, name: string, message: string, cb 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 }; } diff --git a/packages/info/src/index.ts b/packages/info/src/index.ts index 3fa2c092bd9..fddf308f01c 100644 --- a/packages/info/src/index.ts +++ b/packages/info/src/index.ts @@ -11,7 +11,18 @@ interface Information { const DEFAULT_DETAILS: Information = { Binaries: ["Node", "Yarn", "npm"], - Browsers: ["Brave Browser", "Chrome", "Chrome Canary", "Edge", "Firefox", "Firefox Developer Edition", "Firefox Nightly", "Internet Explorer", "Safari", "Safari Technology Preview"], + Browsers: [ + "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"], @@ -40,7 +51,8 @@ class InfoCommand { 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) => { diff --git a/packages/serve/src/index.ts b/packages/serve/src/index.ts index 8232be361cb..fe4432add48 100644 --- a/packages/serve/src/index.ts +++ b/packages/serve/src/index.ts @@ -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]; }, @@ -68,12 +72,19 @@ class ServeCommand { for (const optionName in options) { 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); + const isBuiltInOption = + 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); + const needToProcess = devServerFlags.find( + (devServerOption) => + devServerOption.name === kebabedOption && devServerOption.processor, + ); if (needToProcess) { processors.push(needToProcess.processor); @@ -91,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); diff --git a/packages/serve/src/startDevServer.ts b/packages/serve/src/startDevServer.ts index 0f2b68814af..e740145daeb 100644 --- a/packages/serve/src/startDevServer.ts +++ b/packages/serve/src/startDevServer.ts @@ -15,7 +15,12 @@ import { devServerOptionsType } from "./types"; * @returns {Object[]} array of resulting servers */ -export default async function startDevServer(compiler: any, devServerCliOptions: any, cliOptions: any, logger: any): Promise[]> { +export default async function startDevServer( + compiler: any, + devServerCliOptions: any, + cliOptions: any, + logger: any, +): Promise[]> { let devServerVersion, Server; try { @@ -24,11 +29,16 @@ export default async function startDevServer(compiler: any, devServerCliOptions: // eslint-disable-next-line node/no-extraneous-require 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 }; @@ -36,7 +46,10 @@ export default async function startDevServer(compiler: any, devServerCliOptions: 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; @@ -47,7 +60,9 @@ export default async function startDevServer(compiler: any, devServerCliOptions: 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,14 +77,20 @@ export default async function startDevServer(compiler: any, devServerCliOptions: 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); + const normalizePublicPath = (publicPath): string => + 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 @@ -101,7 +122,9 @@ export default async function startDevServer(compiler: any, devServerCliOptions: const portNumber = Number(options.port); 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."); + 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.", + ); } usedPorts.push(portNumber); diff --git a/packages/webpack-cli/bin/cli.js b/packages/webpack-cli/bin/cli.js index 8d86a1ffb63..d62a625831c 100755 --- a/packages/webpack-cli/bin/cli.js +++ b/packages/webpack-cli/bin/cli.js @@ -35,7 +35,11 @@ if (utils.packageExists("webpack")) { 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/plugins/CLIPlugin.js b/packages/webpack-cli/lib/plugins/CLIPlugin.js index 57d8333d5e9..7668857d341 100644 --- a/packages/webpack-cli/lib/plugins/CLIPlugin.js +++ b/packages/webpack-cli/lib/plugins/CLIPlugin.js @@ -5,7 +5,9 @@ class CLIPlugin { setupHotPlugin(compiler) { const { HotModuleReplacementPlugin } = compiler.webpack || require("webpack"); - const hotModuleReplacementPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin)); + const hotModuleReplacementPlugin = Boolean( + compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin), + ); if (!hotModuleReplacementPlugin) { new HotModuleReplacementPlugin().apply(compiler); @@ -21,7 +23,9 @@ class CLIPlugin { 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 = Boolean( + compiler.options.plugins.find((plugin) => plugin instanceof BundleAnalyzerPlugin), + ); if (!bundleAnalyzerPlugin) { new BundleAnalyzerPlugin().apply(compiler); @@ -30,10 +34,14 @@ class CLIPlugin { setupProgressPlugin(compiler) { const { ProgressPlugin } = compiler.webpack || require("webpack"); - const progressPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin)); + 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); } } @@ -56,7 +64,9 @@ class CLIPlugin { 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,7 +74,9 @@ 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(); @@ -72,7 +84,9 @@ class CLIPlugin { 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}'`, + ); } }); @@ -90,7 +104,9 @@ class CLIPlugin { 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...`, + ); } }); }); diff --git a/packages/webpack-cli/lib/utils/prompt-installation.js b/packages/webpack-cli/lib/utils/prompt-installation.js index 8b8df03a015..10794efe224 100644 --- a/packages/webpack-cli/lib/utils/prompt-installation.js +++ b/packages/webpack-cli/lib/utils/prompt-installation.js @@ -19,14 +19,22 @@ 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")})`, + 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, }); diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index e2fed178b7d..eca0feaa275 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -18,12 +18,19 @@ class WebpackCLI { 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)); + const alreadyLoaded = this.program.commands.find( + (command) => + command.name() === commandOptions.name.split(" ")[0] || + command.aliases().includes(commandOptions.alias), + ); if (alreadyLoaded) { return; @@ -74,7 +81,11 @@ class WebpackCLI { const { promptInstallation, colors } = this.utils; await promptInstallation(dependency, () => { - this.logger.error(`For using '${colors.green(commandOptions.name.split(" ")[0])}' command you need to install: '${colors.green(dependency)}' package`); + this.logger.error( + `For using '${colors.green( + commandOptions.name.split(" ")[0], + )}' command you need to install: '${colors.green(dependency)}' package`, + ); }); } } @@ -82,7 +93,13 @@ class WebpackCLI { if (options) { if (typeof options === "function") { if (forHelp && !allDependenciesInstalled) { - command.description(`${commandOptions.description} To see all available options you need to install ${commandOptions.dependencies.map((dependency) => `'${dependency}'`).join(",")}.`); + command.description( + `${ + commandOptions.description + } To see all available options you need to install ${commandOptions.dependencies + .map((dependency) => `'${dependency}'`) + .join(",")}.`, + ); options = []; } else { options = options(); @@ -170,7 +187,9 @@ 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 { @@ -178,7 +197,9 @@ class WebpackCLI { 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]), + type: option.type + ? new Set(Array.isArray(option.type) ? option.type : [option.type]) + : new Set([Boolean]), multiple: option.multiple, defaultValue: option.defaultValue, }; @@ -186,7 +207,9 @@ 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.`, }; } } @@ -208,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); @@ -233,13 +258,18 @@ 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; command.addOption(optionForCommand); } else { - const optionForCommand = new Option(mainOption.flags, mainOption.description).argParser(Array.from(mainOption.type)[0]).default(mainOption.defaultValue); + const optionForCommand = new Option(mainOption.flags, mainOption.description) + .argParser(Array.from(mainOption.type)[0]) + .default(mainOption.defaultValue); optionForCommand.helpLevel = option.helpLevel; @@ -248,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 = []; @@ -259,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; } } @@ -298,7 +334,24 @@ class WebpackCLI { return this.builtInOptionsCache; } - const minimumHelpFlags = ["config", "config-name", "merge", "env", "mode", "watch", "watch-options-stdin", "stats", "devtool", "entry", "target", "progress", "json", "name", "output-path", "node-env"]; + const minimumHelpFlags = [ + "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 @@ -311,7 +364,8 @@ class WebpackCLI { }, ], 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", @@ -515,7 +569,8 @@ class WebpackCLI { type: "string", }, ], - description: "Name of the configuration. Used when loading multiple configurations.", + description: + "Name of the configuration. Used when loading multiple configurations.", }, { name: "stats", @@ -563,7 +618,13 @@ 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" }; @@ -571,7 +632,12 @@ class WebpackCLI { : []; 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"; @@ -607,7 +673,8 @@ class WebpackCLI { const versionCommandOptions = { name: "version [commands...]", alias: "v", - description: "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", + description: + "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", }; const helpCommandOptions = { name: "help [command] [option]", @@ -653,9 +720,22 @@ class WebpackCLI { }, ]; - const knownCommands = [buildCommandOptions, watchCommandOptions, versionCommandOptions, helpCommandOptions, ...externalBuiltInCommandsInfo]; + const knownCommands = [ + buildCommandOptions, + watchCommandOptions, + versionCommandOptions, + helpCommandOptions, + ...externalBuiltInCommandsInfo, + ]; 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)); + const isKnownCommand = (name) => + knownCommands.find( + (command) => + getCommandName(command.name) === name || + (Array.isArray(command.alias) + ? command.alias.includes(name) + : command.alias === name), + ); const isCommand = (input, commandOptions) => { const longName = getCommandName(commandOptions.name); @@ -673,9 +753,18 @@ class WebpackCLI { return false; }; - const findCommandByName = (name) => this.program.commands.find((command) => name === command.name() || command.aliases().includes(name)); + const findCommandByName = (name) => + 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"; + const isGlobalOption = (value) => + value === "--color" || + value === "--no-color" || + value === "-v" || + value === "--version" || + value === "-h" || + value === "--help"; const loadCommandByName = async (commandName, allowToInstall = false) => { const isBuildCommandUsed = isCommand(commandName, buildCommandOptions); @@ -684,13 +773,19 @@ class WebpackCLI { if (isBuildCommandUsed || isWatchCommandUsed) { const options = this.getBuiltInOptions(); - await this.makeCommand(isBuildCommandUsed ? buildCommandOptions : watchCommandOptions, isWatchCommandUsed ? options.filter((option) => option.name !== "watch") : options, async (entries, options) => { - if (entries.length > 0) { - options.entry = [...entries, ...(options.entry || [])]; - } + await this.makeCommand( + isBuildCommandUsed ? buildCommandOptions : watchCommandOptions, + isWatchCommandUsed + ? options.filter((option) => option.name !== "watch") + : options, + async (entries, options) => { + if (entries.length > 0) { + options.entry = [...entries, ...(options.entry || [])]; + } - await this.buildCommand(options, isWatchCommandUsed); - }); + await this.buildCommand(options, isWatchCommandUsed); + }, + ); } else if (isCommand(commandName, helpCommandOptions)) { // Stub for the `help` command this.makeCommand(helpCommandOptions, [], () => {}); @@ -701,7 +796,9 @@ class WebpackCLI { const builtInExternalCommandInfo = externalBuiltInCommandsInfo.find( (externalBuiltInCommandInfo) => getCommandName(externalBuiltInCommandInfo.name) === commandName || - (Array.isArray(externalBuiltInCommandInfo.alias) ? externalBuiltInCommandInfo.alias.includes(commandName) : externalBuiltInCommandInfo.alias === commandName), + (Array.isArray(externalBuiltInCommandInfo.alias) + ? externalBuiltInCommandInfo.alias.includes(commandName) + : externalBuiltInCommandInfo.alias === commandName), ); let pkg; @@ -720,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`, + ); }); } @@ -777,19 +878,27 @@ class WebpackCLI { } 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()}'?`); } }); @@ -829,7 +938,11 @@ class WebpackCLI { const outputVersion = async (options) => { // Filter `bundle`, `watch`, `version` and `help` commands const possibleCommandNames = options.filter( - (option) => !isCommand(option, buildCommandOptions) && !isCommand(option, watchCommandOptions) && !isCommand(option, versionCommandOptions) && !isCommand(option, helpCommandOptions), + (option) => + !isCommand(option, buildCommandOptions) && + !isCommand(option, watchCommandOptions) && + !isCommand(option, versionCommandOptions) && + !isCommand(option, helpCommandOptions), ); possibleCommandNames.forEach((possibleCommandName) => { @@ -843,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); } @@ -859,7 +978,9 @@ 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); } } @@ -879,14 +1000,19 @@ class WebpackCLI { process.exit(0); }; - this.program.option("-v, --version", "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands."); + this.program.option( + "-v, --version", + "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", + ); const outputHelp = async (options, isVerbose, isHelpCommandSyntax, program) => { 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( + "Please use: 'webpack help [command] [option]' | 'webpack [command] --help'", + ); this.logger.error("Run 'webpack --help' to see available commands and options"); process.exit(2); }; @@ -901,26 +1027,41 @@ class WebpackCLI { commandUsage: (command) => { 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:")} ${parentCmdNames}[command] [options]`; + return `${parentCmdNames}${command.usage()}\n${this.utils.colors.bold( + "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) => { @@ -943,63 +1084,106 @@ 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)}`, ""]; // Description - const commandDescription = isGlobalHelp ? "The build tool for modern web applications." : helper.commandDescription(command); + const commandDescription = isGlobalHelp + ? "The build tool for modern web applications." + : helper.commandDescription(command); if (commandDescription.length > 0) { output = output.concat([commandDescription, ""]); } // Arguments - const argumentList = helper.visibleArguments(command).map((argument) => formatItem(argument.term, argument.description)); + const argumentList = helper + .visibleArguments(command) + .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))); + const optionList = helper + .visibleOptions(command) + .map((option) => + formatItem( + helper.optionTerm(option), + helper.optionDescription(option), + ), + ); if (optionList.length > 0) { output = output.concat([bold("Options:"), formatList(optionList), ""]); } // Global options - const globalOptionList = program.options.map((option) => formatItem(helper.optionTerm(option), helper.optionDescription(option))); + const globalOptionList = program.options.map((option) => + formatItem(helper.optionTerm(option), helper.optionDescription(option)), + ); 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))); + const commandList = helper + .visibleCommands(isGlobalHelp ? program : 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"); @@ -1013,7 +1197,9 @@ class WebpackCLI { }), ); - const buildCommand = findCommandByName(getCommandName(buildCommandOptions.name)); + const buildCommand = findCommandByName( + getCommandName(buildCommandOptions.name), + ); this.logger.raw(buildCommand.helpInformation()); } else { @@ -1024,12 +1210,18 @@ class WebpackCLI { const command = findCommandByName(name); if (!command) { - const builtInCommandUsed = externalBuiltInCommandsInfo.find((command) => command.name.includes(name) || name === command.alias); + 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`); + 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); } @@ -1057,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}'`); @@ -1065,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}'`); @@ -1073,13 +1269,27 @@ class WebpackCLI { process.exit(2); } - const 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}` : ""}`); + const 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}` : ""}`, + ); if (option.short) { - this.logger.raw(`${bold("Short:")} webpack${isCommandSpecified ? ` ${commandName}` : ""} ${option.short}${value ? ` ${value}` : ""}`); + this.logger.raw( + `${bold("Short:")} webpack${isCommandSpecified ? ` ${commandName}` : ""} ${ + option.short + }${value ? ` ${value}` : ""}`, + ); } if (option.description) { @@ -1087,7 +1297,9 @@ class WebpackCLI { } 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(""); @@ -1099,7 +1311,9 @@ class WebpackCLI { outputIncorrectUsageOfHelp(); } - this.logger.raw("To see list of all supported commands and options run 'webpack --help=verbose'.\n"); + 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")}.`); @@ -1136,7 +1350,9 @@ class WebpackCLI { if (isHelpOption) { if (typeof options.help === "string") { if (options.help !== "verbose") { - this.logger.error("Unknown value for '--help' option, please use '--help=verbose'"); + this.logger.error( + "Unknown value for '--help' option, please use '--help=verbose'", + ); process.exit(2); } @@ -1152,8 +1368,16 @@ 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); } @@ -1186,10 +1410,20 @@ class WebpackCLI { } else { this.logger.error(`Unknown command or entry '${operand}'`); - const found = knownCommands.find((commandOptions) => this.utils.levenshtein.distance(operand, getCommandName(commandOptions.name)) < 3); + const found = knownCommands.find( + (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}')?`); + this.logger.error( + `Did you mean '${getCommandName(found.name)}' (alias '${ + Array.isArray(found.alias) ? found.alias.join(", ") : found.alias + }')?`, + ); } this.logger.error("Run 'webpack --help' to see available commands and options"); @@ -1197,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); @@ -1207,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; @@ -1252,7 +1490,12 @@ class WebpackCLI { Module.prototype._compile = previousModuleCompile; } - if ((error.code === "ERR_REQUIRE_ESM" || process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) && pathToFileURL && dynamicImportLoader) { + if ( + (error.code === "ERR_REQUIRE_ESM" || + process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) && + pathToFileURL && + dynamicImportLoader + ) { const urlForConfig = pathToFileURL(configPath); options = await dynamicImportLoader(urlForConfig); @@ -1317,7 +1560,11 @@ class WebpackCLI { let config = { options: {}, path: new WeakMap() }; 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 || {}))); + const evaluatedConfigs = await Promise.all( + options.config.map(async (value) => + evaluateConfig(await loadConfig(path.resolve(value)), options.argv || {}), + ), + ); config.options = []; @@ -1338,7 +1585,11 @@ 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) => ({ @@ -1396,7 +1647,14 @@ class WebpackCLI { }); if (notfoundConfigNames.length > 0) { - this.logger.error(notfoundConfigNames.map((configName) => `Configuration with the name "${configName}" was not found.`).join(" ")); + this.logger.error( + notfoundConfigNames + .map( + (configName) => + `Configuration with the name "${configName}" was not found.`, + ) + .join(" "), + ); process.exit(2); } } @@ -1435,26 +1693,45 @@ class WebpackCLI { const { promptInstallation, colors } = this.utils; await promptInstallation("webpack-bundle-analyzer", () => { - this.logger.error(`It looks like ${colors.yellow("webpack-bundle-analyzer")} is not installed.`); + 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.`); + 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.`); + this.logger.error( + `'${options.hot}' is an invalid value for the --hot option. Use 'only' instead.`, + ); process.exit(2); } const outputHints = (configOptions) => { - if (configOptions.watch && options.argv && options.argv.env && (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"}' command together with '{ watch: true }' configuration, it does not make sense.`); + if ( + configOptions.watch && + options.argv && + options.argv.env && + (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" + }' command together with '{ watch: true }' configuration, it does not make sense.`, + ); if (options.argv.env["WEBPACK_SERVE"]) { configOptions.watch = false; @@ -1464,7 +1741,9 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) ? config.options.map((options) => outputHints(options)) : outputHints(config.options); + config.options = Array.isArray(config.options) + ? config.options.map((options) => outputHints(options)) + : outputHints(config.options); if (this.webpack.cli) { const processArguments = (configOptions) => { @@ -1507,9 +1786,11 @@ class WebpackCLI { 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) { @@ -1524,7 +1805,9 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) ? config.options.map((options) => processArguments(options)) : processArguments(config.options); + config.options = Array.isArray(config.options) + ? config.options.map((options) => processArguments(options)) + : processArguments(config.options); const setupDefaultOptions = (configOptions) => { // No need to run for webpack@4 @@ -1553,7 +1836,9 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) ? config.options.map((options) => setupDefaultOptions(options)) : setupDefaultOptions(config.options); + config.options = Array.isArray(config.options) + ? config.options.map((options) => setupDefaultOptions(options)) + : setupDefaultOptions(config.options); } // Logic for webpack@4 @@ -1580,7 +1865,14 @@ class WebpackCLI { if (options.mode) { configOptions.mode = options.mode; - } else if (!configOptions.mode && process.env && process.env.NODE_ENV && (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "production" || process.env.NODE_ENV === "none")) { + } else if ( + !configOptions.mode && + process.env && + process.env.NODE_ENV && + (process.env.NODE_ENV === "development" || + process.env.NODE_ENV === "production" || + process.env.NODE_ENV === "none") + ) { configOptions.mode = process.env.NODE_ENV; } @@ -1606,7 +1898,9 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) ? config.options.map((options) => processLegacyArguments(options)) : processLegacyArguments(config.options); + config.options = Array.isArray(config.options) + ? config.options.map((options) => processLegacyArguments(options)) + : processLegacyArguments(config.options); // Apply `stats` and `stats.colors` options const applyStatsColors = (configOptions) => { @@ -1616,7 +1910,10 @@ class WebpackCLI { if (statsForWebpack4) { 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" && @@ -1635,7 +1932,9 @@ class WebpackCLI { if (typeof configOptions.stats === "undefined") { configOptions.stats = { preset: "normal" }; } else if (typeof configOptions.stats === "boolean") { - configOptions.stats = configOptions.stats ? { preset: "normal" } : { preset: "none" }; + configOptions.stats = configOptions.stats + ? { preset: "normal" } + : { preset: "none" }; } else if (typeof configOptions.stats === "string") { configOptions.stats = { preset: configOptions.stats }; } @@ -1661,7 +1960,9 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) ? config.options.map((options) => applyStatsColors(options)) : applyStatsColors(config.options); + config.options = Array.isArray(config.options) + ? config.options.map((options) => applyStatsColors(options)) + : applyStatsColors(config.options); return config; } @@ -1687,14 +1988,18 @@ class WebpackCLI { return configOptions; }; - config.options = Array.isArray(config.options) ? config.options.map((options) => addCLIPlugin(options)) : addCLIPlugin(config.options); + config.options = Array.isArray(config.options) + ? config.options.map((options) => addCLIPlugin(options)) + : addCLIPlugin(config.options); return config; } 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; @@ -1703,7 +2008,8 @@ 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"; } @@ -1767,7 +2073,15 @@ class WebpackCLI { return; } - const statsOptions = compiler.compilers ? { children: compiler.compilers.map((compiler) => (compiler.options ? compiler.options.stats : undefined)) } : compiler.options ? compiler.options.stats : undefined; + const statsOptions = compiler.compilers + ? { + children: compiler.compilers.map((compiler) => + compiler.options ? compiler.options.stats : undefined, + ), + } + : compiler.options + ? compiler.options.stats + : undefined; // TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats const statsForWebpack4 = this.webpack.Stats && this.webpack.Stats.presetToOptions; @@ -1777,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); @@ -1795,7 +2111,13 @@ class WebpackCLI { .pipe(fs.createWriteStream(options.json)) .on("error", handleWriteError) // Use stderr to logging - .on("close", () => process.stderr.write(`[webpack-cli] ${this.utils.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`)); + .on("close", () => + process.stderr.write( + `[webpack-cli] ${this.utils.colors.green( + `stats are successfully stored as json to ${options.json}`, + )}\n`, + ), + ); } } else { const printedStats = stats.toString(statsOptions); @@ -1807,7 +2129,10 @@ class WebpackCLI { } }; - const env = isWatchCommand || options.watch ? { WEBPACK_WATCH: true, ...options.env } : { WEBPACK_BUNDLE: true, WEBPACK_BUILD: true, ...options.env }; + const env = + isWatchCommand || options.watch + ? { WEBPACK_WATCH: true, ...options.env } + : { WEBPACK_BUNDLE: true, WEBPACK_BUILD: true, ...options.env }; options.argv = { ...options, env }; @@ -1821,7 +2146,10 @@ class WebpackCLI { return; } - const isWatch = (compiler) => (compiler.compilers ? compiler.compilers.some((compiler) => compiler.options.watch) : compiler.options.watch); + const isWatch = (compiler) => + compiler.compilers + ? compiler.compilers.some((compiler) => compiler.options.watch) + : compiler.options.watch; if (isWatch(compiler) && this.needWatchStdin(compiler)) { process.stdin.on("end", () => { diff --git a/prettier.config.js b/prettier.config.js index b483f6430df..a3ca7933373 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,3 +1,4 @@ module.exports = { + printWidth: 100, trailingComma: "all", }; diff --git a/scripts/cleanupTest.js b/scripts/cleanupTest.js index 8723591c2f0..9be7a8effdb 100644 --- a/scripts/cleanupTest.js +++ b/scripts/cleanupTest.js @@ -3,7 +3,18 @@ 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"]; +const outputDirectories = [ + "bin", + "binary", + "dist", + "test", + "test-assets", + "test-plugin", + "test-loader", + "test-cache-path", + "test-locate-cache", + "stats.json", +]; const folderStrategy = (stats, file) => { return stats.isDirectory() && outputDirectories.includes(file); diff --git a/scripts/snapshotResolver.js b/scripts/snapshotResolver.js index b51a8790cdc..0683c4e30b9 100644 --- a/scripts/snapshotResolver.js +++ b/scripts/snapshotResolver.js @@ -14,11 +14,20 @@ 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), + 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 67aecdf33c5..6193903a675 100644 --- a/scripts/updateDocs.js +++ b/scripts/updateDocs.js @@ -4,10 +4,14 @@ 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(""); @@ -16,10 +20,14 @@ try { 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(""); diff --git a/smoketests/helpers.js b/smoketests/helpers.js index 20165154af7..eac6e1f9100 100644 --- a/smoketests/helpers.js +++ b/smoketests/helpers.js @@ -5,7 +5,9 @@ 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}`; @@ -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); diff --git a/smoketests/missing-command-packages/configtest.test.js b/smoketests/missing-command-packages/configtest.test.js index 950504e28bf..66683b4d53f 100644 --- a/smoketests/missing-command-packages/configtest.test.js +++ b/smoketests/missing-command-packages/configtest.test.js @@ -7,14 +7,16 @@ const isSubPackage = true; const configTest = () => { const args = ["configtest"]; - const logMessage = "For using this command you need to install: '@webpack-cli/configtest' package"; + 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 logMessage = + "For using 'configtest' command you need to install '@webpack-cli/configtest' package"; return runTestWithHelp(packageName, args, logMessage, isSubPackage); }; diff --git a/smoketests/missing-command-packages/generator.test.js b/smoketests/missing-command-packages/generator.test.js index 4b8c3590d01..c0c95b8a8e9 100644 --- a/smoketests/missing-command-packages/generator.test.js +++ b/smoketests/missing-command-packages/generator.test.js @@ -7,14 +7,16 @@ const isSubPackage = true; const initTest = () => { const args = ["init"]; - const logMessage = "For using this command you need to install: '@webpack-cli/generators' package"; + 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 logMessage = + "For using 'init' command you need to install '@webpack-cli/generators' package"; return runTestWithHelp(packageName, args, logMessage, isSubPackage); }; diff --git a/smoketests/missing-packages/prettier.test.js b/smoketests/missing-packages/prettier.test.js index d305d5d61db..a11677ab865 100644 --- a/smoketests/missing-packages/prettier.test.js +++ b/smoketests/missing-packages/prettier.test.js @@ -22,8 +22,14 @@ const prettierTestWithNoAnswer = async () => { const inputs = { "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; }; diff --git a/smoketests/missing-packages/webpack-dev-server.test.js b/smoketests/missing-packages/webpack-dev-server.test.js index ba4f1572f05..e053a970a1d 100644 --- a/smoketests/missing-packages/webpack-dev-server.test.js +++ b/smoketests/missing-packages/webpack-dev-server.test.js @@ -5,7 +5,8 @@ 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 logMessage = + "For using 'serve' command you need to install: 'webpack-dev-server' package"; return runTest(packageName, args, logMessage); }; diff --git a/test/api/CLI.test.js b/test/api/CLI.test.js index c28953f0370..738e6d2aa2a 100644 --- a/test/api/CLI.test.js +++ b/test/api/CLI.test.js @@ -201,7 +201,9 @@ describe("CLI API", () => { }, ); - 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) => { @@ -591,7 +593,9 @@ describe("CLI API", () => { }, ); - 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) => { @@ -616,7 +620,9 @@ describe("CLI API", () => { }, ); - 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) => { @@ -690,7 +696,9 @@ 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) => { @@ -716,7 +724,9 @@ 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) => { @@ -822,7 +832,9 @@ describe("CLI API", () => { }, ); - 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) => { @@ -933,7 +945,9 @@ describe("CLI API", () => { }, ); - 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) => { @@ -977,13 +991,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1033,7 +1051,9 @@ describe("CLI API", () => { }, ); - 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) => { @@ -1106,7 +1126,9 @@ 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) => { @@ -1148,13 +1170,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1178,7 +1204,9 @@ 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) => { @@ -1196,13 +1224,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1221,7 +1253,9 @@ describe("CLI API", () => { }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: "default" }); + expect(options).toEqual({ + booleanAndNumberAndString: "default", + }); done(); }, @@ -1246,13 +1280,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1277,7 +1315,9 @@ 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) => { @@ -1296,13 +1336,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1321,13 +1365,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1346,13 +1394,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1371,13 +1423,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1396,13 +1452,23 @@ describe("CLI API", () => { }, ], (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) => { @@ -1421,13 +1487,18 @@ describe("CLI API", () => { }, ], (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) => { @@ -1447,7 +1518,9 @@ describe("CLI API", () => { }, ], (options) => { - expect(options).toEqual({ booleanAndNumberAndString: "default" }); + expect(options).toEqual({ + booleanAndNumberAndString: "default", + }); done(); }, @@ -1473,13 +1546,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1499,13 +1576,17 @@ describe("CLI API", () => { }, ], (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) => { @@ -1525,13 +1606,18 @@ describe("CLI API", () => { }, ], (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) => { diff --git a/test/api/prompt-installation.test.js b/test/api/prompt-installation.test.js index d7c660a5d0b..691b8b123b8 100644 --- a/test/api/prompt-installation.test.js +++ b/test/api/prompt-installation.test.js @@ -40,7 +40,9 @@ describe("promptInstallation", () => { expect(preMessage.mock.calls.length).toEqual(1); expect(prompt.mock.calls.length).toEqual(1); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'npm install -D test-package')"); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( + "Would you like to install 'test-package' package? (That will run 'npm install -D test-package')", + ); // install the package using npm expect(runCommand.mock.calls[0][0]).toEqual("npm install -D test-package"); @@ -56,7 +58,9 @@ describe("promptInstallation", () => { expect(promptResult).toBeTruthy(); expect(prompt.mock.calls.length).toEqual(1); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'yarn add -D test-package')"); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( + "Would you like to install 'test-package' package? (That will run 'yarn add -D test-package')", + ); // install the package using yarn expect(runCommand.mock.calls[0][0]).toEqual("yarn add -D test-package"); @@ -72,7 +76,9 @@ describe("promptInstallation", () => { expect(promptResult).toBeTruthy(); expect(prompt.mock.calls.length).toEqual(1); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'pnpm install -D test-package')"); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( + "Would you like to install 'test-package' package? (That will run 'pnpm install -D test-package')", + ); // install the package using npm expect(runCommand.mock.calls[0][0]).toEqual("pnpm install -D test-package"); @@ -90,7 +96,9 @@ describe("promptInstallation", () => { expect(preMessage.mock.calls.length).toEqual(1); expect(prompt.mock.calls.length).toEqual(1); expect(runCommand.mock.calls.length).toEqual(1); - expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain("Would you like to install 'test-package' package? (That will run 'npm install -D test-package')"); + expect(stripAnsi(prompt.mock.calls[0][0].message)).toContain( + "Would you like to install 'test-package' package? (That will run 'npm install -D test-package')", + ); // install the package using npm expect(runCommand.mock.calls[0][0]).toEqual("npm install -D test-package"); diff --git a/test/api/resolveConfig/resolveConfig.test.js b/test/api/resolveConfig/resolveConfig.test.js index ee92ae1ad9b..83450146495 100644 --- a/test/api/resolveConfig/resolveConfig.test.js +++ b/test/api/resolveConfig/resolveConfig.test.js @@ -15,7 +15,10 @@ describe("resolveConfig", function () { }); const expectedOptions = { - output: { filename: "./dist-commonjs.js", libraryTarget: "commonjs" }, + output: { + filename: "./dist-commonjs.js", + libraryTarget: "commonjs", + }, entry: "./a.js", name: "amd", mode: "production", @@ -28,7 +31,10 @@ describe("resolveConfig", function () { 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]; @@ -36,13 +42,17 @@ describe("resolveConfig", function () { }); it("should return config object for single config", async () => { - const result = await cli.resolveConfig({ config: [resolve(__dirname, "./webpack.config1.cjs")] }); + 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")] }); + const result = await cli.resolveConfig({ + config: [resolve(__dirname, "./webpack.promise.config.cjs")], + }); const expectedOptions = await promiseConfig(); expect(result.options).toEqual(expectedOptions); @@ -50,7 +60,10 @@ describe("resolveConfig", function () { 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]; diff --git a/test/api/scaffold-utils.test.js b/test/api/scaffold-utils.test.js index 74305636ba6..06cdc64bfcb 100755 --- a/test/api/scaffold-utils.test.js +++ b/test/api/scaffold-utils.test.js @@ -1,5 +1,10 @@ -// 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", () => { let mockSelf; @@ -23,9 +28,11 @@ describe("utils", () => { }); it("should make default value for a List", () => { - expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes", true)).toEqual({ - entry: "Yes", - }); + expect(List(mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes", true)).toEqual( + { + entry: "Yes", + }, + ); }); it("should emulate a prompt for list input", () => { @@ -59,15 +66,28 @@ describe("utils", () => { }); it("should make an Input object with validation", () => { - expect(InputValidate(mockSelf, "plugins", "what is your plugin?", () => true)).toMatchSnapshot(); + 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(); + 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({ + 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 3cdcac020ca..1b45e71a53d 100644 --- a/test/build/analyze/analyze-flag.test.js +++ b/test/build/analyze/analyze-flag.test.js @@ -4,11 +4,17 @@ 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"]); + 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).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 8ea874869d9..a1671a29911 100644 --- a/test/build/analyze/analyze.config.js +++ b/test/build/analyze/analyze.config.js @@ -3,5 +3,10 @@ const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); module.exports = { mode: "development", - plugins: [new BundleAnalyzerPlugin({ analyzerMode: "static", openAnalyzer: false })], + plugins: [ + new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + }), + ], }; diff --git a/test/build/bail/bail.test.js b/test/build/bail/bail.test.js index 32315b2ea1d..9e246571648 100644 --- a/test/build/bail/bail.test.js +++ b/test/build/bail/bail.test.js @@ -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/basic/basic.test.js b/test/build/basic/basic.test.js index ce3fbb85922..a6a089e062e 100644 --- a/test/build/basic/basic.test.js +++ b/test/build/basic/basic.test.js @@ -21,7 +21,10 @@ describe("bundle command", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -29,7 +32,12 @@ describe("bundle command", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + "--mode", + "development", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -37,7 +45,12 @@ describe("bundle command", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "development", + "./src/index.js", + "./src/other.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -45,7 +58,12 @@ describe("bundle command", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + "--entry", + "./src/again.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -53,7 +71,12 @@ describe("bundle command", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "./src/index.js", + "./src/other.js", + "--config", + "./entry.config.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(); diff --git a/test/build/build-errors/errors.test.js b/test/build/build-errors/errors.test.js index 902e99e84e1..874552f6a0d 100644 --- a/test/build/build-errors/errors.test.js +++ b/test/build/build-errors/errors.test.js @@ -25,7 +25,9 @@ describe("errors", () => { 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 () => { @@ -50,6 +52,8 @@ describe("errors", () => { 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-warnings/warnings.test.js b/test/build/build-warnings/warnings.test.js index 0d4f7a1eee2..2af5019f048 100644 --- a/test/build/build-warnings/warnings.test.js +++ b/test/build/build-warnings/warnings.test.js @@ -27,7 +27,9 @@ describe("warnings", () => { 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 () => { @@ -53,6 +55,8 @@ describe("warnings", () => { 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/cache/cache.test.js b/test/build/cache/cache.test.js index a7c11890646..496e7c7a04e 100644 --- a/test/build/cache/cache.test.js +++ b/test/build/cache/cache.test.js @@ -7,7 +7,12 @@ 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")); + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-default-development", + ), + ); let { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]); @@ -34,8 +39,18 @@ 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")); + 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"]); @@ -62,9 +77,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")); + 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"]); + let { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./multi.config.js", + "--config-name", + "cache-test-first", + "--name", + "cache-test-third", + ]); expect(exitCode).toEqual(0); @@ -75,7 +102,14 @@ describe("cache", () => { expect(stdout).toBeTruthy(); } - ({ exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js", "--config-name", "cache-test-first", "--name", "cache-test-third"])); + ({ exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./multi.config.js", + "--config-name", + "cache-test-first", + "--name", + "cache-test-third", + ])); expect(exitCode).toEqual(0); @@ -89,9 +123,22 @@ describe("cache", () => { }); it("should work with the `--merge` argument", async () => { - rimraf.sync(path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-fourth-development")); + 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"]); + let { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./multi.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--name", + "cache-test-fourth", + ]); expect(exitCode).toEqual(0); @@ -102,7 +149,15 @@ describe("cache", () => { expect(stdout).toBeTruthy(); } - ({ exitCode, stderr, stdout } = await run(__dirname, ["-c", "./multi.config.js", "-c", "./webpack.config.js", "--merge", "--name", "cache-test-fourth"])); + ({ exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./multi.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--name", + "cache-test-fourth", + ])); expect(exitCode).toEqual(0); @@ -116,7 +171,12 @@ 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")); + rimraf.sync( + path.join( + __dirname, + "../../../node_modules/.cache/webpack/cache-test-fifth-development", + ), + ); let { exitCode, stderr, stdout } = await run(__dirname, [ "-c", @@ -167,9 +227,17 @@ describe("cache", () => { }); it("should work with autoloading configuration", async () => { - rimraf.sync(path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-autoloading-development")); + 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); diff --git a/test/build/colors/colors.test.js b/test/build/colors/colors.test.js index 2a390d80d36..9d332515c6d 100644 --- a/test/build/colors/colors.test.js +++ b/test/build/colors/colors.test.js @@ -5,7 +5,9 @@ const { resolve } = require("path"); describe("colors", () => { it("should output by default", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, [], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -14,7 +16,9 @@ describe("colors", () => { }); 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(); @@ -23,7 +27,11 @@ describe("colors", () => { }); 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")}`], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--stats=verbose", `--config=${resolve(__dirname, "./no-stats.webpack.config.js")}`], + { env: { FORCE_COLOR: true } }, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -32,9 +40,13 @@ describe("colors", () => { }); 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(); @@ -52,7 +64,10 @@ describe("colors", () => { }); it("should disable colored output with --no-color", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--stats=verbose", "--no-color"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--stats=verbose", + "--no-color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -62,9 +77,13 @@ describe("colors", () => { }); 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(); @@ -73,9 +92,13 @@ describe("colors", () => { }); 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(); @@ -84,9 +107,13 @@ describe("colors", () => { }); 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(); @@ -95,7 +122,9 @@ describe("colors", () => { }); 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(); @@ -104,7 +133,9 @@ describe("colors", () => { }); 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(); @@ -114,7 +145,10 @@ describe("colors", () => { }); it("should prioritize --color over colors in config", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--config=colors-false.webpack.config.js", "--color"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=colors-false.webpack.config.js", + "--color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -123,7 +157,10 @@ describe("colors", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=colors-true.webpack.config.js", + "--no-color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -133,7 +170,10 @@ describe("colors", () => { }); it("should work in multi compiler mode", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--config=multiple-configs.js", "--color"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config=multiple-configs.js", + "--color", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config-format/failure/failure.test.js b/test/build/config-format/failure/failure.test.js index 391a1b8d0f5..ffa5ad01270 100644 --- a/test/build/config-format/failure/failure.test.js +++ b/test/build/config-format/failure/failure.test.js @@ -7,7 +7,9 @@ describe("failure", () => { 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'"); 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 a0bb7e2c4d8..ab211df7819 100644 --- a/test/build/config-lookup/custom-name/custom-name.test.js +++ b/test/build/config-lookup/custom-name/custom-name.test.js @@ -5,7 +5,10 @@ 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")]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + resolve(__dirname, "config.webpack.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -13,9 +16,13 @@ describe("custom config file", () => { }); 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 }, - }); + 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/relative/basic-config.test.js b/test/build/config-lookup/relative/basic-config.test.js index 557cf53e882..cb07beb1082 100644 --- a/test/build/config-lookup/relative/basic-config.test.js +++ b/test/build/config-lookup/relative/basic-config.test.js @@ -4,7 +4,12 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "webpack.config.js", + "--output-path", + "./binary/a", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -12,7 +17,12 @@ describe("relative path to config", () => { }); it("should work #2", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js", "--output-path", "./binary/b"]); + 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-name/config-name.test.js b/test/build/config-name/config-name.test.js index 521f46ddc51..4dee9145219 100644 --- a/test/build/config-name/config-name.test.js +++ b/test/build/config-name/config-name.test.js @@ -14,7 +14,12 @@ describe("--config-name flag", () => { }); it("should work with multiple values for --config-name", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--config-name", "first", "--config-name", "third"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config-name", + "first", + "--config-name", + "third", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -24,7 +29,20 @@ describe("--config-name flag", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + [ + "-c", + "./function-config.js", + "-c", + "./single-other-config.js", + "--config-name", + "first", + "--config-name", + "four", + ], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -43,7 +61,12 @@ describe("--config-name flag", () => { }); 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"]); + 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.'); @@ -51,7 +74,11 @@ describe("--config-name flag", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config-name", "test", "--config-name", "bar", "-c", "single-config.js"], + false, + ); expect(exitCode).toBe(2); expect(stderr).toContain('Configuration with the name "test" was not found.'); @@ -60,7 +87,11 @@ describe("--config-name flag", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config-name", "first", "--config-name", "bar", "-c", "single-config.js"], + false, + ); expect(exitCode).toBe(2); expect(stderr).toContain('Configuration with the name "bar" was not found.'); @@ -68,7 +99,12 @@ describe("--config-name flag", () => { }); it("should work with config as a function", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--config", "function-config.js", "--config-name", "first"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "function-config.js", + "--config-name", + "first", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -78,7 +114,11 @@ describe("--config-name flag", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config", "function-config.js", "--config-name", "first", "--config-name", "third"], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -88,7 +128,12 @@ describe("--config-name flag", () => { }); 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"]); + 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/absent/config-absent.test.js b/test/build/config/absent/config-absent.test.js index 7ba9ffb514e..9442d6b6199 100644 --- a/test/build/config/absent/config-absent.test.js +++ b/test/build/config/absent/config-absent.test.js @@ -5,12 +5,17 @@ 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")]); + 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/basic/basic-config.test.js b/test/build/config/basic/basic-config.test.js index 5f89f96d1eb..3fa970ffdc4 100644 --- a/test/build/config/basic/basic-config.test.js +++ b/test/build/config/basic/basic-config.test.js @@ -5,7 +5,12 @@ 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", resolve(__dirname, "webpack.config.js"), "--output-path", "./binary"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + "--output-path", + "./binary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).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 0812b3679b6..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 @@ -4,7 +4,9 @@ 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 } }); + 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); diff --git a/test/build/config/empty-array/empty-array.test.js b/test/build/config/empty-array/empty-array.test.js index d983078c910..ec3ef7203b4 100644 --- a/test/build/config/empty-array/empty-array.test.js +++ b/test/build/config/empty-array/empty-array.test.js @@ -4,7 +4,10 @@ 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")]); + 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 d983078c910..ec3ef7203b4 100644 --- a/test/build/config/empty-function/empty-function.test.js +++ b/test/build/config/empty-function/empty-function.test.js @@ -4,7 +4,10 @@ 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")]); + 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 d983078c910..ec3ef7203b4 100644 --- a/test/build/config/empty-promise/empty-promise.test.js +++ b/test/build/config/empty-promise/empty-promise.test.js @@ -4,7 +4,10 @@ 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")]); + 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 d983078c910..ec3ef7203b4 100644 --- a/test/build/config/empty/empty.test.js +++ b/test/build/config/empty/empty.test.js @@ -4,7 +4,10 @@ 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")]); + 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-commonjs/config-error.test.js b/test/build/config/error-commonjs/config-error.test.js index 6d8bf8d8a6a..89f2969234d 100644 --- a/test/build/config/error-commonjs/config-error.test.js +++ b/test/build/config/error-commonjs/config-error.test.js @@ -4,7 +4,10 @@ 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")]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + ]); expect(exitCode).toBe(2); expect(stderr).toContain("Invalid configuration object"); @@ -13,7 +16,10 @@ describe("config error", () => { }); 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")]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "syntax-error.js"), + ]); expect(exitCode).toBe(2); expect(stderr).toContain("SyntaxError: Unexpected token"); diff --git a/test/build/config/error-mjs/config-error.test.js b/test/build/config/error-mjs/config-error.test.js index f51e0de9d94..6a69898ca13 100644 --- a/test/build/config/error-mjs/config-error.test.js +++ b/test/build/config/error-mjs/config-error.test.js @@ -4,9 +4,13 @@ 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 }, - }); + 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); @@ -19,9 +23,13 @@ describe("config error", () => { }); 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 }, - }); + 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); diff --git a/test/build/config/function/functional-config.test.js b/test/build/config/function/functional-config.test.js index 78ff5a88e57..034ece3a855 100644 --- a/test/build/config/function/functional-config.test.js +++ b/test/build/config/function/functional-config.test.js @@ -6,7 +6,10 @@ 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")]); + const { stderr, stdout, exitCode } = await run(__dirname, [ + "--config", + resolve(__dirname, "single-webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -15,7 +18,10 @@ describe("functional config", () => { }); 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")]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + resolve(__dirname, "multi-webpack.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/config/invalid-export/invalid-export.test.js b/test/build/config/invalid-export/invalid-export.test.js index 5f924c1e6b7..7a70a7d5fa8 100644 --- a/test/build/config/invalid-export/invalid-export.test.js +++ b/test/build/config/invalid-export/invalid-export.test.js @@ -4,10 +4,15 @@ 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")]); + 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-path/invalid-path.test.js b/test/build/config/invalid-path/invalid-path.test.js index c4a02154e1b..6b73ece3b70 100644 --- a/test/build/config/invalid-path/invalid-path.test.js +++ b/test/build/config/invalid-path/invalid-path.test.js @@ -4,10 +4,15 @@ 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")]); + 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/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 5f89f96d1eb..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 @@ -5,7 +5,12 @@ 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", resolve(__dirname, "webpack.config.js"), "--output-path", "./binary"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.config.js"), + "--output-path", + "./binary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); expect(stdout).toBeTruthy(); diff --git a/test/build/config/multiple/multiple-config.test.js b/test/build/config/multiple/multiple-config.test.js index a36b4722e83..fea09f2d6f7 100644 --- a/test/build/config/multiple/multiple-config.test.js +++ b/test/build/config/multiple/multiple-config.test.js @@ -4,7 +4,12 @@ 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"]); + 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); 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 284c7afcda9..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 @@ -5,7 +5,10 @@ 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")]); + 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/no-config-object.test.js b/test/build/config/no-config-object/no-config-object.test.js index 574af2b5eb1..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 @@ -5,7 +5,12 @@ 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"]); + 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-functions/array-functions.test.js b/test/build/config/type/array-functions/array-functions.test.js index cbafb50dfd3..23fa310800e 100644 --- a/test/build/config/type/array-functions/array-functions.test.js +++ b/test/build/config/type/array-functions/array-functions.test.js @@ -5,7 +5,10 @@ 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")]); + 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/type/array/array.test.js b/test/build/config/type/array/array.test.js index f2cfb91bb12..60e82208882 100644 --- a/test/build/config/type/array/array.test.js +++ b/test/build/config/type/array/array.test.js @@ -5,7 +5,10 @@ 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")]); + 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/type/function-array/function-array.test.js b/test/build/config/type/function-array/function-array.test.js index 8c533ad768c..92df4e46ed0 100644 --- a/test/build/config/type/function-array/function-array.test.js +++ b/test/build/config/type/function-array/function-array.test.js @@ -5,7 +5,10 @@ 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")]); + 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/type/function-async/function-async.test.js b/test/build/config/type/function-async/function-async.test.js index f9fd1ddf7ad..29e27a7e789 100644 --- a/test/build/config/type/function-async/function-async.test.js +++ b/test/build/config/type/function-async/function-async.test.js @@ -5,7 +5,10 @@ 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")]); + 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/type/function-promise/function-promise.test.js b/test/build/config/type/function-promise/function-promise.test.js index b188d5d8937..236c1edd1cc 100644 --- a/test/build/config/type/function-promise/function-promise.test.js +++ b/test/build/config/type/function-promise/function-promise.test.js @@ -5,7 +5,10 @@ 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")]); + 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/type/function-with-env/function-with-env.test.js b/test/build/config/type/function-with-env/function-with-env.test.js index 8d75bf193f3..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 @@ -33,7 +33,14 @@ describe("function configuration", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "environment=production", + "--env", + "app.title=Luffy", + "-c", + "webpack.env.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -43,7 +50,14 @@ describe("function configuration", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "file.name.is.this=Atsumu", + "--env", + "environment=production", + "-c", + "webpack.env.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -53,7 +67,14 @@ describe("function configuration", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "file=name=is=Eren", + "--env", + "environment=multipleq", + "-c", + "webpack.env.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -63,7 +84,14 @@ describe("function configuration", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "name.=Hisoka", + "--env", + "environment=dot", + "-c", + "webpack.env.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -73,7 +101,14 @@ describe("function configuration", () => { }); it("Supports dot at the end", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--env", "name.", "--env", "environment=dot", "-c", "webpack.env.config.js"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "name.", + "--env", + "environment=dot", + "-c", + "webpack.env.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -113,7 +148,14 @@ describe("function configuration", () => { }); it("is able to understand multiple env flags", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--env", "isDev", "--env", "verboseStats", "--env", "envMessage"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "isDev", + "--env", + "verboseStats", + "--env", + "envMessage", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -134,7 +176,16 @@ describe("function configuration", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--env", + "name.=foo", + "--env", + "name.=baz", + "--env", + "environment=dot", + "-c", + "webpack.env.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); 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 f68d8e12cd3..ecb9daebd6e 100644 --- a/test/build/config/type/function-with-env/webpack.config.js +++ b/test/build/config/type/function-with-env/webpack.config.js @@ -37,7 +37,11 @@ module.exports = (env) => { entry: "./a.js", mode: "development", stats: env.verboseStats ? "verbose" : "normal", - plugins: [new DefinePlugin({ envMessage: env.envMessage ? JSON.stringify("env message present") : false })], + plugins: [ + new DefinePlugin({ + envMessage: env.envMessage ? JSON.stringify("env message present") : false, + }), + ], output: { filename: "dev.js", }, diff --git a/test/build/config/type/function/function.test.js b/test/build/config/type/function/function.test.js index a6c89fbbb30..e507bddc6fb 100644 --- a/test/build/config/type/function/function.test.js +++ b/test/build/config/type/function/function.test.js @@ -5,7 +5,10 @@ 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")]); + 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/core-flags/cache-flags.test.js b/test/build/core-flags/cache-flags.test.js index 25ead7ae9df..fda2212b367 100644 --- a/test/build/core-flags/cache-flags.test.js +++ b/test/build/core-flags/cache-flags.test.js @@ -25,11 +25,19 @@ describe("cache related flags from core", () => { }); it("should set cache.type", async () => { - const cacheLocation = path.resolve(__dirname, "../../../node_modules/.cache/webpack/cache-core-flag-test-type"); + 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(); @@ -37,11 +45,21 @@ describe("cache related flags from core", () => { }); 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"); + 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", cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--cache-cache-directory", + "./test-cache-path", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -50,11 +68,19 @@ describe("cache related flags from core", () => { }); 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"); + 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(); @@ -64,11 +90,21 @@ describe("cache related flags from core", () => { }); 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"); + 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", cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--cache-hash-algorithm", + "sha256", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -77,11 +113,21 @@ describe("cache related flags from core", () => { }); it("should set cache.name with --cache-name", async () => { - const cacheLocation = path.resolve(__dirname, "../../../node_modules/.cache/webpack/cache-core-flag-test-name"); + 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", cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--cache-name", + "cli-test", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -90,11 +136,21 @@ describe("cache related flags from core", () => { }); it("should set cache.store with --cache-store", async () => { - const cacheLocation = path.resolve(__dirname, "../../../node_modules/.cache/webpack/cache-core-flag-test-store"); + 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", cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--cache-store", + "pack", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -103,11 +159,21 @@ describe("cache related flags from core", () => { }); it("should set cache.version with --cache-version", async () => { - const cacheLocation = path.resolve(__dirname, "../../../node_modules/.cache/webpack/cache-core-flag-test-version"); + 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", cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "--cache-version", + "1.1.3", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -116,11 +182,21 @@ describe("cache related flags from core", () => { }); 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"); + 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", cacheLocation]); + let { stderr, stdout, exitCode } = await run(__dirname, [ + "--cache-type", + "filesystem", + "-c", + "./webpack.config.js", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -130,7 +206,14 @@ describe("cache related flags from core", () => { 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", cacheLocation])); + ({ exitCode, stderr, stdout } = await run(__dirname, [ + "--cache-type", + "filesystem", + "-c", + "./webpack.config.js", + "--cache-cache-location", + cacheLocation, + ])); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); @@ -138,11 +221,19 @@ describe("cache related flags from core", () => { }); 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"); + const cacheLocation = path.resolve( + __dirname, + "../../../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", cacheLocation]); + let { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.cache.config.js", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -151,7 +242,12 @@ describe("cache related flags from core", () => { // 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(); @@ -161,7 +257,12 @@ describe("cache related flags from core", () => { 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(); @@ -172,9 +273,19 @@ describe("cache related flags from core", () => { }); 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"]); + 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", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -184,11 +295,22 @@ describe("cache related flags from core", () => { }); it("should assign cache build dependencies with merged configs", async () => { - const cacheLocation = path.resolve(__dirname, "../../../node_modules/.cache/webpack/cache-core-flag-test-merge"); + 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", cacheLocation]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.cache.config.js", + "-c", + "./webpack.config.js", + "--merge", + "--cache-cache-location", + cacheLocation, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -199,29 +321,54 @@ describe("cache related flags from core", () => { }); 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")); + 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"}'); - - let { exitCode, stderr, stdout } = await run(__dirname, ["--cache-type", "filesystem", "-c", "./webpack.test.config.js"]); + 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", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); 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]"); // Change config to invalidate cache - 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"])); + 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", + ])); unlinkSync(resolve(__dirname, "./webpack.test.config.js")); diff --git a/test/build/core-flags/context-flag.test.js b/test/build/core-flags/context-flag.test.js index 97953dcb3e9..38d4e7fb37b 100644 --- a/test/build/core-flags/context-flag.test.js +++ b/test/build/core-flags/context-flag.test.js @@ -19,7 +19,10 @@ describe("--context flag", () => { }); it("should throw module not found error for invalid context", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--context", "/invalid-context-path"]); + 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/entry-reset-flag.test.js b/test/build/core-flags/entry-reset-flag.test.js index 55321a78abf..b8d3c176f63 100644 --- a/test/build/core-flags/entry-reset-flag.test.js +++ b/test/build/core-flags/entry-reset-flag.test.js @@ -4,7 +4,11 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry-reset", + "--entry", + "./src/entry.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); 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 52ba8c7dbbf..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 @@ -4,7 +4,10 @@ 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/]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--ignore-warnings", + /Generated Warning/, + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -13,7 +16,11 @@ describe("ignore-warnings", () => { }); it("should reset options.ignoreWarnings", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--ignore-warnings", /Generated Warning/, "--ignore-warnings-reset"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--ignore-warnings", + /Generated Warning/, + "--ignore-warnings-reset", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/infrastructure-logging.test.js b/test/build/core-flags/infrastructure-logging.test.js index 44f1babcc22..1f63f2c75e2 100644 --- a/test/build/core-flags/infrastructure-logging.test.js +++ b/test/build/core-flags/infrastructure-logging.test.js @@ -4,7 +4,10 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--infrastructure-logging-debug", + "myPlugin", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -12,7 +15,9 @@ describe("infrastructure logging related flag", () => { }); it("should reset infrastructureLogging.debug to []", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--infrastructure-logging-debug-reset"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--infrastructure-logging-debug-reset", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -20,7 +25,10 @@ describe("infrastructure logging related flag", () => { }); it("should set infrastructureLogging.level properly", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--infrastructure-logging-level", "log"]); + 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 db983ab3bb0..34dbc286c52 100644 --- a/test/build/core-flags/invalid-flag.test.js +++ b/test/build/core-flags/invalid-flag.test.js @@ -4,7 +4,10 @@ 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"]); + 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/module-flags.test.js b/test/build/core-flags/module-flags.test.js index 0174453aec5..ae425b2386a 100644 --- a/test/build/core-flags/module-flags.test.js +++ b/test/build/core-flags/module-flags.test.js @@ -1,6 +1,11 @@ "use strict"; -const { run, hyphenToUpperCase, normalizeStdout, getWebpackCliArguments } = require("../../utils/test-utils"); +const { + run, + hyphenToUpperCase, + normalizeStdout, + getWebpackCliArguments, +} = require("../../utils/test-utils"); const moduleFlags = getWebpackCliArguments("module-"); describe("module config related flag", () => { @@ -14,7 +19,11 @@ describe("module config related flag", () => { const propName = hyphenToUpperCase(property); - if (value.configs.filter((config) => config.type === "boolean").length > 0 && !name.includes("module-no-parse") && !name.includes("module-parser-")) { + if ( + 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")) { const { stderr, stdout } = await run(__dirname, [`--${name}`]); @@ -29,11 +38,16 @@ describe("module config related flag", () => { expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain("sideEffects: 'flag'"); } else if (name.startsWith("module-generator-")) { - const { exitCode, stderr, stdout } = await run(__dirname, [`--module-generator-asset-emit`, "--module-generator-asset-resource-emit"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--module-generator-asset-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}`]); @@ -61,7 +75,10 @@ describe("module config related flag", () => { } } - if (value.configs.filter((config) => config.type === "string").length > 0 && !(name.includes("module-parser-") || name.startsWith("module-generator"))) { + if ( + 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"]); @@ -70,7 +87,10 @@ describe("module config related flag", () => { expect(stderr).toBeFalsy(); expect(normalizeStdout(stdout)).toContain("value"); } else if (name.includes("reg-exp")) { - let { stdout, stderr, exitCode } = await run(__dirname, [`--${name}`, "/ab?c*/"]); + let { stdout, stderr, exitCode } = await run(__dirname, [ + `--${name}`, + "/ab?c*/", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -81,10 +101,18 @@ describe("module config related flag", () => { expect(normalizeStdout(stdout)).toContain(`${propName}: 'javascript/auto'`); } else if (property.includes("use-")) { - let { stdout } = await run(__dirname, ["--module-rules-use-loader", "myLoader"]); + 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"]); + 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"]); @@ -102,7 +130,12 @@ describe("module config related flag", () => { } 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--module-generator-asset-data-url-encoding", + "base64", + "--module-generator-asset-data-url-mimetype", + "application/node", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -129,7 +162,10 @@ describe("module config related flag", () => { }); it("should accept --module-parser-javascript-url=relative", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--module-parser-javascript-url", "relative"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--module-parser-javascript-url", + "relative", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -137,10 +173,15 @@ describe("module config related flag", () => { }); 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"]); + 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/optimization-flags.test.js b/test/build/core-flags/optimization-flags.test.js index b2d5b34a0c4..c04e7c495d0 100644 --- a/test/build/core-flags/optimization-flags.test.js +++ b/test/build/core-flags/optimization-flags.test.js @@ -64,40 +64,62 @@ 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-")) { + if ( + 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"]); + 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"]); + 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"]); + 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"]); + 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"]); + 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(); @@ -106,7 +128,10 @@ 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"]); diff --git a/test/build/core-flags/output-flags.test.js b/test/build/core-flags/output-flags.test.js index 183f6faa30f..b4a82de718f 100644 --- a/test/build/core-flags/output-flags.test.js +++ b/test/build/core-flags/output-flags.test.js @@ -16,13 +16,19 @@ describe("output config related flag", () => { 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") { //'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(); @@ -67,28 +73,46 @@ 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"]); + 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"]); + 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"]); + 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(); @@ -100,13 +124,19 @@ describe("output config related flag", () => { expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: 'amd'`); } else if (name === "output-hash-function") { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "sha256"]); + 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "module", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -118,37 +148,55 @@ describe("output config related flag", () => { expect(stderr).toBeFalsy(); expect(stdout).toContain(`${propName}: [ 'var' ]`); } else if (name === "output-path") { - 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(); expect(stdout).toContain("test"); } else if (name === "output-pathinfo") { - const { exitCode, stderr, stdout } = await run(__dirname, [`--${name}`, "verbose"]); + 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"]); + 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"]); + 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"]); + 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(); @@ -181,7 +229,11 @@ describe("output config related flag", () => { }); it("should be succesful with --output-library-reset correctly", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--output-library-reset", "--output-library", "newLibrary"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--output-library-reset", + "--output-library", + "newLibrary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/records-flag.test.js b/test/build/core-flags/records-flag.test.js index 34a2562843f..684f4199490 100644 --- a/test/build/core-flags/records-flag.test.js +++ b/test/build/core-flags/records-flag.test.js @@ -4,7 +4,10 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--records-path", + "./bin/records.json", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -12,7 +15,10 @@ describe("module config related flag", () => { }); it("should config records-input-path correctly", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--records-input-path", "./bin/records.json"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--records-input-path", + "./bin/records.json", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -20,7 +26,10 @@ describe("module config related flag", () => { }); it("should config records-output-path correctly", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--records-output-path", "./bin/records.json"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--records-output-path", + "./bin/records.json", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/core-flags/resolve-flags.test.js b/test/build/core-flags/resolve-flags.test.js index f2f60216710..0101f1a62c4 100644 --- a/test/build/core-flags/resolve-flags.test.js +++ b/test/build/core-flags/resolve-flags.test.js @@ -14,7 +14,11 @@ describe("resolve config related flags", () => { const propName = hyphenToUpperCase(property); - if (value.configs.filter((config) => config.type === "boolean").length > 0 && !name.includes("alias-") && !name.includes("fallback-")) { + if ( + 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}`]); @@ -30,7 +34,11 @@ describe("resolve config related flags", () => { }); } - if (value.configs.filter((config) => config.type === "string").length > 0 && !name.includes("alias-") && !name.includes("fallback-")) { + if ( + 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"]); diff --git a/test/build/core-flags/snapshot-flags.test.js b/test/build/core-flags/snapshot-flags.test.js index b1e0fb8f9c9..68400f5bc59 100644 --- a/test/build/core-flags/snapshot-flags.test.js +++ b/test/build/core-flags/snapshot-flags.test.js @@ -29,7 +29,10 @@ describe("snapshot config related flags", () => { 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(); diff --git a/test/build/core-flags/stats-flags.test.js b/test/build/core-flags/stats-flags.test.js index 35ae6503163..f4f47b6277f 100644 --- a/test/build/core-flags/stats-flags.test.js +++ b/test/build/core-flags/stats-flags.test.js @@ -46,11 +46,20 @@ describe("stats config related flag", () => { } if (value.configs.filter((config) => config.type === "string").length > 0) { - const acceptsSingleValue = ["preset", "modulesSort", "logging", "chunksSort", "assetsSort"]; + 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 { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "u001b[32m", + ]); const option = name.split("stats-colors-")[1]; expect(exitCode).toBe(0); @@ -69,7 +78,10 @@ describe("stats config related flag", () => { 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + `--${name}`, + "auto", + ]); 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 e486f778e95..13095c01403 100644 --- a/test/build/core-flags/watch-flags.test.js +++ b/test/build/core-flags/watch-flags.test.js @@ -13,7 +13,10 @@ describe("watch config related flag", () => { 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}`]); @@ -57,7 +60,10 @@ describe("watch config related flag", () => { 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/custom-webpack/custom-webpack.test.js b/test/build/custom-webpack/custom-webpack.test.js index 3a1aad180d8..92c8bd922de 100644 --- a/test/build/custom-webpack/custom-webpack.test.js +++ b/test/build/custom-webpack/custom-webpack.test.js @@ -16,7 +16,9 @@ describe("custom-webpack", () => { 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/defaults/output-defaults.test.js b/test/build/defaults/output-defaults.test.js index 9821f2ccdd8..f4f2bff82b3 100644 --- a/test/build/defaults/output-defaults.test.js +++ b/test/build/defaults/output-defaults.test.js @@ -6,7 +6,12 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry", + "./a.js", + "--output-path", + "./binary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -26,7 +31,11 @@ describe("output flag defaults", () => { }); it("throw error on empty output flag", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--entry", "./a.js", "--output-path"]); + 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 8e92535083b..ee45e79dd06 100644 --- a/test/build/devtool/array/source-map-array.test.js +++ b/test/build/devtool/array/source-map-array.test.js @@ -25,7 +25,12 @@ describe("source-map object", () => { }); it("should override entire array on flag", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--devtool", "source-map", "--output-path", "./binary"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--devtool", + "source-map", + "--output-path", + "./binary", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/devtool/object/source-map-object.test.js b/test/build/devtool/object/source-map-object.test.js index 5319e16d142..77be45d52ac 100644 --- a/test/build/devtool/object/source-map-object.test.js +++ b/test/build/devtool/object/source-map-object.test.js @@ -5,7 +5,10 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.eval.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -23,7 +26,10 @@ describe("source-map object", () => { }); it("should write a sourcemap file", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.source.config.js"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./webpack.source.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -32,7 +38,11 @@ describe("source-map object", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", "./webpack.eval.config.js", "--devtool", "source-map", "-o", "./binary"], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -41,7 +51,11 @@ describe("source-map object", () => { }); it("should override config with devtool false", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.eval.config.js", "--no-devtool", "-o", "./binary"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", "./webpack.eval.config.js", "--no-devtool", "-o", "./binary"], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); 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 f1aec3de0a8..aea0411bb0f 100644 --- a/test/build/entry/flag-entry/entry-with-flag.test.js +++ b/test/build/entry/flag-entry/entry-with-flag.test.js @@ -6,7 +6,12 @@ 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/"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry", + "./src/index.cjs", + "-o", + "./dist/", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/entry/multiple-entries/multi-entries.test.js b/test/build/entry/multiple-entries/multi-entries.test.js index 5da315193ec..cbf765751ee 100644 --- a/test/build/entry/multiple-entries/multi-entries.test.js +++ b/test/build/entry/multiple-entries/multi-entries.test.js @@ -6,7 +6,12 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--entry", + "./src/a.js", + "--entry", + "./src/b.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/error/invalid-schema/invalid-schema.test.js b/test/build/error/invalid-schema/invalid-schema.test.js index b400dd1b88e..de901331213 100644 --- a/test/build/error/invalid-schema/invalid-schema.test.js +++ b/test/build/error/invalid-schema/invalid-schema.test.js @@ -3,7 +3,10 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./webpack.mock.config.js", + ]); expect(exitCode).toEqual(2); expect(stderr).toContain("Invalid configuration object"); @@ -11,7 +14,10 @@ describe("invalid schema", () => { }); it("should log error on invalid plugin options", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--config", "./webpack.plugin-mock.config.js"]); + 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"); @@ -19,7 +25,11 @@ describe("invalid schema", () => { }); 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"); @@ -27,7 +37,11 @@ describe("invalid schema", () => { }); 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"); diff --git a/test/build/hot/hot-flag.test.js b/test/build/hot/hot-flag.test.js index d462642fac3..877973de9a5 100644 --- a/test/build/hot/hot-flag.test.js +++ b/test/build/hot/hot-flag.test.js @@ -10,7 +10,9 @@ describe("--hot flag", () => { expect(exitCode).toBe(0); 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 () => { @@ -19,7 +21,9 @@ describe("--hot flag", () => { expect(exitCode).toBe(0); 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 () => { @@ -36,6 +40,8 @@ describe("--hot flag", () => { expect(exitCode).toBe(0); 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/json/json.test.js b/test/build/json/json.test.js index 818c4c84388..37294945fb6 100644 --- a/test/build/json/json.test.js +++ b/test/build/json/json.test.js @@ -39,7 +39,11 @@ describe("json", () => { }); 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 } }); + 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}`); @@ -61,7 +65,11 @@ describe("json", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--json", + "stats.json", + "--no-color", + ]); expect(exitCode).toBe(0); expect(stderr).not.toContain(`\u001b[32m${successMessage}`); @@ -102,7 +110,11 @@ describe("json", () => { }); 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"); @@ -125,7 +137,11 @@ describe("json", () => { }); it("should work and output json stats with cli logs", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--json", "--config", "logging.config.js"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--json", + "--config", + "logging.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toContain("Compiler starting..."); @@ -135,7 +151,12 @@ describe("json", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--json", + "stats.json", + "--config", + "logging.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toContain("Compiler starting..."); 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 25560251bff..78a2dc4cdae 100644 --- a/test/build/merge/config-absent/merge-config-absent.test.js +++ b/test/build/merge/config-absent/merge-config-absent.test.js @@ -7,7 +7,13 @@ const { run } = require("../../../utils/test-utils"); 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 diff --git a/test/build/merge/config/merge-config.test.js b/test/build/merge/config/merge-config.test.js index 8b155f57a1f..53653068ca3 100644 --- a/test/build/merge/config/merge-config.test.js +++ b/test/build/merge/config/merge-config.test.js @@ -4,7 +4,13 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./1.js", + "--config", + "./2.js", + "--merge", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -13,7 +19,11 @@ describe("merge flag configuration", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["--config", "./1.js", "--config", "./2.js", "--config", "./3.js", "--merge"], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -23,7 +33,13 @@ describe("merge flag configuration", () => { }); it("merges two configurations together with flag alias", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--config", "./1.js", "--config", "./2.js", "-m"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--config", + "./1.js", + "--config", + "./2.js", + "-m", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -32,7 +48,11 @@ describe("merge flag configuration", () => { }); it("fails when there are less than 2 configurations to merge", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--config", "./1.js", "--merge"]); + 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."); 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 e3a13a63b18..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 @@ -9,7 +9,9 @@ describe("mode flags", () => { 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 () => { @@ -37,7 +39,9 @@ describe("mode flags", () => { }); it("should pick mode form NODE_ENV", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { env: { NODE_ENV: "development" } }); + const { exitCode, stderr, stdout } = await run(__dirname, [], { + env: { NODE_ENV: "development" }, + }); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); 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 ba85331552b..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 @@ -4,7 +4,12 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "production", + "--config", + "./webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -13,7 +18,12 @@ describe("mode flags with config", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "development", + "--config", + "./webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -22,7 +32,12 @@ describe("mode flags with config", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "none", + "--config", + "./webpack.config.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -31,9 +46,14 @@ 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(); @@ -49,7 +69,12 @@ describe("mode flags with config", () => { }); 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"]); + const { exitCode, stdout, stderr } = await run(__dirname, [ + "-c", + "webpack.config3.js", + "-c", + "webpack.config2.js", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -58,7 +83,14 @@ describe("mode flags with config", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--mode", + "none", + "-c", + "./webpack.config3.js", + "-c", + "./webpack.config2.js", + ]); expect(exitCode).toEqual(0); expect(stderr).toBeFalsy(); @@ -67,11 +99,15 @@ describe("mode flags with config", () => { }); 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", + 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(); diff --git a/test/build/node-env/node-env.test.js b/test/build/node-env/node-env.test.js index a4ee1cd6ca9..479c1d90d7f 100644 --- a/test/build/node-env/node-env.test.js +++ b/test/build/node-env/node-env.test.js @@ -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/node.test.js b/test/build/node/node.test.js index 5bcd046794e..5689d97b95b 100644 --- a/test/build/node/node.test.js +++ b/test/build/node/node.test.js @@ -5,7 +5,10 @@ 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")}`], + nodeOptions: [ + `--require=${resolve(__dirname, "bootstrap.js")}`, + `--require=${resolve(__dirname, "bootstrap2.js")}`, + ], }); expect(exitCode).toBe(0); @@ -15,7 +18,9 @@ describe("node flags", () => { }); it("throws an error on supplying unknown flags", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [], { nodeOptions: ["--unknown"] }); + const { exitCode, stderr, stdout } = await run(__dirname, [], { + nodeOptions: ["--unknown"], + }); expect(exitCode).not.toBe(0); expect(stderr).toContain("bad option"); @@ -23,7 +28,9 @@ describe("node flags", () => { }); 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"] }); + 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"); @@ -31,10 +38,14 @@ describe("node flags", () => { }); 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"] }); + 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/output/output-named-bundles.test.js b/test/build/output/output-named-bundles.test.js index 6d20e9e875b..f872fef7790 100644 --- a/test/build/output/output-named-bundles.test.js +++ b/test/build/output/output-named-bundles.test.js @@ -5,7 +5,11 @@ const { run, normalizeStdout, normalizeStderr } = require("../../utils/test-util 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", resolve(__dirname, "webpack.config.js"), "--output-path", "./binary"], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -13,7 +17,11 @@ describe("output flag named bundles", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", resolve(__dirname, "webpack.config.js"), "--output-path", "binary"], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -21,7 +29,11 @@ describe("output flag named bundles", () => { }); 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"], false); + const { exitCode, stderr, stdout } = await run( + __dirname, + ["-c", resolve(__dirname, "webpack.single.config.js"), "--output-path", "./bin"], + false, + ); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -29,7 +41,10 @@ describe("output flag named bundles", () => { }); it("should successfully compile multiple entries", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["-c", resolve(__dirname, "webpack.multiple.config.js")]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + resolve(__dirname, "webpack.multiple.config.js"), + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); diff --git a/test/build/prefetch/prefetch.test.js b/test/build/prefetch/prefetch.test.js index f74daa1ea0a..8a9b7c91fe7 100644 --- a/test/build/prefetch/prefetch.test.js +++ b/test/build/prefetch/prefetch.test.js @@ -11,7 +11,12 @@ describe("prefetch", () => { }); it("should load the prefetched file", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--prefetch", "./src/p.js", "--mode", "development"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--prefetch", + "./src/p.js", + "--mode", + "development", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -23,7 +28,10 @@ describe("prefetch", () => { }); it("should log error when the prefetched file is absent", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--prefetch", "./src/somefile.js"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--prefetch", + "./src/somefile.js", + ]); expect(exitCode).toBe(1); expect(stderr).toBeFalsy(); diff --git a/test/build/progress/progress-flag.test.js b/test/build/progress/progress-flag.test.js index e2b0b93435e..3ddaf4003f2 100644 --- a/test/build/progress/progress-flag.test.js +++ b/test/build/progress/progress-flag.test.js @@ -29,12 +29,18 @@ describe("progress flag", () => { 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"]); + 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/); 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 9afff54980b..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 @@ -37,9 +37,13 @@ describe("start finish force log", () => { }); 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 }, - }); + 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..."); diff --git a/test/build/stats/flags/stats.test.js b/test/build/stats/flags/stats.test.js index 77489457554..5f2e652ee98 100644 --- a/test/build/stats/flags/stats.test.js +++ b/test/build/stats/flags/stats.test.js @@ -2,7 +2,15 @@ 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"); diff --git a/test/build/target/flag-test/target-flag.test.js b/test/build/target/flag-test/target-flag.test.js index 6c69f0cd0d5..71b53e3515f 100644 --- a/test/build/target/flag-test/target-flag.test.js +++ b/test/build/target/flag-test/target-flag.test.js @@ -1,7 +1,16 @@ "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"]; +const targetValues = [ + "web", + "webworker", + "node", + "async-node", + "node-webkit", + "electron-main", + "electron-renderer", + "electron-preload", +]; describe("--target flag", () => { targetValues.forEach((val) => { @@ -42,7 +51,12 @@ describe("--target flag", () => { if (isWebpack5) { it("should allow multiple targets", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--target", "node", "--target", "async-node"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target", + "node", + "--target", + "async-node", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -50,7 +64,12 @@ describe("--target flag", () => { }); it("should throw an error for invalid target in multiple syntax", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--target", "node", "--target", "invalid"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target", + "node", + "--target", + "invalid", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -58,7 +77,12 @@ describe("--target flag", () => { }); it("should throw an error for incompatible multiple targets", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--target", "node", "--target", "web"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target", + "node", + "--target", + "web", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -66,7 +90,11 @@ describe("--target flag", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--target-reset", + "--target", + "async-node", + ]); expect(exitCode).toBe(0); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); diff --git a/test/build/unknown/unknown.test.js b/test/build/unknown/unknown.test.js index f979f628032..5569953bd61 100644 --- a/test/build/unknown/unknown.test.js +++ b/test/build/unknown/unknown.test.js @@ -100,7 +100,9 @@ describe("unknown behaviour", () => { }); it("should log error and respect --color flag", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown", "--color"], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(2); expect(stderr).toMatchSnapshot("stderr"); @@ -108,7 +110,9 @@ describe("unknown behaviour", () => { }); 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 } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["--unknown", "--no-color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(2); expect(stderr).toMatchSnapshot("stderr"); @@ -124,7 +128,10 @@ describe("unknown behaviour", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--output-fileneme", + "[name].js", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -132,7 +139,9 @@ describe("unknown behaviour", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "--output-library-auxiliary-comment-commnjs", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -172,7 +181,9 @@ describe("unknown behaviour", () => { }); it("should log error if an unknown command passed", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["qqq"], true, [], { TERM_PROGRAM: false }); + const { exitCode, stderr, stdout } = await run(__dirname, ["qqq"], true, [], { + TERM_PROGRAM: false, + }); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -180,7 +191,9 @@ describe("unknown behaviour", () => { }); 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 }); + const { exitCode, stderr, stdout } = await run(__dirname, ["serverr"], true, [], { + TERM_PROGRAM: false, + }); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); 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 f82ba61c1c3..530ce490fee 100644 --- a/test/configtest/with-config-path/with-config-path.test.js +++ b/test/configtest/with-config-path/with-config-path.test.js @@ -4,7 +4,10 @@ const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-util 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "configtest", + "./basic.config.js", + ]); expect(exitCode).toBe(0); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -12,7 +15,10 @@ describe("'configtest' command with the configuration path option", () => { }); it("should throw validation error", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["configtest", "./error.config.js"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "configtest", + "./error.config.js", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -20,7 +26,10 @@ describe("'configtest' command with the configuration path option", () => { }); it("should throw syntax error", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["configtest", "./syntax-error.config.js"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "configtest", + "./syntax-error.config.js", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); diff --git a/test/help/help.test.js b/test/help/help.test.js index 62d8ff6d168..627a1ab9929 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -36,20 +36,34 @@ describe("help", () => { }); 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: exitCodeFromCommandSyntax, stderr: stderrFromCommandSyntax, stdout: stdoutFromCommandSyntax } = 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"]); 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(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(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"); @@ -58,7 +72,9 @@ describe("help", () => { }); 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"); @@ -130,7 +146,9 @@ describe("help", () => { }); 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"); @@ -139,7 +157,11 @@ describe("help", () => { }); 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"); @@ -159,7 +181,11 @@ describe("help", () => { }); 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"); @@ -241,7 +267,9 @@ describe("help", () => { }); 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"); @@ -250,7 +278,9 @@ describe("help", () => { }); 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"); @@ -258,7 +288,9 @@ describe("help", () => { }); 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"); @@ -363,7 +395,12 @@ describe("help", () => { }); it("should log error for invalid command using command syntax #4", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["help", "serve", "--mode", "--mode"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "help", + "serve", + "--mode", + "--mode", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); diff --git a/test/init/init.test.js b/test/init/init.test.js index 3d706af7a2c..ef75f160e59 100644 --- a/test/init/init.test.js +++ b/test/init/init.test.js @@ -2,7 +2,12 @@ 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 { + isWindows, + run, + runPromptWithAnswers, + uniqueDirectoryForTest, +} = require("../utils/test-utils"); jest.setTimeout(480000); @@ -70,7 +75,9 @@ describe("init command", () => { const assetsPath = path.resolve(os.tmpdir(), Date.now().toString()); 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( + "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"); @@ -89,7 +96,9 @@ describe("init command", () => { const assetsPath = path.resolve(os.tmpdir(), Date.now().toString()); 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( + "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"); @@ -109,7 +118,11 @@ describe("init command", () => { 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"); @@ -128,7 +141,11 @@ describe("init command", () => { it("should generate typescript project correctly", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["init"], [`${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["init"], + [`${DOWN}${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`], + ); expect(stdout).toContain("Project has been initialised with webpack!"); expect(stderr).toContain("webpack.config.js"); @@ -150,7 +167,11 @@ describe("init command", () => { it("should generate ES6 project correctly", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["init"], [`${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["init"], + [`${DOWN}${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${ENTER}`], + ); expect(stdout).toContain("Project has been initialised with webpack!"); expect(stderr).toContain("webpack.config.js"); @@ -172,7 +193,19 @@ describe("init command", () => { 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}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["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"); @@ -193,13 +226,31 @@ describe("init command", () => { 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}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["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"); // 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(); @@ -214,7 +265,19 @@ describe("init command", () => { 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}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["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"); @@ -235,13 +298,31 @@ describe("init command", () => { 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}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["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"); // 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(); @@ -256,7 +337,19 @@ describe("init command", () => { 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}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["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"); @@ -277,7 +370,19 @@ describe("init command", () => { 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}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["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"); @@ -298,7 +403,11 @@ describe("init command", () => { 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!"); @@ -319,13 +428,23 @@ describe("init command", () => { it("should use postcss in project when selected", async () => { const assetsPath = await uniqueDirectoryForTest(); - const { stdout, stderr } = await runPromptWithAnswers(assetsPath, ["init"], [`${ENTER}`, `n${ENTER}`, `n${ENTER}`, `${DOWN}${ENTER}`, ENTER, `n${ENTER}`]); + const { stdout, stderr } = await runPromptWithAnswers( + assetsPath, + ["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"); // 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(); @@ -340,9 +459,15 @@ describe("init command", () => { 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]); - - expect(stdout).toContain("Do you want to simplify the creation of HTML files for your bundle?"); + 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"); diff --git a/test/loader/loader.test.js b/test/loader/loader.test.js index b1ae0a02843..0656845c50a 100644 --- a/test/loader/loader.test.js +++ b/test/loader/loader.test.js @@ -2,7 +2,12 @@ const { existsSync } = require("fs"); const { join, resolve } = require("path"); -const { run, runPromptWithAnswers, uniqueDirectoryForTest, normalizeStdout } = require("../utils/test-utils"); +const { + run, + runPromptWithAnswers, + uniqueDirectoryForTest, + normalizeStdout, +} = require("../utils/test-utils"); const firstPrompt = "? Loader name (my-loader)"; const ENTER = "\x0D"; @@ -40,7 +45,14 @@ 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(); @@ -57,7 +69,11 @@ describe("loader command", () => { 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); @@ -70,7 +86,14 @@ 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(); @@ -87,7 +110,11 @@ describe("loader command", () => { 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); @@ -100,7 +127,14 @@ 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(); @@ -118,7 +152,11 @@ describe("loader command", () => { 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); @@ -131,7 +169,14 @@ 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(); @@ -155,7 +200,11 @@ describe("loader command", () => { 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); @@ -168,7 +217,14 @@ 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(); diff --git a/test/plugin/plugin.test.js b/test/plugin/plugin.test.js index f4e4e5c1125..62dcb5023ca 100644 --- a/test/plugin/plugin.test.js +++ b/test/plugin/plugin.test.js @@ -1,6 +1,11 @@ const { existsSync, mkdirSync } = require("fs"); const { join, resolve } = require("path"); -const { run, runPromptWithAnswers, uniqueDirectoryForTest, normalizeStdout } = require("../utils/test-utils"); +const { + run, + runPromptWithAnswers, + uniqueDirectoryForTest, + normalizeStdout, +} = require("../utils/test-utils"); const ENTER = "\x0D"; @@ -37,21 +42,35 @@ describe("plugin command", () => { } // 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"]); + 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 () => { 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); @@ -64,21 +83,35 @@ describe("plugin command", () => { } // 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"]); + 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 () => { 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); @@ -91,14 +124,24 @@ describe("plugin command", () => { } // 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"]); + const { stdout: stdout2 } = await run(customPluginPath, [ + "--config", + "./examples/simple/webpack.config.js", + ]); expect(normalizeStdout(stdout2)).toContain("Hello World!"); }); @@ -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); @@ -123,14 +170,24 @@ describe("plugin command", () => { } // 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"]); + const { stdout: stdout2 } = await run(customPluginPath, [ + "--config", + "./examples/simple/webpack.config.js", + ]); expect(normalizeStdout(stdout2)).toContain("Hello World!"); }); @@ -144,7 +201,11 @@ describe("plugin command", () => { 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(); @@ -153,12 +214,22 @@ describe("plugin command", () => { 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"]); + 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/serve-basic.test.js b/test/serve/basic/serve-basic.test.js index 6defecccd50..d714dc0db8e 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -3,7 +3,13 @@ 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 { + runWatch, + isWebpack5, + normalizeStderr, + normalizeStdout, + isDevServer4, +} = require("../../utils/test-utils"); const testPath = path.resolve(__dirname); @@ -29,7 +35,13 @@ describe("basic serve usage", () => { }); 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"); @@ -43,7 +55,15 @@ describe("basic serve usage", () => { }); 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", port]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "function-with-env.config.js", + "--env", + "foo=bar", + "--port", + port, + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -59,7 +79,16 @@ describe("basic serve usage", () => { }); 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", port]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "function-with-argv.config.js", + "--env", + "foo=bar", + "--hot", + "--port", + port, + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -76,7 +105,13 @@ describe("basic serve usage", () => { }); it("should work in multi compiler mode", async () => { - const { stderr, stdout } = await runWatch(__dirname, ["serve", "--config", "multi.config.js", "--port", port]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "multi.config.js", + "--port", + port, + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -94,7 +129,11 @@ describe("basic serve usage", () => { // 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"]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "multi-dev-server.config.js", + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -150,7 +189,9 @@ describe("basic serve usage", () => { expect(stdout).not.toContain("HotModuleReplacementPlugin"); } - expect(stdout).toContain(isWebpack5 ? "from webpack.Compiler" : "webpack.buildChunkGraph.visitModules"); + expect(stdout).toContain( + isWebpack5 ? "from webpack.Compiler" : "webpack.buildChunkGraph.visitModules", + ); expect(stdout).toContain("main.js"); }); @@ -213,7 +254,11 @@ describe("basic serve usage", () => { }); 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"); @@ -263,7 +308,12 @@ describe("basic serve usage", () => { }); 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"); @@ -279,7 +329,13 @@ describe("basic serve usage", () => { }); 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"); @@ -302,7 +358,11 @@ describe("basic serve usage", () => { // 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"); @@ -321,7 +381,11 @@ describe("basic serve usage", () => { }); 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"); @@ -336,7 +400,13 @@ describe("basic serve usage", () => { }); 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"); @@ -354,7 +424,11 @@ describe("basic serve usage", () => { }); 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"); @@ -376,7 +450,9 @@ describe("basic serve usage", () => { if (/wait until bundle finished/.test(normalizedStderr)) { 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); @@ -396,7 +472,13 @@ describe("basic serve usage", () => { }); 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", port]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "multi-dev-server-output-public-path.config.js", + "--port", + port, + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -413,7 +495,12 @@ describe("basic serve usage", () => { }); it("should work with entries syntax", async () => { - const { stderr, stdout } = await runWatch(__dirname, ["serve", "./src/entry.js", "--port", port]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "./src/entry.js", + "--port", + port, + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -427,7 +514,13 @@ describe("basic serve usage", () => { }); 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]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "./watch.config.js", + "--port", + port, + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -449,9 +542,13 @@ describe("basic serve usage", () => { }); 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\.\.\./, - }); + 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(stdout).toBeTruthy(); @@ -474,7 +571,12 @@ describe("basic serve usage", () => { }); it("should log an error on unknown flag", async () => { - const { exitCode, stdout, stderr } = await runWatch(testPath, ["serve", "--port", port, "--unknown-flag"]); + const { exitCode, stdout, stderr } = await runWatch(testPath, [ + "serve", + "--port", + port, + "--unknown-flag", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -482,9 +584,13 @@ describe("basic serve usage", () => { }); 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, - }); + 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"); @@ -492,7 +598,11 @@ describe("basic serve usage", () => { }); it("should throw error when same ports in multicompiler", async () => { - const { stderr, stdout } = await runWatch(__dirname, ["serve", "--config", "same-ports-dev-serever.config.js"]); + const { stderr, stdout } = await runWatch(__dirname, [ + "serve", + "--config", + "same-ports-dev-serever.config.js", + ]); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); diff --git a/test/serve/invalid-schema/invalid-schema.test.js b/test/serve/invalid-schema/invalid-schema.test.js index 073a4831b00..81aede987c5 100644 --- a/test/serve/invalid-schema/invalid-schema.test.js +++ b/test/serve/invalid-schema/invalid-schema.test.js @@ -3,7 +3,11 @@ const { run, normalizeStderr, normalizeStdout } = require("../../utils/test-util 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "serve", + "--config", + "./webpack.config.mock.js", + ]); expect(exitCode).toEqual(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -28,7 +32,11 @@ describe("invalid schema", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "serve", + "--config", + "./webpack-dev-server.config.mock.js", + ]); expect(exitCode).toEqual(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js index 066fee5e757..ed707c23691 100644 --- a/test/utils/test-utils.js +++ b/test/utils/test-utils.js @@ -233,15 +233,22 @@ 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"); + 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", + ); }; 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) => { @@ -276,13 +283,19 @@ 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, ":/"); @@ -291,10 +304,16 @@ const normalizeStderr = (stderr) => { // Github Actions doesnt' support IPv6 on ubuntu in some cases 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://[]:/"); + normalizedStderr.splice( + ipv4MessageIndex + 1, + 0, + " [webpack-dev-server] On Your Network (IPv6): http://[]:/", + ); } normalizedStderr = normalizedStderr.join("\n"); diff --git a/test/utils/test-utils.test.js b/test/utils/test-utils.test.js index fa698db8354..efe183b6a78 100644 --- a/test/utils/test-utils.test.js +++ b/test/utils/test-utils.test.js @@ -1,6 +1,11 @@ "use strict"; -const { run, runAndGetProcess, hyphenToUpperCase, uniqueDirectoryForTest } = require("./test-utils"); +const { + run, + runAndGetProcess, + hyphenToUpperCase, + uniqueDirectoryForTest, +} = require("./test-utils"); const ENTER = "\x0D"; @@ -51,7 +56,11 @@ describe("runAndGetWatchProc function", () => { }); it("executes cli with passed commands and params", async () => { - const { stdout, stderr, command } = await runAndGetProcess(__dirname, ["info", "--output", "markdown"]); + const { stdout, stderr, command } = await runAndGetProcess(__dirname, [ + "info", + "--output", + "markdown", + ]); // execution command contains info command expect(command).toContain("info"); @@ -66,7 +75,11 @@ describe("runAndGetWatchProc function", () => { 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!"); }); diff --git a/test/version/version.test.js b/test/version/version.test.js index 5464ff44d11..5d1416c7e4b 100644 --- a/test/version/version.test.js +++ b/test/version/version.test.js @@ -212,7 +212,9 @@ describe("single version flag", () => { }); it("outputs versions with --color using option syntax", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "--color"], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "--color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -220,7 +222,9 @@ describe("single version flag", () => { }); it("outputs versions with --no-color using option syntax", async () => { - const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "--no-color"], { env: { FORCE_COLOR: true } }); + const { exitCode, stderr, stdout } = await run(__dirname, ["--version", "--no-color"], { + env: { FORCE_COLOR: true }, + }); expect(exitCode).toBe(0); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); @@ -324,7 +328,12 @@ describe("single version flag", () => { }); 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "version", + "info", + "serve", + "--unknown", + ]); expect(exitCode).toBe(2); expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); diff --git a/test/watch/analyze/analyze.config.js b/test/watch/analyze/analyze.config.js index 8ea874869d9..a1671a29911 100644 --- a/test/watch/analyze/analyze.config.js +++ b/test/watch/analyze/analyze.config.js @@ -3,5 +3,10 @@ const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); module.exports = { mode: "development", - plugins: [new BundleAnalyzerPlugin({ analyzerMode: "static", openAnalyzer: false })], + plugins: [ + new BundleAnalyzerPlugin({ + analyzerMode: "static", + openAnalyzer: false, + }), + ], }; diff --git a/test/watch/bail/bail.test.js b/test/watch/bail/bail.test.js index fac087b43a6..ba351e6c71d 100644 --- a/test/watch/bail/bail.test.js +++ b/test/watch/bail/bail.test.js @@ -11,37 +11,58 @@ describe('"bail" option', () => { }); 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"]); + 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"]); + 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"]); - 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/basic/basic.test.js b/test/watch/basic/basic.test.js index 732db6a93aa..a414b432f40 100644 --- a/test/watch/basic/basic.test.js +++ b/test/watch/basic/basic.test.js @@ -9,7 +9,11 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "-c", + "./watch.config.js", + "--no-watch", + ]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -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; @@ -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; @@ -83,7 +93,12 @@ 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"]); + const proc = runAndGetProcess(__dirname, [ + "watch", + "./src/entry.js", + "--mode", + "development", + ]); let modified = false; @@ -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; @@ -118,7 +136,13 @@ 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"]); + const proc = runAndGetProcess(__dirname, [ + "--watch", + "--mode", + "development", + "--config", + "./watch.config.js", + ]); let modified = false; @@ -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; @@ -152,7 +179,9 @@ describe("basic", () => { proc.stderr.on("data", (chunk) => { const data = chunk.toString(); - expect(data).toContain("No need to use the 'watch' command together with '{ watch: true }' configuration, it does not make sense."); + expect(data).toContain( + "No need to use the 'watch' command together with '{ watch: true }' configuration, it does not make sense.", + ); }); }); @@ -179,7 +208,12 @@ 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"]); + const { exitCode, stderr, stdout } = await run(__dirname, [ + "watch", + "--watch", + "--mode", + "development", + ]); expect(exitCode).toBe(2); expect(stderr).toContain("Error: Unknown option '--watch'"); @@ -188,7 +222,12 @@ describe("basic", () => { }); 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"]); + 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/stats/multi-webpack.config.js b/test/watch/stats/multi-webpack.config.js index 80af49b6de3..ac39ad32ead 100644 --- a/test/watch/stats/multi-webpack.config.js +++ b/test/watch/stats/multi-webpack.config.js @@ -9,9 +9,12 @@ module.exports = [ 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}`); + }, + ); }, }, ], @@ -24,9 +27,12 @@ module.exports = [ 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 d53f25dd300..b2c3beee283 100644 --- a/test/watch/stats/stats-and-watch.test.js +++ b/test/watch/stats/stats-and-watch.test.js @@ -18,7 +18,12 @@ describe("stats and watch", () => { }); 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 d47bf6c655e..c8bf98e63b8 100644 --- a/test/watch/stats/webpack.config.js +++ b/test/watch/stats/webpack.config.js @@ -7,9 +7,12 @@ module.exports = { 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/watch-variable/watch-variable.test.js b/test/watch/watch-variable/watch-variable.test.js index 9bb90ecc9a1..dc79871fdcc 100644 --- a/test/watch/watch-variable/watch-variable.test.js +++ b/test/watch/watch-variable/watch-variable.test.js @@ -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; @@ -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; From d00c010850073c14093b236f5fef417e3e251814 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 15 May 2021 18:57:36 +0530 Subject: [PATCH 3/3] fix: eslint --- .eslintrc.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4b037f778f9..8a997fa48f2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -44,7 +44,6 @@ module.exports = { plugins: ["@typescript-eslint"], rules: { "node/no-unsupported-features/es-syntax": "off", - "max-len": [0, 100], }, }, ],