From 3dcbdbb5008119a1a63855655a753936060f771b Mon Sep 17 00:00:00 2001 From: hrmny <8845940+ForsakenHarmony@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:50:02 +0200 Subject: [PATCH] work around tree shaking issue --- crates/turbopack-tests/js/jest-entry.ts | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/turbopack-tests/js/jest-entry.ts b/crates/turbopack-tests/js/jest-entry.ts index dd71a1e999ea0e..6a31422b25a792 100644 --- a/crates/turbopack-tests/js/jest-entry.ts +++ b/crates/turbopack-tests/js/jest-entry.ts @@ -3,18 +3,20 @@ const jest = __turbopack_external_require__("jest-circus"); const expectMod = __turbopack_external_require__("expect"); -globalThis.describe = jest.describe; -globalThis.it = jest.it; -globalThis.test = jest.test; -globalThis.expect = expectMod.expect; - -// From https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/test/TestCases.template.js#L422 -globalThis.nsObj = function nsObj(obj) { - Object.defineProperty(obj, Symbol.toStringTag, { - value: "Module", - }); - return obj; -}; +function setupGlobals() { + globalThis.describe = jest.describe; + globalThis.it = jest.it; + globalThis.test = jest.test; + globalThis.expect = expectMod.expect; + + // From https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/test/TestCases.template.js#L422 + globalThis.nsObj = function nsObj(obj) { + Object.defineProperty(obj, Symbol.toStringTag, { + value: "Module", + }); + return obj; + }; +} const uncaughtExceptions: string[] = []; const unhandledRejections: string[] = []; @@ -28,6 +30,8 @@ process.on("unhandledRejection", (e) => { }); export default async function run() { + setupGlobals(); + await import("TESTS"); const jestResult = await jest.run();