Skip to content

Commit a0d7e7a

Browse files
test: keep the lazy runtime module case on the node baseline
The marker wrote through `globalThis`, which Node 10 does not have, so the executed bundle threw there. Emit through RuntimeGlobals.global instead.
1 parent 0887fe0 commit a0d7e7a

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎test/configCases/plugins/add-lazy-runtime-module/MarkerRuntimeModule.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
const RuntimeGlobals = require("../../../../lib/RuntimeGlobals");
34
const RuntimeModule = require("../../../../lib/RuntimeModule");
45

56
// Loaded through `addLazyRuntimeModule`, so it must reach the chunk's runtime.
@@ -12,7 +13,8 @@ class MarkerRuntimeModule extends RuntimeModule {
1213
* @returns {string} runtime code
1314
*/
1415
generate() {
15-
return 'globalThis.__lazyRuntimeMarker = "attached";';
16+
// the portable global: `globalThis` does not exist on the node baseline
17+
return `${RuntimeGlobals.global}.__lazyRuntimeMarker = "attached";`;
1618
}
1719
}
1820

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
it("should attach a runtime module queued through addLazyRuntimeModule", () => {
2-
expect(globalThis.__lazyRuntimeMarker).toBe("attached");
2+
expect(global.__lazyRuntimeMarker).toBe("attached");
33
});

‎test/configCases/plugins/add-lazy-runtime-module/webpack.config.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22

3+
const RuntimeGlobals = require("../../../../lib/RuntimeGlobals");
4+
35
const PLUGIN_NAME = "AddLazyRuntimeModuleTestPlugin";
46

57
/** @type {import("../../../../types").Configuration} */
@@ -10,7 +12,8 @@ module.exports = {
1012
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
1113
compilation.hooks.additionalTreeRuntimeRequirements.tap(
1214
PLUGIN_NAME,
13-
(chunk) => {
15+
(chunk, set) => {
16+
set.add(RuntimeGlobals.global);
1417
compilation.addLazyRuntimeModule(
1518
chunk,
1619
() => Promise.resolve(require("./MarkerRuntimeModule")),

0 commit comments

Comments
 (0)