Skip to content

Commit 39190ea

Browse files
authored
fix(jest-types): compat with @types/node v16 (#11645)
1 parent 321e8d5 commit 39190ea

File tree

27 files changed

+134
-114
lines changed

27 files changed

+134
-114
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `[jest-environment-node]` Add `Event` and `EventTarget` to node global environment. ([#11705](https://github.com/facebook/jest/issues/11705))
1111
- `[jest-mock]` Fix `spyOn` to use `Object.prototype.hasOwnProperty` [#11721](https://github.com/facebook/jest/pull/11721)
1212
- `[jest-resolver]` Add dependency on `jest-haste-map` [#11759](https://github.com/facebook/jest/pull/11759)
13+
- `[jest-types]` Compat with `@types/node` v16 ([#11645](https://github.com/facebook/jest/pull/11645))
1314

1415
### Chore & Maintenance
1516

packages/jest-console/src/BufferedConsole.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import assert = require('assert');
99
import {Console} from 'console';
10-
import {format, formatWithOptions, inspect} from 'util';
10+
import {InspectOptions, format, formatWithOptions, inspect} from 'util';
1111
import chalk = require('chalk');
1212
import {ErrorWithStack, formatTime} from 'jest-util';
1313
import type {
@@ -24,7 +24,7 @@ export default class BufferedConsole extends Console {
2424
private _timers: LogTimers = {};
2525
private _groupDepth = 0;
2626

27-
Console: NodeJS.ConsoleConstructor = Console;
27+
Console: typeof Console = Console;
2828

2929
constructor() {
3030
super({
@@ -95,7 +95,7 @@ export default class BufferedConsole extends Console {
9595
this._log('debug', format(firstArg, ...rest));
9696
}
9797

98-
dir(firstArg: unknown, options: NodeJS.InspectOptions = {}): void {
98+
dir(firstArg: unknown, options: InspectOptions = {}): void {
9999
const representation = inspect(firstArg, options);
100100
this._log('dir', formatWithOptions(options, representation));
101101
}

packages/jest-console/src/CustomConsole.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import assert = require('assert');
99
import {Console} from 'console';
10-
import {format, formatWithOptions, inspect} from 'util';
10+
import {InspectOptions, format, formatWithOptions, inspect} from 'util';
1111
import chalk = require('chalk');
1212
import {clearLine, formatTime} from 'jest-util';
1313
import type {LogCounters, LogMessage, LogTimers, LogType} from './types';
@@ -22,7 +22,7 @@ export default class CustomConsole extends Console {
2222
private _timers: LogTimers = {};
2323
private _groupDepth = 0;
2424

25-
Console: NodeJS.ConsoleConstructor = Console;
25+
Console: typeof Console = Console;
2626

2727
constructor(
2828
stdout: NodeJS.WriteStream,
@@ -73,7 +73,7 @@ export default class CustomConsole extends Console {
7373
this._log('debug', format(firstArg, ...args));
7474
}
7575

76-
dir(firstArg: unknown, options: NodeJS.InspectOptions = {}): void {
76+
dir(firstArg: unknown, options: InspectOptions = {}): void {
7777
const representation = inspect(firstArg, options);
7878
this._log('dir', formatWithOptions(options, representation));
7979
}

packages/jest-each/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const install = (
6969
const each = (
7070
table: Global.EachTable,
7171
...data: Global.TemplateData
72-
): ReturnType<typeof install> => install(global as Global, table, ...data);
72+
): ReturnType<typeof install> =>
73+
install(global as unknown as Global, table, ...data);
7374

7475
each.withGlobal =
7576
(g: Global) =>

packages/jest-environment-jsdom/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Win = Window &
2222
};
2323
};
2424

25-
class JSDOMEnvironment implements JestEnvironment {
25+
class JSDOMEnvironment implements JestEnvironment<number> {
2626
dom: JSDOM | null;
2727
fakeTimers: LegacyFakeTimers<number> | null;
2828
fakeTimersModern: ModernFakeTimers | null;
@@ -52,14 +52,14 @@ class JSDOMEnvironment implements JestEnvironment {
5252
}
5353

5454
// for "universal" code (code should use `globalThis`)
55-
global.global = global;
55+
global.global = global as any;
5656

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

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

6565
// Report uncaught errors.
@@ -101,12 +101,15 @@ class JSDOMEnvironment implements JestEnvironment {
101101

102102
this.fakeTimers = new LegacyFakeTimers({
103103
config,
104-
global,
104+
global: global as unknown as typeof globalThis,
105105
moduleMocker: this.moduleMocker,
106106
timerConfig,
107107
});
108108

109-
this.fakeTimersModern = new ModernFakeTimers({config, global});
109+
this.fakeTimersModern = new ModernFakeTimers({
110+
config,
111+
global: global as unknown as typeof globalThis,
112+
});
110113
}
111114

112115
async setup(): Promise<void> {}

packages/jest-environment/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export type ModuleWrapper = (
3232
...extraGlobals: Array<Global.Global[keyof Global.Global]>
3333
) => unknown;
3434

35-
export declare class JestEnvironment {
35+
export declare class JestEnvironment<Timer = unknown> {
3636
constructor(config: Config.ProjectConfig, context?: EnvironmentContext);
3737
global: Global.Global;
38-
fakeTimers: LegacyFakeTimers<unknown> | null;
38+
fakeTimers: LegacyFakeTimers<Timer> | null;
3939
fakeTimersModern: ModernFakeTimers | null;
4040
moduleMocker: ModuleMocker | null;
4141
getVmContext(): Context | null;

0 commit comments

Comments
 (0)