Skip to content

Commit 9dfdf76

Browse files
test: globalThis (#20028)
1 parent ed3574a commit 9dfdf76

8 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
text
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
it("should use/not use globalThis", () => {
2+
expect(new URL("./file.text", import.meta.url)).toBeDefined();
3+
4+
const stats = __STATS__.children[__STATS_I__];
5+
6+
expect(stats.modules.length).toBe(__STATS_I__ === 0 ? 6 : 5);
7+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
const supportsGlobalThis = require("../../../helpers/supportsGlobalThis");
4+
5+
module.exports = () => supportsGlobalThis();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration[]} */
4+
module.exports = [
5+
{
6+
target: "web",
7+
output: {
8+
environment: { globalThis: false }
9+
},
10+
stats: {
11+
runtimeModules: true
12+
}
13+
},
14+
{
15+
target: "web",
16+
output: {
17+
environment: { globalThis: true }
18+
},
19+
stats: {
20+
runtimeModules: true
21+
}
22+
}
23+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
it("should use/not use globalThis", () => {
2+
expect(global).toBeDefined();
3+
4+
const stats = __STATS__.children[__STATS_I__];
5+
6+
expect(stats.modules.length).toBe(__STATS_I__ === 0 ? 2 : 1);
7+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
const supportsGlobalThis = require("../../../helpers/supportsGlobalThis");
4+
5+
module.exports = () => supportsGlobalThis();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration[]} */
4+
module.exports = [
5+
{
6+
target: "web",
7+
output: {
8+
environment: { globalThis: false }
9+
},
10+
stats: {
11+
runtimeModules: true
12+
}
13+
},
14+
{
15+
target: "web",
16+
output: {
17+
environment: { globalThis: true }
18+
},
19+
stats: {
20+
runtimeModules: true
21+
}
22+
}
23+
];

test/helpers/supportsGlobalThis.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
3+
module.exports = function supportsGlobalThis() {
4+
try {
5+
eval("globalThis");
6+
return true;
7+
} catch (_err) {
8+
// Ignore
9+
}
10+
11+
return false;
12+
};

0 commit comments

Comments
 (0)