Skip to content

Commit

Permalink
use getter and setter
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Dec 6, 2021
1 parent 2ad75af commit 4d175b4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/jest-jasmine2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const JASMINE = require.resolve('./jasmine/jasmineLight');

const jestEachBuildDir = path.dirname(require.resolve('jest-each'));

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

export default async function jasmine2(
globalConfig: Config.GlobalConfig,
config: Config.ProjectConfig,
Expand Down Expand Up @@ -132,12 +130,10 @@ export default async function jasmine2(
configurable: true,
enumerable: true,
get() {
// @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587
return environment.global[testTimeoutSymbol];
return this._DEFAULT_TIMEOUT_INTERVAL;
},
set(value) {
// @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587
environment.global[testTimeoutSymbol] = value;
this._DEFAULT_TIMEOUT_INTERVAL = value;
},
});
}
Expand Down
12 changes: 5 additions & 7 deletions packages/jest-jasmine2/src/jasmine/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ import type {
import type {default as Spec, SpecResult} from './Spec';
import type Suite from './Suite';

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

export default function (j$: Jasmine) {
return class Env {
specFilter: (spec: Spec) => boolean;
Expand Down Expand Up @@ -512,7 +510,7 @@ export default function (j$: Jasmine) {
queueableFn: {
fn,
timeout() {
return timeout || (global as any)[testTimeoutSymbol];
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
},
throwOnExpectationFailure,
Expand Down Expand Up @@ -624,7 +622,7 @@ export default function (j$: Jasmine) {
currentDeclarationSuite.beforeEach({
fn: beforeEachFunction,
timeout() {
return timeout || (global as any)[testTimeoutSymbol];
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
Expand All @@ -633,7 +631,7 @@ export default function (j$: Jasmine) {
currentDeclarationSuite.beforeAll({
fn: beforeAllFunction,
timeout() {
return timeout || (global as any)[testTimeoutSymbol];
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
Expand All @@ -642,7 +640,7 @@ export default function (j$: Jasmine) {
currentDeclarationSuite.afterEach({
fn: afterEachFunction,
timeout() {
return timeout || (global as any)[testTimeoutSymbol];
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
Expand All @@ -651,7 +649,7 @@ export default function (j$: Jasmine) {
currentDeclarationSuite.afterAll({
fn: afterAllFunction,
timeout() {
return timeout || (global as any)[testTimeoutSymbol];
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
Expand Down
13 changes: 12 additions & 1 deletion packages/jest-jasmine2/src/jasmine/jasmineLight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL');
export const create = function (createOptions: Record<string, any>): Jasmine {
const j$ = {...createOptions} as Jasmine;

(global as any)[testTimeoutSymbol] = 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
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type JasmineMatcher = {
export type JasmineMatchersObject = {[id: string]: JasmineMatcher};

export type Jasmine = {
_DEFAULT_TIMEOUT_INTERVAL: number;
DEFAULT_TIMEOUT_INTERVAL: number;
currentEnv_: ReturnType<typeof Env>['prototype'];
getEnv: () => ReturnType<typeof Env>['prototype'];
Expand Down

0 comments on commit 4d175b4

Please sign in to comment.