Skip to content

Commit

Permalink
chore: do not cast symbol to string (#12409)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 16, 2022
1 parent 755640d commit 7cc9949
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
18 changes: 6 additions & 12 deletions packages/jest-circus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@

import type {Circus} from '@jest/types';

export const STATE_SYM = Symbol(
'JEST_STATE_SYMBOL',
) as unknown as 'STATE_SYM_SYMBOL';
export const RETRY_TIMES = Symbol.for(
'RETRY_TIMES',
) as unknown as 'RETRY_TIMES_SYMBOL';
export const STATE_SYM = Symbol('JEST_STATE_SYMBOL');
export const RETRY_TIMES = Symbol.for('RETRY_TIMES');
// To pass this value from Runtime object to state we need to use global[sym]
export const TEST_TIMEOUT_SYMBOL = Symbol.for(
'TEST_TIMEOUT_SYMBOL',
) as unknown as 'TEST_TIMEOUT_SYMBOL';
export const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL');

declare global {
namespace NodeJS {
interface Global {
STATE_SYM_SYMBOL: Circus.State;
RETRY_TIMES_SYMBOL: string;
TEST_TIMEOUT_SYMBOL: number;
[STATE_SYM]: Circus.State;
[RETRY_TIMES]: string;
[TEST_TIMEOUT_SYMBOL]: number;
}
}
}
14 changes: 10 additions & 4 deletions packages/jest-jasmine2/src/jasmine/jasmineLight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,25 @@ import SpyRegistry from './spyRegistry';

const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL');

declare global {
namespace NodeJS {
interface Global {
[testTimeoutSymbol]: number;
}
}
}

export const create = function (createOptions: Record<string, any>): Jasmine {
const j$ = {...createOptions} as Jasmine;

Object.defineProperty(j$, '_DEFAULT_TIMEOUT_INTERVAL', {
configurable: true,
enumerable: true,
get() {
return (
(global as any)[testTimeoutSymbol] || createOptions.testTimeout || 5000
);
return global[testTimeoutSymbol] || createOptions.testTimeout || 5000;
},
set(value) {
(global as any)[testTimeoutSymbol] = value;
global[testTimeoutSymbol] = value;
},
});

Expand Down

0 comments on commit 7cc9949

Please sign in to comment.