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

[jest-worker]: bigInt serialization in jest-worker #11624

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: use json-bigint for serialization
  • Loading branch information
sauravhiremath committed Sep 18, 2021
commit f4a5c7c82b7cb0e2c2d15e532b6cde2b4afa1426
2 changes: 2 additions & 0 deletions packages/jest-worker/package.json
Original file line number Diff line number Diff line change
@@ -15,10 +15,12 @@
},
"dependencies": {
"@types/node": "*",
"json-bigint": "^1.0.0",
"merge-stream": "^2.0.0",
"supports-color": "^8.0.0"
},
"devDependencies": {
"@types/json-bigint": "^1.0.1",
"@types/merge-stream": "^1.1.2",
"@types/supports-color": "^8.1.0",
"get-stream": "^6.0.0",
6 changes: 2 additions & 4 deletions packages/jest-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
/* eslint-disable local/ban-types-eventually */

import {cpus} from 'os';
import * as JSONbig from 'json-bigint';
import Farm from './Farm';
import WorkerPool from './WorkerPool';
import type {
@@ -46,10 +47,7 @@ function getExposedMethods(
}

export function serializerWithBigInt(data: unknown): unknown {
Copy link
Member

Choose a reason for hiding this comment

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

this should not be in index to avoid circular dependencies. Please stick it into a utils, serializers or something

if (typeof data === 'bigint') {
return data.toString();
}
return data;
return JSONbig.parse(JSONbig.stringify(data));
}

/**
4 changes: 2 additions & 2 deletions packages/jest-worker/src/workers/processChild.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {serializeBigInt} from '../index';
import {serializerWithBigInt} from '..';
import {
CHILD_MESSAGE_CALL,
CHILD_MESSAGE_END,
@@ -65,7 +65,7 @@ function reportSuccess(result: unknown) {
throw new Error('Child can only be used on a forked process');
}

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

function reportClientError(error: Error) {
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -4648,6 +4648,13 @@ __metadata:
languageName: node
linkType: hard

"@types/json-bigint@npm:^1.0.1":
version: 1.0.1
resolution: "@types/json-bigint@npm:1.0.1"
checksum: 374924d3a3c8620a282c8145751ef60d9daa7b627a0991e88f6a955f7d477853d2fdb9781ac125fa0bf8d2a0cc5edc1e063dcff5619332b9eb94661e0e7196f2
languageName: node
linkType: hard

"@types/json-schema@npm:*, @types/json-schema@npm:^7.0.5, @types/json-schema@npm:^7.0.7, @types/json-schema@npm:^7.0.8":
version: 7.0.9
resolution: "@types/json-schema@npm:7.0.9"
@@ -6414,6 +6421,13 @@ __metadata:
languageName: node
linkType: hard

"bignumber.js@npm:^9.0.0":
version: 9.0.1
resolution: "bignumber.js@npm:9.0.1"
checksum: 605e9639c413f344c37b23e919254f60a5017cc5ccd925e2f8fb79b36aa3d54f356df9c726f38465263236455f685d60dcf38dbe32cb0b7e4d2a32c94b035476
languageName: node
linkType: hard

"binary-extensions@npm:^1.0.0":
version: 1.13.1
resolution: "binary-extensions@npm:1.13.1"
@@ -13313,11 +13327,13 @@ fsevents@^1.2.7:
version: 0.0.0-use.local
resolution: "jest-worker@workspace:packages/jest-worker"
dependencies:
"@types/json-bigint": ^1.0.1
"@types/merge-stream": ^1.1.2
"@types/node": "*"
"@types/supports-color": ^8.1.0
get-stream: ^6.0.0
jest-leak-detector: ^27.2.0
json-bigint: ^1.0.0
merge-stream: ^2.0.0
supports-color: ^8.0.0
worker-farm: ^1.6.0
@@ -13535,6 +13551,15 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"json-bigint@npm:^1.0.0":
version: 1.0.0
resolution: "json-bigint@npm:1.0.0"
dependencies:
bignumber.js: ^9.0.0
checksum: f6c550e09f25416d07d888db88e3cec6c13443b4c0ed5a903dc39b9870fc5adc77aecc30a2d4373888abce7526410a42b0bcf926382a399a285686163a479801
languageName: node
linkType: hard

"json-buffer@npm:3.0.0":
version: 3.0.0
resolution: "json-buffer@npm:3.0.0"