diff --git a/test/BuildDependencies.test.js b/test/BuildDependencies.test.js index 1133b71e0..1e828e67e 100644 --- a/test/BuildDependencies.test.js +++ b/test/BuildDependencies.test.js @@ -9,11 +9,11 @@ const cacheDirectory = path.resolve(__dirname, "js/buildDepsCache"); const outputDirectory = path.resolve(__dirname, "js/buildDeps"); const inputDirectory = path.resolve(__dirname, "js/buildDepsInput"); -const webpack = require("../"); -const coverageEnabled = webpack.toString().includes("++"); - const exec = (n, options = {}) => { return new Promise((resolve, reject) => { + const webpack = require("../"); + const coverageEnabled = webpack.toString().includes("++"); + const p = child_process.execFile( process.execPath, [ diff --git a/test/ChangesAndRemovals.test.js b/test/ChangesAndRemovals.test.js index fbd182064..ad647b174 100644 --- a/test/ChangesAndRemovals.test.js +++ b/test/ChangesAndRemovals.test.js @@ -1,12 +1,14 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const { createFsFromVolume, Volume } = require("memfs"); -const webpack = require(".."); const fs = require("graceful-fs"); const rimraf = require("rimraf"); const createCompiler = config => { + const webpack = require(".."); const compiler = webpack(config); compiler.outputFileSystem = createFsFromVolume(new Volume()); return compiler; diff --git a/test/Compiler-caching.test.js b/test/Compiler-caching.test.js index f4a6f9a9f..2e2efda7b 100644 --- a/test/Compiler-caching.test.js +++ b/test/Compiler-caching.test.js @@ -1,16 +1,18 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("graceful-fs"); const rimraf = require("rimraf"); -const webpack = require(".."); let fixtureCount = 0; describe("Compiler (caching)", () => { jest.setTimeout(15000); function compile(entry, options, callback) { + const webpack = require(".."); options = webpack.config.getNormalizedWebpackOptions(options); options.mode = "none"; options.cache = true; diff --git a/test/Compiler.test.js b/test/Compiler.test.js index a94b2be72..c440edc42 100644 --- a/test/Compiler.test.js +++ b/test/Compiler.test.js @@ -1,8 +1,8 @@ "use strict"; -const path = require("path"); +require("./helpers/warmup-webpack"); -const webpack = require(".."); +const path = require("path"); const Stats = require("../lib/Stats"); const { createFsFromVolume, Volume } = require("memfs"); const captureStdio = require("./helpers/captureStdio"); @@ -12,6 +12,7 @@ describe("Compiler", () => { jest.setTimeout(20000); function compile(entry, options, callback) { const noOutputPath = !options.output || !options.output.path; + const webpack = require(".."); options = webpack.config.getNormalizedWebpackOptions(options); if (!options.mode) options.mode = "production"; options.entry = entry; @@ -206,6 +207,7 @@ describe("Compiler", () => { describe("methods", () => { let compiler; beforeEach(() => { + const webpack = require(".."); compiler = webpack({ entry: "./c", context: path.join(__dirname, "fixtures"), @@ -285,6 +287,7 @@ describe("Compiler", () => { }); }); it("should not emit on errors", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -306,6 +309,7 @@ describe("Compiler", () => { try { const createCompiler = options => { return new Promise((resolve, reject) => { + const webpack = require(".."); const c = webpack(options); c.run((err, stats) => { if (err) { @@ -339,6 +343,7 @@ describe("Compiler", () => { it("should not emit compilation errors in async (watch)", async () => { const createStats = options => { return new Promise((resolve, reject) => { + const webpack = require(".."); const c = webpack(options); c.outputFileSystem = createFsFromVolume(new Volume()); const watching = c.watch({}, (err, stats) => { @@ -362,6 +367,7 @@ describe("Compiler", () => { }); it("should not emit on errors (watch)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -381,6 +387,7 @@ describe("Compiler", () => { }); }); it("should not be running twice at a time (run)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -399,6 +406,7 @@ describe("Compiler", () => { }); }); it("should not be running twice at a time (watch)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -417,6 +425,7 @@ describe("Compiler", () => { }); }); it("should not be running twice at a time (run - watch)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -435,6 +444,7 @@ describe("Compiler", () => { }); }); it("should not be running twice at a time (watch - run)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -453,6 +463,7 @@ describe("Compiler", () => { }); }); it("should not be running twice at a time (instance cb)", done => { + const webpack = require(".."); compiler = webpack( { context: __dirname, @@ -471,6 +482,7 @@ describe("Compiler", () => { }); }); it("should run again correctly after first compilation", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -492,6 +504,7 @@ describe("Compiler", () => { }); }); it("should watch again correctly after first compilation", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -512,6 +525,7 @@ describe("Compiler", () => { }); }); it("should run again correctly after first closed watch", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -533,6 +547,7 @@ describe("Compiler", () => { }); }); it("should set compiler.watching correctly", function (done) { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -550,6 +565,7 @@ describe("Compiler", () => { expect(compiler.watching).toBe(watching); }); it("should watch again correctly after first closed watch", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -571,6 +587,7 @@ describe("Compiler", () => { }); }); it("should run again correctly inside afterDone hook", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -595,6 +612,7 @@ describe("Compiler", () => { }); }); it("should call afterDone hook after other callbacks (run)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -620,6 +638,7 @@ describe("Compiler", () => { }); it("should call afterDone hook after other callbacks (instance cb)", done => { const instanceCb = jest.fn(); + const webpack = require(".."); compiler = webpack( { context: __dirname, @@ -645,6 +664,7 @@ describe("Compiler", () => { }); }); it("should call afterDone hook after other callbacks (watch)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -677,6 +697,7 @@ describe("Compiler", () => { }); }); it("should call afterDone hook after other callbacks (watch close)", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -709,6 +730,7 @@ describe("Compiler", () => { }); }); it("should flag watchMode as true in watch", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "production", @@ -731,6 +753,7 @@ describe("Compiler", () => { }); }); it("should use cache on second run call", done => { + const webpack = require(".."); compiler = webpack({ context: __dirname, mode: "development", @@ -754,6 +777,7 @@ describe("Compiler", () => { }); it("should call the failed-hook on error", done => { const failedSpy = jest.fn(); + const webpack = require(".."); compiler = webpack({ bail: true, context: __dirname, @@ -775,7 +799,8 @@ describe("Compiler", () => { }); it("should deprecate when watch option is used without callback", () => { const tracker = deprecationTracking.start(); - webpack({ + const webpack = require(".."); + compiler = webpack({ watch: true }); const deprecations = tracker(); @@ -817,6 +842,7 @@ describe("Compiler", () => { } } it("should log to the console (verbose)", done => { + const webpack = require(".."); compiler = webpack({ context: path.join(__dirname, "fixtures"), entry: "./a", @@ -847,6 +873,7 @@ describe("Compiler", () => { }); }); it("should log to the console (debug mode)", done => { + const webpack = require(".."); compiler = webpack({ context: path.join(__dirname, "fixtures"), entry: "./a", @@ -879,6 +906,7 @@ describe("Compiler", () => { }); }); it("should log to the console (none)", done => { + const webpack = require(".."); compiler = webpack({ context: path.join(__dirname, "fixtures"), entry: "./a", @@ -898,6 +926,7 @@ describe("Compiler", () => { }); }); it("should log to the console with colors (verbose)", done => { + const webpack = require(".."); compiler = webpack({ context: path.join(__dirname, "fixtures"), entry: "./a", @@ -929,6 +958,7 @@ describe("Compiler", () => { }); }); it("should log to the console with colors (debug mode)", done => { + const webpack = require(".."); compiler = webpack({ context: path.join(__dirname, "fixtures"), entry: "./a", diff --git a/test/ConfigTestCases.template.js b/test/ConfigTestCases.template.js index 462118f21..124a6e3f8 100644 --- a/test/ConfigTestCases.template.js +++ b/test/ConfigTestCases.template.js @@ -1,5 +1,7 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("graceful-fs"); const vm = require("vm"); diff --git a/test/Defaults.unittest.js b/test/Defaults.unittest.js index 20bda519d..c11d89b8a 100644 --- a/test/Defaults.unittest.js +++ b/test/Defaults.unittest.js @@ -1,8 +1,8 @@ +require("./helpers/warmup-webpack"); + const path = require("path"); const jestDiff = require("jest-diff").diff; const stripAnsi = require("strip-ansi"); -const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = - require("..").config; /** * Escapes regular expression metacharacters @@ -63,6 +63,8 @@ describe("Defaults", () => { }); const getDefaultConfig = config => { + const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = + require("..").config; config = getNormalizedWebpackOptions(config); applyWebpackOptionsDefaults(config); process.chdir(cwd); diff --git a/test/Errors.test.js b/test/Errors.test.js index 6e4fbbd6f..53ca3c778 100644 --- a/test/Errors.test.js +++ b/test/Errors.test.js @@ -1,5 +1,7 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("graceful-fs"); const webpack = require(".."); @@ -129,12 +131,6 @@ async function compile(options) { return { errors, warnings }; } -it("should compile fine (warmup)", async () => { - await compile({ - entry: "./entry-point" - }); -}, 120000); - it("should emit warning for missingFile", async () => { await expect( compile({ diff --git a/test/Examples.test.js b/test/Examples.test.js index 747dc503c..39a39608a 100644 --- a/test/Examples.test.js +++ b/test/Examples.test.js @@ -1,9 +1,9 @@ "use strict"; -/* describe it */ +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("graceful-fs"); -const webpack = require(".."); describe("Examples", () => { const basePath = path.join(__dirname, "..", "examples"); @@ -39,6 +39,7 @@ describe("Examples", () => { if (!options.entry) options.entry = "./example.js"; if (!options.plugins) options.plugins = []; } + const webpack = require(".."); webpack(options, (err, stats) => { if (err) return done(err); if (stats.hasErrors()) { diff --git a/test/HotTestCases.template.js b/test/HotTestCases.template.js index 8e2245adf..7d991f038 100644 --- a/test/HotTestCases.template.js +++ b/test/HotTestCases.template.js @@ -1,5 +1,7 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("graceful-fs"); const vm = require("vm"); @@ -7,8 +9,6 @@ const rimraf = require("rimraf"); const checkArrayExpectation = require("./checkArrayExpectation"); const createLazyTestEnv = require("./helpers/createLazyTestEnv"); -const webpack = require(".."); - const casesPath = path.join(__dirname, "hotCases"); let categories = fs .readdirSync(casesPath) @@ -45,6 +45,7 @@ const describeCases = config => { it( testName + " should compile", done => { + const webpack = require(".."); const outputDirectory = path.join( __dirname, "js", diff --git a/test/MultiCompiler.test.js b/test/MultiCompiler.test.js index 2b11f5e03..1c7459ec5 100644 --- a/test/MultiCompiler.test.js +++ b/test/MultiCompiler.test.js @@ -1,5 +1,6 @@ "use strict"; +require("./helpers/warmup-webpack"); const path = require("path"); const { createFsFromVolume, Volume } = require("memfs"); const webpack = require(".."); diff --git a/test/MultiStats.test.js b/test/MultiStats.test.js index db5f64f6b..e36364975 100644 --- a/test/MultiStats.test.js +++ b/test/MultiStats.test.js @@ -1,10 +1,12 @@ "use strict"; -const webpack = require(".."); +require("./helpers/warmup-webpack"); + const { createFsFromVolume, Volume } = require("memfs"); describe("MultiStats", () => { it("should create JSON of children stats", done => { + const webpack = require(".."); const compiler = webpack([ { context: __dirname, diff --git a/test/NodeTemplatePlugin.test.js b/test/NodeTemplatePlugin.test.js index be3f1c872..5c87decd5 100644 --- a/test/NodeTemplatePlugin.test.js +++ b/test/NodeTemplatePlugin.test.js @@ -1,11 +1,13 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); -const webpack = require(".."); describe("NodeTemplatePlugin", () => { jest.setTimeout(20000); it("should compile and run a simple module", done => { + const webpack = require(".."); webpack( { mode: "production", @@ -42,6 +44,7 @@ describe("NodeTemplatePlugin", () => { }); it("should compile and run a simple module in single mode", done => { + const webpack = require(".."); webpack( { mode: "production", diff --git a/test/PersistentCaching.test.js b/test/PersistentCaching.test.js index 0b59186bd..581f6e957 100644 --- a/test/PersistentCaching.test.js +++ b/test/PersistentCaching.test.js @@ -1,9 +1,10 @@ +require("./helpers/warmup-webpack"); + const path = require("path"); const util = require("util"); const fs = require("fs"); const rimraf = require("rimraf"); const vm = require("vm"); -const webpack = require("../"); const readdir = util.promisify(fs.readdir); const writeFile = util.promisify(fs.writeFile); @@ -52,6 +53,7 @@ describe("Persistent Caching", () => { const compile = async (configAdditions = {}) => { return new Promise((resolve, reject) => { + const webpack = require("../"); webpack( { ...config, @@ -164,6 +166,7 @@ export default ${files.map((_, i) => `f${i}`).join(" + ")}; "lib2.js": "export default 21" }; await updateSrc(data); + const webpack = require("../"); const configAdditions = { plugins: [ new webpack.container.ModuleFederationPlugin({ diff --git a/test/ProfilingPlugin.test.js b/test/ProfilingPlugin.test.js index a79de98f5..de3a67669 100644 --- a/test/ProfilingPlugin.test.js +++ b/test/ProfilingPlugin.test.js @@ -1,14 +1,16 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("graceful-fs"); -const webpack = require("../"); const rimraf = require("rimraf"); describe("Profiling Plugin", function () { jest.setTimeout(120000); it("should handle output path with folder creation", done => { + const webpack = require("../"); const outputPath = path.join(__dirname, "js/profilingPath"); const finalPath = path.join(outputPath, "events.json"); rimraf(outputPath, () => { diff --git a/test/Stats.test.js b/test/Stats.test.js index 15dc0c220..d57979117 100644 --- a/test/Stats.test.js +++ b/test/Stats.test.js @@ -1,10 +1,12 @@ "use strict"; -const webpack = require(".."); +require("./helpers/warmup-webpack"); + const { createFsFromVolume, Volume } = require("memfs"); const compile = options => { return new Promise((resolve, reject) => { + const webpack = require(".."); const compiler = webpack(options); compiler.outputFileSystem = createFsFromVolume(new Volume()); compiler.run((err, stats) => { diff --git a/test/StatsTestCases.basictest.js b/test/StatsTestCases.basictest.js index af088cbbc..aa21e8d3f 100644 --- a/test/StatsTestCases.basictest.js +++ b/test/StatsTestCases.basictest.js @@ -1,5 +1,6 @@ "use strict"; +require("./helpers/warmup-webpack"); const path = require("path"); const fs = require("graceful-fs"); const rimraf = require("rimraf"); @@ -35,7 +36,7 @@ const tests = fs }); describe("StatsTestCases", () => { - jest.setTimeout(60000); + jest.setTimeout(30000); let stderr; beforeEach(() => { stderr = captureStdio(process.stderr, true); diff --git a/test/TestCases.template.js b/test/TestCases.template.js index e88202f1b..32b1f32ee 100644 --- a/test/TestCases.template.js +++ b/test/TestCases.template.js @@ -1,5 +1,6 @@ "use strict"; +require("./helpers/warmup-webpack"); const path = require("path"); const fs = require("graceful-fs"); const vm = require("vm"); diff --git a/test/TestCasesAllCombined.test.js b/test/TestCasesAllCombined.test.js index c6482879e..1d193c5f6 100644 --- a/test/TestCasesAllCombined.test.js +++ b/test/TestCasesAllCombined.test.js @@ -1,5 +1,4 @@ const { describeCases } = require("./TestCases.template"); -const webpack = require(".."); describe("TestCases", () => { describeCases({ @@ -11,6 +10,11 @@ describe("TestCases", () => { moduleIds: "named", chunkIds: "named" }, - plugins: [new webpack.HotModuleReplacementPlugin()] + plugins: [ + c => { + const webpack = require(".."); + new webpack.HotModuleReplacementPlugin().apply(c); + } + ] }); }); diff --git a/test/Validation.test.js b/test/Validation.test.js index bcba1df67..490ed620d 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -1,11 +1,12 @@ "use strict"; -const webpack = require(".."); +require("./helpers/warmup-webpack"); describe("Validation", () => { const createTestCase = (name, config, fn) => { it("should fail validation for " + name, () => { try { + const webpack = require(".."); webpack(config); } catch (err) { if (err.name !== "ValidationError") throw err; diff --git a/test/WatchClose.test.js b/test/WatchClose.test.js index 9d476817b..1b632e13c 100644 --- a/test/WatchClose.test.js +++ b/test/WatchClose.test.js @@ -1,8 +1,8 @@ "use strict"; -const path = require("path"); +require("./helpers/warmup-webpack"); -const webpack = require("../"); +const path = require("path"); describe("WatchClose", () => { jest.setTimeout(5000); @@ -16,6 +16,7 @@ describe("WatchClose", () => { let watcher; beforeEach(() => { + const webpack = require("../"); compiler = webpack({ mode: "development", entry: filePath, diff --git a/test/WatchSuspend.test.js b/test/WatchSuspend.test.js index 2fa2137a6..dce53a7fc 100644 --- a/test/WatchSuspend.test.js +++ b/test/WatchSuspend.test.js @@ -1,10 +1,10 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("fs"); -const webpack = require("../"); - describe("WatchSuspend", () => { if (process.env.NO_WATCH_TESTS) { it.skip("long running tests excluded", () => {}); @@ -41,6 +41,7 @@ describe("WatchSuspend", () => { } catch (e) { // skip } + const webpack = require("../"); compiler = webpack({ mode: "development", entry: filePath, diff --git a/test/WatchTestCases.test.js b/test/WatchTestCases.test.js index 20f0a2ee5..b03bc32bf 100644 --- a/test/WatchTestCases.test.js +++ b/test/WatchTestCases.test.js @@ -1,5 +1,7 @@ "use strict"; +require("./helpers/warmup-webpack"); + const path = require("path"); const fs = require("graceful-fs"); const vm = require("vm"); @@ -11,8 +13,6 @@ const prepareOptions = require("./helpers/prepareOptions"); const deprecationTracking = require("./helpers/deprecationTracking"); const FakeDocument = require("./helpers/FakeDocument"); -const webpack = require(".."); - function copyDiff(src, dest, initial) { if (!fs.existsSync(dest)) fs.mkdirSync(dest); const files = fs.readdirSync(src); @@ -156,6 +156,7 @@ describe("WatchTestCases", () => { setTimeout(() => { const deprecationTracker = deprecationTracking.start(); + const webpack = require(".."); const compiler = webpack(options); compiler.hooks.invalid.tap( "WatchTestCasesTest", diff --git a/test/helpers/warmup-webpack.js b/test/helpers/warmup-webpack.js new file mode 100644 index 000000000..44429c66f --- /dev/null +++ b/test/helpers/warmup-webpack.js @@ -0,0 +1,26 @@ +describe("warmup", () => { + it("should warmup webpack", done => { + let webpack = require("../../"); + let END = new Error("end warmup"); + webpack( + { + entry: "data:text/javascript,import 'data:text/javascript,'", + plugins: [ + c => + c.hooks.emit.tap("Warmup", () => { + throw END; + }) + ] + }, + err => { + webpack = undefined; + try { + expect(err).toBe(END); + done(); + } catch (e) { + done(e); + } + } + ); + }, 120000); +});