From d11298a55564b7f860137547aa5303943d36c14b Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Sat, 20 Mar 2021 09:32:12 +0900 Subject: [PATCH 1/2] test(e2e): fix DevServer test (#3096) * refactor(test): extract ExitOnDonePlugin to helpers * test(e2e): add ExitOnDonePlugin to dev-server fixtures * test(e2e): set config paths * test(e2e): show orphaned modules in empty entry test * refactor: remove debug code --- test/e2e/DevServer.test.js | 28 ++++++++----------- test/fixtures/cli/webpack.config.js | 16 ++--------- .../dev-server/client-custom-path-config.js | 2 ++ .../dev-server/client-default-path-config.js | 2 ++ test/fixtures/dev-server/default-config.js | 2 ++ test/fixtures/dev-server/empty-entry.js | 5 +++- test/fixtures/dev-server/multi-entry.js | 2 ++ test/fixtures/dev-server/target-config.js | 2 ++ .../entry-as-descriptor/webpack.config.js | 16 ++--------- test/helpers/ExitOnDonePlugin.js | 13 +++++++++ 10 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 test/helpers/ExitOnDonePlugin.js diff --git a/test/e2e/DevServer.test.js b/test/e2e/DevServer.test.js index e87f5884d5..baaa60173e 100644 --- a/test/e2e/DevServer.test.js +++ b/test/e2e/DevServer.test.js @@ -7,7 +7,7 @@ describe('DevServer', () => { const webpack5Test = isWebpack5 ? it : it.skip; it('should add devServer entry points to a single entry point', (done) => { - testBin('--config ./test/fixtures/dev-server/default-config.js') + testBin(null, './test/fixtures/dev-server/default-config.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).toContain('client/default/index.js?'); @@ -19,9 +19,7 @@ describe('DevServer', () => { webpack5Test( 'should add devServer entry points to a multi entry point object', (done) => { - testBin( - '--config ./test/fixtures/dev-server/multi-entry.js --stats=verbose' - ) + testBin('--stats=verbose', './test/fixtures/dev-server/multi-entry.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).toContain('client/default/index.js?'); @@ -35,7 +33,7 @@ describe('DevServer', () => { webpack5Test( 'should add devServer entry points to an empty entry object', (done) => { - testBin('--config ./test/fixtures/dev-server/empty-entry.js') + testBin(null, './test/fixtures/dev-server/empty-entry.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).toContain('client/default/index.js?'); @@ -47,7 +45,8 @@ describe('DevServer', () => { webpack5Test('should supports entry as descriptor', (done) => { testBin( - '--config ./test/fixtures/entry-as-descriptor/webpack.config --stats detailed' + '--stats detailed', + './test/fixtures/entry-as-descriptor/webpack.config' ) .then((output) => { expect(output.exitCode).toEqual(0); @@ -58,9 +57,7 @@ describe('DevServer', () => { }); it('should only prepends devServer entry points to "web" target', (done) => { - testBin( - '--config ./test/fixtures/dev-server/default-config.js --target web' - ) + testBin('--target web', './test/fixtures/dev-server/default-config.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).toContain('client/default/index.js?'); @@ -71,9 +68,7 @@ describe('DevServer', () => { }); it('should not prepend devServer entry points to "node" target', (done) => { - testBin( - '--config ./test/fixtures/dev-server/default-config.js --target node' - ) + testBin('--target node', './test/fixtures/dev-server/default-config.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).not.toContain('client/default/index.js?'); @@ -85,7 +80,8 @@ describe('DevServer', () => { it('should prepends the hot runtime to "node" target as well', (done) => { testBin( - '--config ./test/fixtures/dev-server/default-config.js --target node --hot' + '--target node --hot', + './test/fixtures/dev-server/default-config.js' ) .then((output) => { expect(output.exitCode).toEqual(0); @@ -96,7 +92,7 @@ describe('DevServer', () => { }); it('does not use client.path when default', (done) => { - testBin('--config ./test/fixtures/dev-server/client-default-path-config.js') + testBin(null, './test/fixtures/dev-server/client-default-path-config.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).not.toContain('&path=/ws'); @@ -106,7 +102,7 @@ describe('DevServer', () => { }); it('should use client.path when custom', (done) => { - testBin('--config ./test/fixtures/dev-server/client-custom-path-config.js') + testBin(null, './test/fixtures/dev-server/client-custom-path-config.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).toContain('&path=/custom/path'); @@ -118,7 +114,7 @@ describe('DevServer', () => { webpack5Test( 'should prepend devServer entry points depending on targetProperties', (done) => { - testBin('--config ./test/fixtures/dev-server/target-config.js') + testBin(null, './test/fixtures/dev-server/target-config.js') .then((output) => { expect(output.exitCode).toEqual(0); expect(output.stdout).toContain('client/default/index.js'); diff --git a/test/fixtures/cli/webpack.config.js b/test/fixtures/cli/webpack.config.js index 0d36c0dafa..46ad3c051a 100644 --- a/test/fixtures/cli/webpack.config.js +++ b/test/fixtures/cli/webpack.config.js @@ -1,21 +1,11 @@ 'use strict'; +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); + module.exports = { mode: 'development', stats: 'detailed', context: __dirname, entry: './foo.js', - plugins: [ - { - apply(compiler) { - compiler.hooks.done.tap('webpack-dev-server', (stats) => { - let exitCode = 0; - if (stats.hasErrors()) { - exitCode = 1; - } - setTimeout(() => process.exit(exitCode)); - }); - }, - }, - ], + plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/client-custom-path-config.js b/test/fixtures/dev-server/client-custom-path-config.js index 300ef62d86..eb00682d20 100644 --- a/test/fixtures/dev-server/client-custom-path-config.js +++ b/test/fixtures/dev-server/client-custom-path-config.js @@ -1,6 +1,7 @@ 'use strict'; const { resolve } = require('path'); +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); module.exports = { mode: 'development', @@ -15,4 +16,5 @@ module.exports = { client: 'sockjs', }, }, + plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/client-default-path-config.js b/test/fixtures/dev-server/client-default-path-config.js index d36d7aff85..e2f7dda837 100644 --- a/test/fixtures/dev-server/client-default-path-config.js +++ b/test/fixtures/dev-server/client-default-path-config.js @@ -1,6 +1,7 @@ 'use strict'; const { resolve } = require('path'); +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); module.exports = { mode: 'development', @@ -15,4 +16,5 @@ module.exports = { client: 'sockjs', }, }, + plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/default-config.js b/test/fixtures/dev-server/default-config.js index 300ef62d86..eb00682d20 100644 --- a/test/fixtures/dev-server/default-config.js +++ b/test/fixtures/dev-server/default-config.js @@ -1,6 +1,7 @@ 'use strict'; const { resolve } = require('path'); +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); module.exports = { mode: 'development', @@ -15,4 +16,5 @@ module.exports = { client: 'sockjs', }, }, + plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/empty-entry.js b/test/fixtures/dev-server/empty-entry.js index b700d59507..0f5cd8c513 100644 --- a/test/fixtures/dev-server/empty-entry.js +++ b/test/fixtures/dev-server/empty-entry.js @@ -1,8 +1,10 @@ 'use strict'; +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); + module.exports = { mode: 'development', - stats: 'detailed', + stats: { orphanModules: true, preset: 'detailed' }, entry: {}, devServer: { transportMode: { @@ -10,4 +12,5 @@ module.exports = { client: 'sockjs', }, }, + plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/multi-entry.js b/test/fixtures/dev-server/multi-entry.js index 20b7e08c16..afa26f52da 100644 --- a/test/fixtures/dev-server/multi-entry.js +++ b/test/fixtures/dev-server/multi-entry.js @@ -1,6 +1,7 @@ 'use strict'; const { resolve } = require('path'); +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); module.exports = { mode: 'development', @@ -16,4 +17,5 @@ module.exports = { client: 'sockjs', }, }, + plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/target-config.js b/test/fixtures/dev-server/target-config.js index 8f1567286a..f97416aeb8 100644 --- a/test/fixtures/dev-server/target-config.js +++ b/test/fixtures/dev-server/target-config.js @@ -1,6 +1,7 @@ 'use strict'; const { resolve } = require('path'); +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); module.exports = { mode: 'development', @@ -21,4 +22,5 @@ module.exports = { client: 'sockjs', }, }, + plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/entry-as-descriptor/webpack.config.js b/test/fixtures/entry-as-descriptor/webpack.config.js index a9668f24d9..5429420f9e 100644 --- a/test/fixtures/entry-as-descriptor/webpack.config.js +++ b/test/fixtures/entry-as-descriptor/webpack.config.js @@ -1,5 +1,7 @@ 'use strict'; +const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); + module.exports = { mode: 'development', context: __dirname, @@ -8,19 +10,7 @@ module.exports = { import: './foo.js', }, }, - plugins: [ - { - apply(compiler) { - compiler.hooks.done.tap('webpack-dev-server', (stats) => { - let exitCode = 0; - if (stats.hasErrors()) { - exitCode = 1; - } - setTimeout(() => process.exit(exitCode)); - }); - }, - }, - ], + plugins: [ExitOnDonePlugin], infrastructureLogging: { level: 'warn', }, diff --git a/test/helpers/ExitOnDonePlugin.js b/test/helpers/ExitOnDonePlugin.js new file mode 100644 index 0000000000..a49d67ec08 --- /dev/null +++ b/test/helpers/ExitOnDonePlugin.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = { + apply(compiler) { + compiler.hooks.done.tap('webpack-dev-server', (stats) => { + let exitCode = 0; + if (stats.hasErrors()) { + exitCode = 1; + } + setTimeout(() => process.exit(exitCode)); + }); + }, +}; From 24961104e9faba7efb5ed1a2a51d4c7e0ec7a872 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 22 Mar 2021 15:09:26 +0300 Subject: [PATCH 2/2] chore(deps): update dependency webpack to ^5.27.1 (#3095) Co-authored-by: Renovate Bot --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 944fa4cd0f..8f57f297d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -81,7 +81,7 @@ "tcp-port-used": "^1.0.2", "typescript": "^4.2.3", "url-loader": "^4.1.1", - "webpack": "^5.26.2", + "webpack": "^5.27.1", "webpack-cli": "^4.5.0", "webpack-merge": "^5.7.3" }, @@ -17863,9 +17863,9 @@ } }, "node_modules/webpack": { - "version": "5.26.2", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.26.2.tgz", - "integrity": "sha512-h07tAPeQceEO3Idrevqv4ECcpMH8Zp0aUUJ+IytujWTVf6TF5PI3rKVw0Z+7rNjU4qJuEx18BykFxgRvR9VgEQ==", + "version": "5.27.1", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.27.1.tgz", + "integrity": "sha512-rxIDsPZ3Apl3JcqiemiLmWH+hAq04YeOXqvCxNZOnTp8ZgM9NEPtbu4CaMfMEf9KShnx/Ym8uLGmM6P4XnwCoA==", "dependencies": { "@types/eslint-scope": "^3.7.0", "@types/estree": "^0.0.46", @@ -32179,9 +32179,9 @@ "dev": true }, "webpack": { - "version": "5.26.2", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.26.2.tgz", - "integrity": "sha512-h07tAPeQceEO3Idrevqv4ECcpMH8Zp0aUUJ+IytujWTVf6TF5PI3rKVw0Z+7rNjU4qJuEx18BykFxgRvR9VgEQ==", + "version": "5.27.1", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.27.1.tgz", + "integrity": "sha512-rxIDsPZ3Apl3JcqiemiLmWH+hAq04YeOXqvCxNZOnTp8ZgM9NEPtbu4CaMfMEf9KShnx/Ym8uLGmM6P4XnwCoA==", "requires": { "@types/eslint-scope": "^3.7.0", "@types/estree": "^0.0.46", diff --git a/package.json b/package.json index c781c27326..2682a4f80d 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "tcp-port-used": "^1.0.2", "typescript": "^4.2.3", "url-loader": "^4.1.1", - "webpack": "^5.26.2", + "webpack": "^5.27.1", "webpack-cli": "^4.5.0", "webpack-merge": "^5.7.3" },