Skip to content

Commit 7dd4935

Browse files
committed
test(commonjs): call stub fixture to ensure external built-in proxy is emitted; update snapshots
1 parent 41adfa1 commit 7dd4935

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
// Top-level require of a Node builtin ensures the transform computes
2-
// wrappedModuleSideEffects for an external wrapped dependency.
1+
// Ensure the transform computes `wrappedModuleSideEffects` for an external
2+
// wrapped dependency by including a Node builtin `require()` inside a function.
33
function unused() {
4-
// External Node builtin require; not executed at runtime
4+
// External Node builtin require – converted to an external proxy.
5+
// When `externalBuiltinsRequire: 'stub'`, calling this will throw; we
6+
// invoke it inside a try/catch below so the test can snapshot the emitted
7+
// stub proxy without failing at runtime.
58
require('node:crypto');
69
}
710

11+
try {
12+
unused();
13+
} catch {}
14+
815
module.exports = 1;

β€Žpackages/commonjs/test/snapshots/function.js.mdβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6742,12 +6742,27 @@ Generated by [AVA](https://avajs.dev).
67426742
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊
67436743
}␊
67446744
␊
6745+
function __require() { throw new Error("Node built-in node:crypto is not available in this environment"); }␊
6746+
␊
67456747
var main$1;␊
67466748
var hasRequiredMain;␊
67476749
␊
67486750
function requireMain () {␊
67496751
if (hasRequiredMain) return main$1;␊
67506752
hasRequiredMain = 1;␊
6753+
// Ensure the transform computes \`wrappedModuleSideEffects\` for an external␊
6754+
// wrapped dependency by including a Node builtin \`require()\` inside a function.␊
6755+
function unused() {␊
6756+
// External Node builtin require – converted to an external proxy.␊
6757+
// When \`externalBuiltinsRequire: 'stub'\`, calling this will throw; we␊
6758+
// invoke it inside a try/catch below so the test can snapshot the emitted␊
6759+
// stub proxy without failing at runtime.␊
6760+
__require();␊
6761+
}␊
6762+
␊
6763+
try {␊
6764+
unused();␊
6765+
} catch {}␊
67516766
␊
67526767
main$1 = 1;␊
67536768
return main$1;␊
377 Bytes
Binary file not shown.

0 commit comments

Comments
Β (0)