Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 2d9e3e1

Browse files
authored
fix vitest-environment-miniflare node 21 compatibility (#734)
1 parent 90797a8 commit 2d9e3e1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/shared/src/error.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export function prefixError(prefix: string, e: any): Error {
1515
if (e.stack) {
1616
return new Proxy(e, {
1717
get(target, propertyKey, receiver) {
18-
const value = Reflect.get(target, propertyKey, receiver);
19-
return propertyKey === "stack" ? `${prefix}: ${value}` : value;
18+
return propertyKey === "stack"
19+
? `${prefix}: ${target.stack}`
20+
: Reflect.get(target, propertyKey, receiver);
2021
},
2122
});
2223
}

packages/vitest-environment-miniflare/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export default <Environment>{
9999
delete mfGlobalScope.crypto;
100100
Object.defineProperty(global, "crypto", { get: () => crypto });
101101

102+
// `navigator` is defined as a getter on the global scope in Node 21+,
103+
// so attempting to set it with `Object.assign()` would fail. Instead,
104+
// override the getter with a new value.
105+
const navigator = mfGlobalScope.navigator;
106+
delete mfGlobalScope.navigator;
107+
Object.defineProperty(global, "navigator", { get: () => navigator });
108+
102109
// Attach all Miniflare globals to `global`, recording originals to restore
103110
// in teardown
104111
const keys = Object.keys(mfGlobalScope);

0 commit comments

Comments
 (0)