diff options
author | 2023-09-13 19:57:59 -0400 | |
---|---|---|
committer | 2023-09-13 16:57:59 -0700 | |
commit | 4f8edb825f48d06891de7a77131c6a434c06df88 (patch) | |
tree | ee9b1b19a3c379e0f05b2f28e395948ed078561a /test/cli/run/require-cache-bug-5188.js | |
parent | cb01cb0d4ad67aace33ae603938d1a28a7c10ca7 (diff) | |
download | bun-4f8edb825f48d06891de7a77131c6a434c06df88.tar.gz bun-4f8edb825f48d06891de7a77131c6a434c06df88.tar.zst bun-4f8edb825f48d06891de7a77131c6a434c06df88.zip |
fix(runtime): require cache should not include unevaluated ESM modules. (#5233)
Diffstat (limited to 'test/cli/run/require-cache-bug-5188.js')
-rw-r--r-- | test/cli/run/require-cache-bug-5188.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/cli/run/require-cache-bug-5188.js b/test/cli/run/require-cache-bug-5188.js new file mode 100644 index 000000000..cb9bd2099 --- /dev/null +++ b/test/cli/run/require-cache-bug-5188.js @@ -0,0 +1,21 @@ +const { strictEqual, ok } = require("assert"); + +Loader.registry.set("bad", { evaluated: false }); +strictEqual(require.cache.bad, undefined); +ok(!Object.hasOwn(require.cache, "bad")); +ok(!Object.getOwnPropertyNames(require.cache).includes("bad")); + +// hard to simplify this test case, but importing this would cause require.cache.extract to be set +require("msgpackr-extract"); + +strictEqual(require.cache["extract"], undefined); +ok(!Object.hasOwnProperty.call(require.cache, "extract")); +ok(!Object.getOwnPropertyNames(require.cache).includes("extract")); + +for (const key of Object.keys(require.cache)) { + if (!require.cache[key]) { + throw new Error("require.cache has an undefined value that was in it's keys"); + } +} + +console.log("--pass--"); |