Skip to content

Commit b6ccbb5

Browse files
authored
test: make global.__import_unsupported configurable (#2553)
1 parent 8433df5 commit b6ccbb5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/utils/fixture.ts

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ async function installDependencies(cwd: string) {
5454
export const getFixtureSourceDirectory = (fixture: string) =>
5555
fileURLToPath(new URL(`../fixtures/${fixture}`, import.meta.url))
5656

57+
// https://github.com/vercel/next.js/pull/67539 added more imports to "globals" modules which does have a side effect at import time
58+
// that defines NOT configurable global property ( https://github.com/vercel/next.js/blob/ba3959bb46f4d0e92403304579b8fb30d3ecc3d1/packages/next/src/server/web/globals.ts#L87-L107 ).
59+
// Running multiple fixtures in the same process then would evaluate copy of that module
60+
// and attempt to redefine that not configurable property which result in an error. We can't delete that property either, so
61+
// this "patch" to Object.defineProperty is making that property configurable when running our tests to avoid that error.
62+
const originalDefineProperty = Object.defineProperty
63+
Object.defineProperty = function (target, property, descriptor) {
64+
if (property === '__import_unsupported' && descriptor?.configurable === false) {
65+
descriptor.configurable = true
66+
}
67+
68+
return originalDefineProperty.call(this, target, property, descriptor)
69+
}
70+
5771
/**
5872
* Copies a fixture to a temp folder on the system and runs the tests inside.
5973
* @param fixture name of the folder inside the fixtures folder

0 commit comments

Comments
 (0)