Skip to content

Commit

Permalink
fix(jest-types): compat with @types/node v16 (#11645)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Aug 27, 2021
1 parent 321e8d5 commit 39190ea
Show file tree
Hide file tree
Showing 27 changed files with 134 additions and 114 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
- `[jest-environment-node]` Add `Event` and `EventTarget` to node global environment. ([#11705](https://github.com/facebook/jest/issues/11705))
- `[jest-mock]` Fix `spyOn` to use `Object.prototype.hasOwnProperty` [#11721](https://github.com/facebook/jest/pull/11721)
- `[jest-resolver]` Add dependency on `jest-haste-map` [#11759](https://github.com/facebook/jest/pull/11759)
- `[jest-types]` Compat with `@types/node` v16 ([#11645](https://github.com/facebook/jest/pull/11645))

### Chore & Maintenance

Expand Down
6 changes: 3 additions & 3 deletions packages/jest-console/src/BufferedConsole.ts
Expand Up @@ -7,7 +7,7 @@

import assert = require('assert');
import {Console} from 'console';
import {format, formatWithOptions, inspect} from 'util';
import {InspectOptions, format, formatWithOptions, inspect} from 'util';
import chalk = require('chalk');
import {ErrorWithStack, formatTime} from 'jest-util';
import type {
Expand All @@ -24,7 +24,7 @@ export default class BufferedConsole extends Console {
private _timers: LogTimers = {};
private _groupDepth = 0;

Console: NodeJS.ConsoleConstructor = Console;
Console: typeof Console = Console;

constructor() {
super({
Expand Down Expand Up @@ -95,7 +95,7 @@ export default class BufferedConsole extends Console {
this._log('debug', format(firstArg, ...rest));
}

dir(firstArg: unknown, options: NodeJS.InspectOptions = {}): void {
dir(firstArg: unknown, options: InspectOptions = {}): void {
const representation = inspect(firstArg, options);
this._log('dir', formatWithOptions(options, representation));
}
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-console/src/CustomConsole.ts
Expand Up @@ -7,7 +7,7 @@

import assert = require('assert');
import {Console} from 'console';
import {format, formatWithOptions, inspect} 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 All @@ -22,7 +22,7 @@ export default class CustomConsole extends Console {
private _timers: LogTimers = {};
private _groupDepth = 0;

Console: NodeJS.ConsoleConstructor = Console;
Console: typeof Console = Console;

constructor(
stdout: NodeJS.WriteStream,
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class CustomConsole extends Console {
this._log('debug', format(firstArg, ...args));
}

dir(firstArg: unknown, options: NodeJS.InspectOptions = {}): void {
dir(firstArg: unknown, options: InspectOptions = {}): void {
const representation = inspect(firstArg, options);
this._log('dir', formatWithOptions(options, representation));
}
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-each/src/index.ts
Expand Up @@ -69,7 +69,8 @@ const install = (
const each = (
table: Global.EachTable,
...data: Global.TemplateData
): ReturnType<typeof install> => install(global as Global, table, ...data);
): ReturnType<typeof install> =>
install(global as unknown as Global, table, ...data);

each.withGlobal =
(g: Global) =>
Expand Down
13 changes: 8 additions & 5 deletions packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -22,7 +22,7 @@ type Win = Window &
};
};

class JSDOMEnvironment implements JestEnvironment {
class JSDOMEnvironment implements JestEnvironment<number> {
dom: JSDOM | null;
fakeTimers: LegacyFakeTimers<number> | null;
fakeTimersModern: ModernFakeTimers | null;
Expand Down Expand Up @@ -52,14 +52,14 @@ class JSDOMEnvironment implements JestEnvironment {
}

// for "universal" code (code should use `globalThis`)
global.global = global;
global.global = global as any;

// Node's error-message stack size is limited at 10, but it's pretty useful
// to see more than that when a test fails.
this.global.Error.stackTraceLimit = 100;
installCommonGlobals(global as any, config.globals);

// TODO: remove this ASAP, but it currntly causes tests to run really slow
// TODO: remove this ASAP, but it currently causes tests to run really slow
global.Buffer = Buffer;

// Report uncaught errors.
Expand Down Expand Up @@ -101,12 +101,15 @@ class JSDOMEnvironment implements JestEnvironment {

this.fakeTimers = new LegacyFakeTimers({
config,
global,
global: global as unknown as typeof globalThis,
moduleMocker: this.moduleMocker,
timerConfig,
});

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

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

export declare class JestEnvironment {
export declare class JestEnvironment<Timer = unknown> {
constructor(config: Config.ProjectConfig, context?: EnvironmentContext);
global: Global.Global;
fakeTimers: LegacyFakeTimers<unknown> | null;
fakeTimers: LegacyFakeTimers<Timer> | null;
fakeTimersModern: ModernFakeTimers | null;
moduleMocker: ModuleMocker | null;
getVmContext(): Context | null;
Expand Down

0 comments on commit 39190ea

Please sign in to comment.