Skip to content

Commit

Permalink
chore: fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Aug 24, 2021
1 parent 0517ccb commit c628bda
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/jest-console/src/BufferedConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import assert = require('assert');
import {Console} from 'console';
import {format, formatWithOptions, inspect, InspectOptions} from 'util';
import {InspectOptions, format, formatWithOptions, inspect} from 'util';
import chalk = require('chalk');
import {ErrorWithStack, formatTime} from 'jest-util';
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-console/src/CustomConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import assert = require('assert');
import {Console} from 'console';
import {format, formatWithOptions, inspect, InspectOptions} from 'util';
import {InspectOptions, format, formatWithOptions, inspect} from 'util';
import chalk = require('chalk');
import {clearLine, formatTime} from 'jest-util';
import type {LogCounters, LogMessage, LogTimers, LogType} from './types';
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-each/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ const install = (
const each = (
table: Global.EachTable,
...data: Global.TemplateData
): ReturnType<typeof install> => install(global as unknown as typeof globalThis, table, ...data);
): ReturnType<typeof install> =>
install(global as unknown as typeof globalThis, table, ...data);

each.withGlobal =
(g: typeof globalThis) =>
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ class JSDOMEnvironment implements JestEnvironment<number> {
timerConfig,
});

this.fakeTimersModern = new ModernFakeTimers({config, global: global as any as typeof globalThis});
this.fakeTimersModern = new ModernFakeTimers({
config,
global: global as any as typeof globalThis,
});
}

async setup(): Promise<void> {}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export type ModuleWrapper = (
...extraGlobals: Array<Global.Global[keyof Global.Global]>
) => unknown;

export declare class JestEnvironment<T = unknown> {
export declare class JestEnvironment<Timer = unknown> {
constructor(config: Config.ProjectConfig, context?: EnvironmentContext);
global: Global.Global;
fakeTimers: LegacyFakeTimers<T> | null;
fakeTimers: LegacyFakeTimers<Timer> | null;
fakeTimersModern: ModernFakeTimers | null;
moduleMocker: ModuleMocker | null;
getVmContext(): Context | null;
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-jasmine2/src/jasmine/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ export default function (j$: Jasmine) {

let catchExceptions = true;

const realSetTimeout = global.setTimeout as typeof globalThis['setTimeout'];
const realClearTimeout = global.clearTimeout as typeof globalThis['clearTimeout'];
const realSetTimeout =
global.setTimeout as typeof globalThis['setTimeout'];
const realClearTimeout =
global.clearTimeout as typeof globalThis['clearTimeout'];

const runnableResources: Record<string, {spies: Array<Spy>}> = {};
const currentlyExecutingSuites: Array<Suite> = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-jasmine2/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export type Jasmine = {
version: string;
testPath: Config.Path;
addMatchers: (matchers: JasmineMatchersObject) => void;
} & typeof expect & typeof globalThis;
} & typeof expect &
typeof globalThis;

declare global {
module NodeJS {
Expand Down
12 changes: 10 additions & 2 deletions packages/jest-repl/src/cli/runtime-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,16 @@ export async function run(
'console',
new CustomConsole(process.stdout, process.stderr),
);
setGlobal(environment.global as unknown as typeof globalThis, 'jestProjectConfig', config);
setGlobal(environment.global as unknown as typeof globalThis, 'jestGlobalConfig', globalConfig);
setGlobal(
environment.global as unknown as typeof globalThis,
'jestProjectConfig',
config,
);
setGlobal(
environment.global as unknown as typeof globalThis,
'jestGlobalConfig',
globalConfig,
);

const runtime = new Runtime(
config,
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-runner/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ async function runTestInternal(
? new LeakDetector(environment)
: null;

setGlobal(environment.global as unknown as typeof globalThis, 'console', testConsole);
setGlobal(
environment.global as unknown as typeof globalThis,
'console',
testConsole,
);

const runtime = new Runtime(
config,
Expand Down
22 changes: 12 additions & 10 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,16 +929,18 @@ export default class Runtime {
if (this._environment) {
if (this._environment.global) {
const envGlobal = this._environment.global;
(Object.keys(envGlobal) as Array<keyof typeof globalThis>).forEach(key => {
const globalMock = envGlobal[key];
if (
((typeof globalMock === 'object' && globalMock !== null) ||
typeof globalMock === 'function') &&
globalMock._isMockFunction === true
) {
globalMock.mockClear();
}
});
(Object.keys(envGlobal) as Array<keyof typeof globalThis>).forEach(
key => {
const globalMock = envGlobal[key];
if (
((typeof globalMock === 'object' && globalMock !== null) ||
typeof globalMock === 'function') &&
globalMock._isMockFunction === true
) {
globalMock.mockClear();
}
},
);
}

if (this._environment.fakeTimers) {
Expand Down

0 comments on commit c628bda

Please sign in to comment.