Skip to content

Commit a5f664f

Browse files
committed
test: reset globalThis.__import_unsupported between tests
1 parent 2b71395 commit a5f664f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/test-setup.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import { type FixtureTestContext } from './utils/contexts'
44

55
// cleanup after each test as a fallback if someone forgot to call it
66
afterEach<FixtureTestContext>(async ({ cleanup }) => {
7+
// https://github.com/vercel/next.js/blob/668f8edb0ea47d578c6389a1d6df8fe902dec55c/packages/next/src/server/web/globals.ts#L90-L96
8+
// Next defines non-configurable property on globalThis which we can't delete and without deletion it cause "Cannot redefine property"
9+
// errors. So to be able to run tests from multiple fixtures we recreate globalThis without __import_unsupported property.
10+
const newGlobalThisWithoutImportUnsupported = {}
11+
const globalProps = Object.getOwnPropertyDescriptors(globalThis)
12+
delete globalProps.__import_unsupported
13+
Object.defineProperties(newGlobalThisWithoutImportUnsupported, globalProps)
14+
// @ts-ignore it seems we can assign globalThis despite TS error
15+
globalThis = newGlobalThisWithoutImportUnsupported
16+
717
if ('reset' in fs) {
818
;(fs as any).reset()
919
}

0 commit comments

Comments
 (0)