From ff7a7518a941e75587ae67b6c0455882bda6cb17 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Thu, 10 Feb 2022 13:05:21 +0200 Subject: [PATCH] refactor(jest-jasmine2, jest-runtime): use Symbol to pass `jest.setTimeout` value instead of `jasmine` specific logic (#12124) --- CHANGELOG.md | 1 + .../jest-jasmine2/src/jasmine/jasmineLight.ts | 15 ++++++++++++++- packages/jest-runtime/src/index.ts | 8 ++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5606f64e920b..e710607bc6c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - `[jest-environment-node]` [**BREAKING**] Add default `node` and `node-addon` conditions to `exportConditions` for `node` environment ([#11924](https://github.com/facebook/jest/pull/11924)) - `[jest-environment-node]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340)) - `[@jest/expect-utils]` New module exporting utils for `expect` ([#12323](https://github.com/facebook/jest/pull/12323)) +- `[jest-jasmine2, jest-runtime]` [**BREAKING**] Use `Symbol` to pass `jest.setTimeout` value instead of `jasmine` specific logic ([#12124](https://github.com/facebook/jest/pull/12124)) - `[jest-snapshot]` [**BREAKING**] Migrate to ESM ([#12342](https://github.com/facebook/jest/pull/12342)) - `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343)) diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts index b54a79d8927e..be334b91531a 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts @@ -40,10 +40,23 @@ import Timer from './Timer'; import createSpy from './createSpy'; import SpyRegistry from './spyRegistry'; +const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); + export const create = function (createOptions: Record): Jasmine { const j$ = {...createOptions} as Jasmine; - j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.testTimeout || 5000; + Object.defineProperty(j$, '_DEFAULT_TIMEOUT_INTERVAL', { + configurable: true, + enumerable: true, + get() { + return ( + (global as any)[testTimeoutSymbol] || createOptions.testTimeout || 5000 + ); + }, + set(value) { + (global as any)[testTimeoutSymbol] = value; + }, + }); j$.getEnv = function () { const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env()); diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index bb22dbcde7b8..22be30d419d4 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -1933,12 +1933,8 @@ export default class Runtime { }); const setTimeout = (timeout: number) => { - if (this._environment.global.jasmine) { - this._environment.global.jasmine._DEFAULT_TIMEOUT_INTERVAL = timeout; - } else { - // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 - this._environment.global[testTimeoutSymbol] = timeout; - } + // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 + this._environment.global[testTimeoutSymbol] = timeout; return jestObject; };