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

fix(jest-types): compat with @types/node v16 #11645

Merged
merged 4 commits into from Aug 27, 2021
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 @@ -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