diff --git a/package.json b/package.json index 0e8fe6de227..7f23b513f8d 100644 --- a/package.json +++ b/package.json @@ -131,10 +131,10 @@ ], "scripts": { "setup": "node ./setup/setup.js", - "test": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest", + "test": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage", "test:update-snapshots": "yarn jest -u", - "test:integration": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.test.js\"", - "test:basic": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\"", + "test:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.test.js\"", + "test:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\"", "test:unit": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.unittest.js\"", "travis:integration": "yarn cover:integration --ci $JEST", "travis:basic": "yarn cover:basic --ci $JEST", @@ -165,9 +165,9 @@ "benchmark": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", "cover": "yarn cover:all && yarn cover:report", "cover:clean": "rimraf .nyc_output coverage", - "cover:all": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --coverage", - "cover:basic": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --testMatch \"/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\" --coverage", - "cover:integration": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --testMatch \"/test/*.test.js\" --coverage", + "cover:all": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --coverage", + "cover:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\" --coverage", + "cover:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.test.js\" --coverage", "cover:unit": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --testMatch \"/test/*.unittest.js\" --coverage", "cover:types": "node node_modules/tooling/type-coverage", "cover:merge": "nyc merge .nyc_output coverage/coverage-nyc.json && rimraf .nyc_output", diff --git a/test/ConfigTestCases.template.js b/test/ConfigTestCases.template.js index c93656ac83e..bdd8eca4d67 100644 --- a/test/ConfigTestCases.template.js +++ b/test/ConfigTestCases.template.js @@ -128,6 +128,12 @@ const describeCases = config => { } if (testConfig.timeout) setDefaultTimeout(testConfig.timeout); }); + afterAll(() => { + // cleanup + options = undefined; + optionsArr = undefined; + testConfig = undefined; + }); beforeAll(() => { rimraf.sync(cacheDirectory); }); @@ -306,6 +312,11 @@ const describeCases = config => { esmMode, parentModule ) => { + if (testConfig === undefined) { + throw new Error( + `_require(${module}) called after all tests have completed` + ); + } if (Array.isArray(module) || /^\.\.?\//.test(module)) { let content; let p; diff --git a/test/TestCases.template.js b/test/TestCases.template.js index 03d0d5718a3..cfe9ee9cd13 100644 --- a/test/TestCases.template.js +++ b/test/TestCases.template.js @@ -11,8 +11,6 @@ const deprecationTracking = require("./helpers/deprecationTracking"); const captureStdio = require("./helpers/captureStdio"); const asModule = require("./helpers/asModule"); -const webpack = require(".."); - const casesPath = path.join(__dirname, "cases"); let categories = fs.readdirSync(casesPath); categories = categories.map(cat => { @@ -79,7 +77,7 @@ const describeCases = config => { const terserForTesting = new TerserPlugin({ parallel: false }); - const options = { + let options = { context: casesPath, entry: "./" + category.name + "/" + testName + "/", target: config.target || "async-node", @@ -191,6 +189,8 @@ const describeCases = config => { }; const cleanups = []; afterAll(() => { + options = undefined; + testConfig = undefined; for (const fn of cleanups) fn(); }); beforeAll(done => { @@ -206,6 +206,7 @@ const describeCases = config => { "cache1" ); const deprecationTracker = deprecationTracking.start(); + const webpack = require(".."); webpack(options, err => { deprecationTracker(); options.output.path = oldPath; @@ -224,6 +225,7 @@ const describeCases = config => { "cache2" ); const deprecationTracker = deprecationTracking.start(); + const webpack = require(".."); webpack(options, err => { deprecationTracker(); options.output.path = oldPath; @@ -237,6 +239,7 @@ const describeCases = config => { it( testName + " should compile", done => { + const webpack = require(".."); const compiler = webpack(options); const run = () => { const deprecationTracker = deprecationTracking.start(); diff --git a/test/configCases/asset-emitted/normal/index.js b/test/configCases/asset-emitted/normal/index.js index c5d0cd4199f..9e1b6b1cd1b 100644 --- a/test/configCases/asset-emitted/normal/index.js +++ b/test/configCases/asset-emitted/normal/index.js @@ -1,3 +1 @@ -import("./module"); - -it("should run", () => {}); +it("should run", () => import("./module")); diff --git a/test/configCases/async-commons-chunk/existing-name/index.js b/test/configCases/async-commons-chunk/existing-name/index.js index b05f483e755..b953c1a09b4 100644 --- a/test/configCases/async-commons-chunk/existing-name/index.js +++ b/test/configCases/async-commons-chunk/existing-name/index.js @@ -1,11 +1,17 @@ const chunkLoadingSpy = jest.spyOn(__webpack_require__, "e"); -it("should not have duplicate chunks in blocks", function(done) { +it("should not have duplicate chunks in blocks", function (done) { + let i = 0; + const d = () => { + if (i++ >= 3) done(); + }; + // This split point should contain: a require.ensure( [], - function(require) { + function (require) { expect(require("./a")).toBe("a"); + d(); }, "a" ); @@ -14,9 +20,10 @@ it("should not have duplicate chunks in blocks", function(done) { // have it only contain b and make chunk a be an async dependency. require.ensure( [], - function(require) { + function (require) { expect(require("./a")).toBe("a"); expect(require("./b")).toBe("b"); + d(); }, "a+b" ); @@ -25,10 +32,11 @@ it("should not have duplicate chunks in blocks", function(done) { // have it only contain c and make chunks a and a+b be async dependencies. require.ensure( [], - function(require) { + function (require) { expect(require("./a")).toBe("a"); expect(require("./b")).toBe("b"); expect(require("./c")).toBe("c"); + d(); }, "a+b+c" ); @@ -46,5 +54,5 @@ it("should not have duplicate chunks in blocks", function(done) { ["a+b" /* == b */], ["a+b+c" /* == c */] ]); - done(); + d(); }); diff --git a/test/configCases/chunk-index/order-multiple-entries/entry1.js b/test/configCases/chunk-index/order-multiple-entries/entry1.js index 32a5fa8c867..ff832a0bcad 100644 --- a/test/configCases/chunk-index/order-multiple-entries/entry1.js +++ b/test/configCases/chunk-index/order-multiple-entries/entry1.js @@ -1,6 +1,4 @@ import "./a"; -import(/* webpackChunkName: "async" */ "./async"); +it("should compile", () => import(/* webpackChunkName: "async" */ "./async")); import "./b"; import "./c"; - -it("should compile", () => {}); diff --git a/test/configCases/chunk-index/order-multiple-entries/entry2.js b/test/configCases/chunk-index/order-multiple-entries/entry2.js index aa9ec2317ed..92f9311d3d5 100644 --- a/test/configCases/chunk-index/order-multiple-entries/entry2.js +++ b/test/configCases/chunk-index/order-multiple-entries/entry2.js @@ -1,6 +1,4 @@ import "./c"; -import(/* webpackChunkName: "async" */ "./async"); +it("should compile", () => import(/* webpackChunkName: "async" */ "./async")); import "./b"; import "./a"; - -it("should compile", () => {}); diff --git a/test/configCases/entry/issue-12562/app.js b/test/configCases/entry/issue-12562/app.js index 6d8bc6abb95..03392144212 100644 --- a/test/configCases/entry/issue-12562/app.js +++ b/test/configCases/entry/issue-12562/app.js @@ -1 +1 @@ -import("./test.js"); +it("should load", () => import("./test.js")); diff --git a/test/configCases/parsing/requirejs/index.js b/test/configCases/parsing/requirejs/index.js index b032e27d81e..6d38fad8e66 100644 --- a/test/configCases/parsing/requirejs/index.js +++ b/test/configCases/parsing/requirejs/index.js @@ -9,12 +9,12 @@ it("should ignore require.config", function() { it("should have a require.version", function() { expect(require.version).toBeTypeOf("string"); }); -it("should have a requirejs.onError function", function() { +it("should have a requirejs.onError function", function(done) { function f(){} expect(requirejs.onError).toBeTypeOf("undefined"); // has no default handler var org = requirejs.onError; requirejs.onError = f; expect(requirejs.onError).toBe(f); requirejs.onError = org; - require(["./file.js"], function() {}); + require(["./file.js"], function() { done() }); }); diff --git a/test/configCases/source-map/module-names/index.js b/test/configCases/source-map/module-names/index.js index 49134e0227e..9bce8ae0465 100644 --- a/test/configCases/source-map/module-names/index.js +++ b/test/configCases/source-map/module-names/index.js @@ -5,21 +5,27 @@ function getSourceMap(filename) { return map; } -it("should include test.js in SourceMap", function() { +it("should include test.js in SourceMap", function () { var allSources = new Set(); var map = getSourceMap("bundle0.js"); - for(var source of map.sources) allSources.add(source); + for (var source of map.sources) allSources.add(source); map = getSourceMap("chunk-a.js"); - for(var source of map.sources) allSources.add(source); + for (var source of map.sources) allSources.add(source); map = getSourceMap("chunk-b.js"); - for(var source of map.sources) allSources.add(source); + for (var source of map.sources) allSources.add(source); expect(allSources).toContain("module"); allSources.delete("module"); expect(allSources).toContain("fallback"); - for(const source of allSources) { + for (const source of allSources) { expect(source).toMatch(/^fallback\**$/); } }); -require.ensure(["./test.js"], function(require) {}, "chunk-a"); -require.ensure(["./test.js", "./test.js?1"], function(require) {}, "chunk-b"); +if (Math.random() < 0) { + require.ensure(["./test.js"], function (require) {}, "chunk-a"); + require.ensure( + ["./test.js", "./test.js?1"], + function (require) {}, + "chunk-b" + ); +} diff --git a/test/configCases/split-chunks/chunk-filename-delimiter-default/index.js b/test/configCases/split-chunks/chunk-filename-delimiter-default/index.js index 4bb3b122e5d..653a17d44d5 100644 --- a/test/configCases/split-chunks/chunk-filename-delimiter-default/index.js +++ b/test/configCases/split-chunks/chunk-filename-delimiter-default/index.js @@ -1,10 +1,10 @@ it("should run", function () { - Promise.all([ - import(/* webpackChunkName: "a" */ "./a"), - import(/* webpackChunkName: "b" */ "./b") - ]); - const files = require("fs").readdirSync(__dirname); expect(files).toContain("a.bundle.js"); expect(files).toContain("b-b_js-c441f481.bundle.js"); + + return Promise.all([ + import(/* webpackChunkName: "a" */ "./a"), + import(/* webpackChunkName: "b" */ "./b") + ]); }); diff --git a/test/configCases/split-chunks/chunk-filename-delimiter/index.js b/test/configCases/split-chunks/chunk-filename-delimiter/index.js index 141e9df534f..524184c6340 100644 --- a/test/configCases/split-chunks/chunk-filename-delimiter/index.js +++ b/test/configCases/split-chunks/chunk-filename-delimiter/index.js @@ -1,10 +1,10 @@ it("should run", function () { - Promise.all([ - import(/* webpackChunkName: "a" */ "./a"), - import(/* webpackChunkName: "b" */ "./b") - ]); - const files = require("fs").readdirSync(__dirname); expect(files).toContain("a.bundle.js"); expect(files).toContain("b---b_js---c441f481.bundle.js"); + + return Promise.all([ + import(/* webpackChunkName: "a" */ "./a"), + import(/* webpackChunkName: "b" */ "./b") + ]); }); diff --git a/test/configCases/split-chunks/issue-11337/index.js b/test/configCases/split-chunks/issue-11337/index.js index 9dfd14f1dc1..38fdc8a741c 100644 --- a/test/configCases/split-chunks/issue-11337/index.js +++ b/test/configCases/split-chunks/issue-11337/index.js @@ -1,4 +1,2 @@ -it("should compile and evaluate fine", () => {}); - -import("./a"); -import("./b"); +it("should compile and evaluate fine", () => + Promise.all([import("./a"), import("./b")])); diff --git a/test/configCases/split-chunks/issue-11513/index.js b/test/configCases/split-chunks/issue-11513/index.js index b74ae1b44c7..1988e1d16a1 100644 --- a/test/configCases/split-chunks/issue-11513/index.js +++ b/test/configCases/split-chunks/issue-11513/index.js @@ -1,4 +1,2 @@ -it("should handle mixed size types chunk in splitChunks", async () => { - import("./chunk1"); - import("./chunk2"); -}); +it("should handle mixed size types chunk in splitChunks", () => + Promise.all([import("./chunk1"), import("./chunk2")])); diff --git a/test/configCases/split-chunks/runtime-chunk-async-node/webpack.config.js b/test/configCases/split-chunks/runtime-chunk-async-node/webpack.config.js index 6f0323a1ba2..a023f1b45f2 100644 --- a/test/configCases/split-chunks/runtime-chunk-async-node/webpack.config.js +++ b/test/configCases/split-chunks/runtime-chunk-async-node/webpack.config.js @@ -9,7 +9,10 @@ module.exports = { }, target: "async-node", output: { - filename: "[name].js" + filename: "[name].js", + library: { + type: "commonjs-module" + } }, optimization: { chunkIds: "named",