Skip to content

Commit

Permalink
revert worker changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Dec 30, 2020
1 parent 5e8ae67 commit 6e282ca
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 140 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
- `[jest-transform]` [**BREAKING**] Refactor API of transformers to pass an options bag rather than separate `config` and other options ([#10834](https://github.com/facebook/jest/pull/10834))
- `[jest-worker]` [**BREAKING**] Use named exports ([#10623] (https://github.com/facebook/jest/pull/10623))
- `[jest-worker]` Do not swallow errors during serialization ([#10984] (https://github.com/facebook/jest/pull/10984))
- `[jest-worker]` Handle passing messages with circular data ([#10981] (https://github.com/facebook/jest/pull/10981))
- `[pretty-format]` [**BREAKING**] Convert to ES Modules ([#10515](https://github.com/facebook/jest/pull/10515))

### Chore & Maintenance
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"dependencies": {
"@types/node": "*",
"merge-stream": "^2.0.0",
"supports-color": "^8.0.0",
"telejson": "^5.1.0"
"supports-color": "^8.0.0"
},
"devDependencies": {
"@types/merge-stream": "^1.1.2",
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-worker/src/workers/ChildProcessWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
WorkerInterface,
WorkerOptions,
} from '../types';
import {parse} from './utils';

const SIGNAL_BASE_EXIT_CODE = 128;
const SIGKILL_EXIT_CODE = SIGNAL_BASE_EXIT_CODE + 9;
Expand Down Expand Up @@ -163,7 +162,7 @@ export default class ChildProcessWorker implements WorkerInterface {

switch (response[0]) {
case PARENT_MESSAGE_OK:
this._onProcessEnd(null, parse(response[1]));
this._onProcessEnd(null, response[1]);
break;

case PARENT_MESSAGE_CLIENT_ERROR:
Expand Down Expand Up @@ -196,7 +195,7 @@ export default class ChildProcessWorker implements WorkerInterface {
this._onProcessEnd(error, null);
break;
case PARENT_MESSAGE_CUSTOM:
this._onCustomMessage(parse(response[1]));
this._onCustomMessage(response[1]);
break;
default:
throw new TypeError('Unexpected response from worker: ' + response[0]);
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-worker/src/workers/NodeThreadsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
WorkerInterface,
WorkerOptions,
} from '../types';
import {parse} from './utils';

export default class ExperimentalWorker implements WorkerInterface {
private _worker!: Worker;
Expand Down Expand Up @@ -142,7 +141,7 @@ export default class ExperimentalWorker implements WorkerInterface {

switch (response[0]) {
case PARENT_MESSAGE_OK:
this._onProcessEnd(null, parse(response[1]));
this._onProcessEnd(null, response[1]);
break;

case PARENT_MESSAGE_CLIENT_ERROR:
Expand Down Expand Up @@ -176,7 +175,7 @@ export default class ExperimentalWorker implements WorkerInterface {
this._onProcessEnd(error, null);
break;
case PARENT_MESSAGE_CUSTOM:
this._onCustomMessage(parse(response[1]));
this._onCustomMessage(response[1]);
break;
default:
throw new TypeError('Unexpected response from worker: ' + response[0]);
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-worker/src/workers/messageParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import {PARENT_MESSAGE_CUSTOM} from '../types';
import {serialize} from './utils';

const isWorkerThread: boolean = (() => {
try {
Expand All @@ -31,9 +30,9 @@ export default function messageParent(
parentPort,
} = require('worker_threads') as typeof import('worker_threads');
// ! is safe due to `null` check in `isWorkerThread`
parentPort!.postMessage([PARENT_MESSAGE_CUSTOM, serialize(message)]);
parentPort!.postMessage([PARENT_MESSAGE_CUSTOM, message]);
} else if (typeof parentProcess.send === 'function') {
parentProcess.send([PARENT_MESSAGE_CUSTOM, serialize(message)]);
parentProcess.send([PARENT_MESSAGE_CUSTOM, message]);
} else {
throw new Error('"messageParent" can only be used inside a worker');
}
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-worker/src/workers/processChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
PARENT_MESSAGE_OK,
PARENT_MESSAGE_SETUP_ERROR,
} from '../types';
import {serialize} from './utils';

let file: string | null = null;
let setupArgs: Array<unknown> = [];
Expand Down Expand Up @@ -65,7 +64,7 @@ function reportSuccess(result: unknown) {
throw new Error('Child can only be used on a forked process');
}

process.send([PARENT_MESSAGE_OK, serialize(result)]);
process.send([PARENT_MESSAGE_OK, result]);
}

function reportClientError(error: Error) {
Expand All @@ -87,7 +86,7 @@ function reportError(error: Error, type: PARENT_MESSAGE_ERROR) {

process.send([
type,
error.constructor?.name,
error.constructor && error.constructor.name,
error.message,
error.stack,
typeof error === 'object' ? {...error} : error,
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-worker/src/workers/threadChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
PARENT_MESSAGE_OK,
PARENT_MESSAGE_SETUP_ERROR,
} from '../types';
import {serialize} from './utils';

let file: string | null = null;
let setupArgs: Array<unknown> = [];
Expand Down Expand Up @@ -66,7 +65,7 @@ function reportSuccess(result: unknown) {
throw new Error('Child can only be used on a forked process');
}

parentPort!.postMessage([PARENT_MESSAGE_OK, serialize(result)]);
parentPort!.postMessage([PARENT_MESSAGE_OK, result]);
}

function reportClientError(error: Error) {
Expand Down
34 changes: 0 additions & 34 deletions packages/jest-worker/src/workers/utils.ts

This file was deleted.

91 changes: 2 additions & 89 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3605,13 +3605,6 @@ __metadata:
languageName: node
linkType: hard

"@types/is-function@npm:^1.0.0":
version: 1.0.0
resolution: "@types/is-function@npm:1.0.0"
checksum: 6cfa84eac88803fc3fcff37f452fa9fd029f434d6fee75db265b0e67603c781c8fa646b8a1f5056c307ac16313ead1c7f06c884ddee27bba7ec6c0362ce4f516
languageName: node
linkType: hard

"@types/istanbul-lib-coverage@npm:*, @types/istanbul-lib-coverage@npm:^2.0.0, @types/istanbul-lib-coverage@npm:^2.0.1":
version: 2.0.3
resolution: "@types/istanbul-lib-coverage@npm:2.0.3"
Expand Down Expand Up @@ -7519,13 +7512,6 @@ __metadata:
languageName: node
linkType: hard

"dom-walk@npm:^0.1.0":
version: 0.1.2
resolution: "dom-walk@npm:0.1.2"
checksum: 948c7527f3798cae9d7039cc0e5dc9f013ebd701d7d99478bac79d7d9eb8b81e7b6e836526e21ed9b156466b268e30ea0f2d5b72df955fabec3ce2aa7dc0086e
languageName: node
linkType: hard

"domelementtype@npm:1, domelementtype@npm:^1.3.0, domelementtype@npm:^1.3.1":
version: 1.3.1
resolution: "domelementtype@npm:1.3.1"
Expand Down Expand Up @@ -9816,16 +9802,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"global@npm:^4.4.0":
version: 4.4.0
resolution: "global@npm:4.4.0"
dependencies:
min-document: ^2.19.0
process: ^0.11.10
checksum: da0cf92ef034b63cf4d0fe5e14cb71bc4c748b8c1bbeabe4061443562ba8e9027774f8074e66543fa98f0d965da6d11e0861e3bf8c628b7ab19220e8ee18cc71
languageName: node
linkType: hard

"globals@npm:^11.1.0":
version: 11.12.0
resolution: "globals@npm:11.12.0"
Expand Down Expand Up @@ -11069,13 +11045,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"is-function@npm:^1.0.2":
version: 1.0.2
resolution: "is-function@npm:1.0.2"
checksum: 894562b5e4dcf3544eb0b5c26ba94e08c99007728059782f5e863296e865af9b7d2bcad06057d20bb862943dcfc9bb1387fedb4cdc953af93bd0a70ad61a3ba1
languageName: node
linkType: hard

"is-generator-fn@npm:^2.0.0":
version: 2.1.0
resolution: "is-generator-fn@npm:2.1.0"
Expand Down Expand Up @@ -11351,7 +11320,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"is-symbol@npm:^1.0.2, is-symbol@npm:^1.0.3":
"is-symbol@npm:^1.0.2":
version: 1.0.3
resolution: "is-symbol@npm:1.0.3"
dependencies:
Expand Down Expand Up @@ -11482,13 +11451,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"isobject@npm:^4.0.0":
version: 4.0.0
resolution: "isobject@npm:4.0.0"
checksum: bfc8e8f6e2bebf7d85e4bec91497e24f87e6b33576d03e223ff6ce1679f5a7dc6f357fdb3e1c6c6d85fc6f0feac26acca9e9e7b0ab473ea60fa3f838c203ee01
languageName: node
linkType: hard

"isomorphic-fetch@npm:^2.1.1":
version: 2.2.1
resolution: "isomorphic-fetch@npm:2.2.1"
Expand Down Expand Up @@ -12372,7 +12334,6 @@ fsevents@^1.2.7:
get-stream: ^6.0.0
merge-stream: ^2.0.0
supports-color: ^8.0.0
telejson: ^5.1.0
worker-farm: ^1.6.0
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -13170,7 +13131,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"lodash@npm:^4.15.0, lodash@npm:^4.17.12, lodash@npm:^4.17.14, lodash@npm:^4.17.15, lodash@npm:^4.17.19, lodash@npm:^4.17.20, lodash@npm:^4.17.4, lodash@npm:^4.2.1, lodash@npm:^4.3.0, lodash@npm:~4.17.10":
"lodash@npm:^4.15.0, lodash@npm:^4.17.12, lodash@npm:^4.17.14, lodash@npm:^4.17.15, lodash@npm:^4.17.19, lodash@npm:^4.17.4, lodash@npm:^4.2.1, lodash@npm:^4.3.0, lodash@npm:~4.17.10":
version: 4.17.20
resolution: "lodash@npm:4.17.20"
checksum: c62101d2500c383b5f174a7e9e6fe8098149ddd6e9ccfa85f36d4789446195f5c4afd3cfba433026bcaf3da271256566b04a2bf2618e5a39f6e67f8c12030cb6
Expand Down Expand Up @@ -13416,13 +13377,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"map-or-similar@npm:^1.5.0":
version: 1.5.0
resolution: "map-or-similar@npm:1.5.0"
checksum: 3d759eff8025ad5d1e96acc618379f4664be56abdcca1d4f08a8e8df7c3ca6359acbc117611279d972405c0b4347ab28a6724c666dd25006f745bf487dc261d7
languageName: node
linkType: hard

"map-visit@npm:^1.0.0":
version: 1.0.0
resolution: "map-visit@npm:1.0.0"
Expand Down Expand Up @@ -13505,15 +13459,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"memoizerific@npm:^1.11.3":
version: 1.11.3
resolution: "memoizerific@npm:1.11.3"
dependencies:
map-or-similar: ^1.5.0
checksum: 6601aab4719d269884882b24fc94d33da054817b6472b586dc9117773661abf838f838f5b80d202b8d84f942bcac63421a3044ef31f1af9790eed3f32e33eac6
languageName: node
linkType: hard

"memory-pager@npm:^1.0.2":
version: 1.5.0
resolution: "memory-pager@npm:1.5.0"
Expand Down Expand Up @@ -14123,15 +14068,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"min-document@npm:^2.19.0":
version: 2.19.0
resolution: "min-document@npm:2.19.0"
dependencies:
dom-walk: ^0.1.0
checksum: 8da883996e00a53729e867dad45a358c6d8b3b55f2473a20768c1a2b4642d0983bc61827cf29eb98c53d7290c2a1a74a5cba60873857da416bdfae09bf73bb21
languageName: node
linkType: hard

"min-indent@npm:^1.0.0":
version: 1.0.1
resolution: "min-indent@npm:1.0.1"
Expand Down Expand Up @@ -16299,13 +16235,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"process@npm:^0.11.10":
version: 0.11.10
resolution: "process@npm:0.11.10"
checksum: ed93a85e9185b40fb01788c588a87c1a9da0eb925ef7cebebbe1b8bbf0eba1802130366603a29e3b689c116969d4fe018de6aed3474bbeb5aefb3716b85d6449
languageName: node
linkType: hard

"progress@npm:^2.0.0":
version: 2.0.3
resolution: "progress@npm:2.0.3"
Expand Down Expand Up @@ -18888,22 +18817,6 @@ [email protected]:
languageName: node
linkType: hard

"telejson@npm:^5.1.0":
version: 5.1.0
resolution: "telejson@npm:5.1.0"
dependencies:
"@types/is-function": ^1.0.0
global: ^4.4.0
is-function: ^1.0.2
is-regex: ^1.1.1
is-symbol: ^1.0.3
isobject: ^4.0.0
lodash: ^4.17.20
memoizerific: ^1.11.3
checksum: 6e74253262887cfc85098ded1f6cda053a8183fb3885ceda9b56e18a35736aa81ce73204d783a474a0457b1f1b5b1ebd0dd54abb8731de49f4df6515bba4638c
languageName: node
linkType: hard

"temp-dir@npm:^1.0.0":
version: 1.0.0
resolution: "temp-dir@npm:1.0.0"
Expand Down

0 comments on commit 6e282ca

Please sign in to comment.