Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(jest-jasmine2, jest-runtime): use Symbol to pass jest.setTimeout value instead of jasmine specific logic #12124

Merged
merged 5 commits into from Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,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;
},
Comment on lines +56 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setter is used by jasmine.DEFAULT_TIMEOUT_INTERVAL. Otherwise it is unnecessary here.

});

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