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(worker): support v12 node typings #10336

Merged
merged 5 commits into from Jul 30, 2020
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"@types/which": "^1.3.2",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
Expand Down
1 change: 1 addition & 0 deletions packages/jest-core/src/collectHandles.ts
Expand Up @@ -63,6 +63,7 @@ export default function collectHandles(): () => Array<Error> {
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
Expand Down
1 change: 1 addition & 0 deletions packages/jest-runtime/package.json
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions packages/jest-worker/src/types.ts
Expand Up @@ -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
Expand Down Expand Up @@ -66,7 +73,7 @@ export interface PromiseWithCustomMessage<T> extends Promise<T> {

// Option objects.

export type {ForkOptions, ResourceLimits};
export type {ForkOptions};

export type FarmOptions = {
computeWorkerKey?: (method: string, ...args: Array<unknown>) => string | null;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-worker/src/workers/NodeThreadsWorker.ts
Expand Up @@ -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,
Expand Down
18 changes: 13 additions & 5 deletions yarn.lock
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down