Skip to content

Commit

Permalink
chore: add a script to patch jest-worker for bigint assertion messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mkazlauskas committed Feb 9, 2022
1 parent d6f052c commit de488b1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/patch-jest-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// See https://github.com/facebook/jest/issues/11617
const fs = require('fs');
const path = require('path');

const pathToMessageParentJs = path.join(__dirname, '../node_modules/jest-worker/build/workers/messageParent.js');

const originalContents = fs.readFileSync(pathToMessageParentJs).toString();
const patch = `try {
parentProcess.send([_types().PARENT_MESSAGE_CUSTOM, message]);
} catch (error) {
console.error('jest-worker message serialisation failed', error);
console.dir(message, {depth: 10});
throw error;
}`;

if (originalContents.includes(patch)) {
console.log(pathToMessageParentJs, 'is already patched, nothing to do...');
} else {
const patchedContents = originalContents.replace(
'parentProcess.send([_types().PARENT_MESSAGE_CUSTOM, message]);',
patch
);

fs.writeFileSync(pathToMessageParentJs, patchedContents);
console.log(pathToMessageParentJs, 'successfully patched!');
}

0 comments on commit de488b1

Please sign in to comment.