From 2db6aa11ef482167cd84114c2ec3b93a3da5f82f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 30 Jul 2020 13:33:00 +0200 Subject: [PATCH] fix(worker): support v12 node typings (#10336) --- CHANGELOG.md | 2 ++ package.json | 2 +- packages/jest-core/src/collectHandles.ts | 1 + packages/jest-runtime/package.json | 1 + packages/jest-worker/src/types.ts | 11 +++++++++-- .../src/workers/NodeThreadsWorker.ts | 1 + yarn.lock | 18 +++++++++++++----- 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4b871dc8589..d6ac3c21746e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-worker]` Make sure to work with Node TS typings v12 ([#10336](https://github.com/facebook/jest/pull/10336)) + ### Chore & Maintenance ### Performance diff --git a/package.json b/package.json index 8367866f7c0b..55cba314c73f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@types/babel__template": "^7.0.0", "@types/dedent": "0.7.0", "@types/jest": "24.0.2", - "@types/node": "*", + "@types/node": "~10.14.0", "@types/which": "^1.3.2", "@typescript-eslint/eslint-plugin": "^2.30.0", "@typescript-eslint/parser": "^2.30.0", diff --git a/packages/jest-core/src/collectHandles.ts b/packages/jest-core/src/collectHandles.ts index 6cb0f8eb99e6..3575387e28da 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -63,6 +63,7 @@ export default function collectHandles(): () => Array { if (type === 'Timeout' || type === 'Immediate') { if ('hasRef' in resource) { // Timer that supports hasRef (Node v11+) + // @ts-expect-error: doesn't exist in v10 typings isActive = resource.hasRef.bind(resource); } else { // Timer that doesn't support hasRef diff --git a/packages/jest-runtime/package.json b/packages/jest-runtime/package.json index 9abb02523c08..dc16886ad953 100644 --- a/packages/jest-runtime/package.json +++ b/packages/jest-runtime/package.json @@ -42,6 +42,7 @@ "@types/exit": "^0.1.30", "@types/glob": "^7.1.1", "@types/graceful-fs": "^4.1.2", + "@types/node": "^14.0.27", "execa": "^4.0.0", "jest-environment-node": "^26.2.0", "jest-snapshot-serializer-raw": "^1.1.0" diff --git a/packages/jest-worker/src/types.ts b/packages/jest-worker/src/types.ts index 5242ec0f2c97..af59e7fd87ef 100644 --- a/packages/jest-worker/src/types.ts +++ b/packages/jest-worker/src/types.ts @@ -7,7 +7,14 @@ import type {EventEmitter} from 'events'; import type {ForkOptions} from 'child_process'; -import type {ResourceLimits} from 'worker_threads'; + +// import type {ResourceLimits} from 'worker_threads'; +// This is not present in the Node 12 typings +export interface ResourceLimits { + maxYoungGenerationSizeMb?: number; + maxOldGenerationSizeMb?: number; + codeRangeSizeMb?: number; +} // Because of the dynamic nature of a worker communication process, all messages // coming from any of the other processes cannot be typed. Thus, many types @@ -66,7 +73,7 @@ export interface PromiseWithCustomMessage extends Promise { // Option objects. -export type {ForkOptions, ResourceLimits}; +export type {ForkOptions}; export type FarmOptions = { computeWorkerKey?: (method: string, ...args: Array) => string | null; diff --git a/packages/jest-worker/src/workers/NodeThreadsWorker.ts b/packages/jest-worker/src/workers/NodeThreadsWorker.ts index ab964d1730e4..9d1920819766 100644 --- a/packages/jest-worker/src/workers/NodeThreadsWorker.ts +++ b/packages/jest-worker/src/workers/NodeThreadsWorker.ts @@ -62,6 +62,7 @@ export default class ExperimentalWorker implements WorkerInterface { initialize(): void { this._worker = new Worker(path.resolve(__dirname, './threadChild.js'), { eval: false, + // @ts-expect-error: added in newer versions resourceLimits: this._options.resourceLimits, stderr: true, stdout: true, diff --git a/yarn.lock b/yarn.lock index c814ede49bb9..c3169d94b757 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3476,10 +3476,17 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:>= 8": - version: 13.13.4 - resolution: "@types/node@npm:13.13.4" - checksum: dc52acb5f3d9c8577abdaf682bb85d3731a090b503e1b5abde62ba426f5d556fa655a1255ebb91cfdd36060205631eb7e7d7daf185e6ebab1ff9f6f4a0605170 +"@types/node@npm:*, @types/node@npm:>= 8, @types/node@npm:~10.14.0": + version: 10.14.22 + resolution: "@types/node@npm:10.14.22" + checksum: 392965766fc7f221169d62e4dafbfc875ba172ce610ac48fec26eaf572386913bd2c5d2e036bb747bb49923f1ade9eed2b2d09a391cbf5fbaaa864a74a4dad60 + languageName: node + linkType: hard + +"@types/node@npm:^14.0.27": + version: 14.0.27 + resolution: "@types/node@npm:14.0.27" + checksum: 54ecf408eb94f44685e12ef395d8d9d5789cb9e209f171153b6b951272af6b8da099778d09d66454aa5d35ce246f3922ebd7476ed768bf3bd4267306c12a6703 languageName: node linkType: hard @@ -11496,6 +11503,7 @@ fsevents@^1.2.7: "@types/exit": ^0.1.30 "@types/glob": ^7.1.1 "@types/graceful-fs": ^4.1.2 + "@types/node": ^14.0.27 "@types/yargs": ^15.0.0 chalk: ^4.0.0 collect-v8-coverage: ^1.0.0 @@ -16454,7 +16462,7 @@ fsevents@^1.2.7: "@types/babel__template": ^7.0.0 "@types/dedent": 0.7.0 "@types/jest": 24.0.2 - "@types/node": "*" + "@types/node": ~10.14.0 "@types/which": ^1.3.2 "@typescript-eslint/eslint-plugin": ^2.30.0 "@typescript-eslint/parser": ^2.30.0