Skip to content

Commit

Permalink
fix vitest-environment-miniflare node 21 compatibility (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeys089 authored Nov 8, 2023
1 parent 90797a8 commit 2d9e3e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/shared/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export function prefixError(prefix: string, e: any): Error {
if (e.stack) {
return new Proxy(e, {
get(target, propertyKey, receiver) {
const value = Reflect.get(target, propertyKey, receiver);
return propertyKey === "stack" ? `${prefix}: ${value}` : value;
return propertyKey === "stack"
? `${prefix}: ${target.stack}`
: Reflect.get(target, propertyKey, receiver);
},
});
}
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest-environment-miniflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export default <Environment>{
delete mfGlobalScope.crypto;
Object.defineProperty(global, "crypto", { get: () => crypto });

// `navigator` is defined as a getter on the global scope in Node 21+,
// so attempting to set it with `Object.assign()` would fail. Instead,
// override the getter with a new value.
const navigator = mfGlobalScope.navigator;
delete mfGlobalScope.navigator;
Object.defineProperty(global, "navigator", { get: () => navigator });

// Attach all Miniflare globals to `global`, recording originals to restore
// in teardown
const keys = Object.keys(mfGlobalScope);
Expand Down

0 comments on commit 2d9e3e1

Please sign in to comment.