Skip to content

Commit

Permalink
refactor(jest-jasmine2, jest-runtime): use Symbol to pass `jest.setTi…
Browse files Browse the repository at this point in the history
…meout` value instead of `jasmine` specific logic (#12124)
  • Loading branch information
mrazauskas committed Feb 10, 2022
1 parent a8e997a commit ff7a751
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))

Expand Down
15 changes: 14 additions & 1 deletion packages/jest-jasmine2/src/jasmine/jasmineLight.ts
Expand Up @@ -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<string, any>): 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());
Expand Down
8 changes: 2 additions & 6 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -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;
};

Expand Down

0 comments on commit ff7a751

Please sign in to comment.