Skip to content

Commit

Permalink
feat(diff): increase the maxBuffer to 10MB for the diff process (#167)
Browse files Browse the repository at this point in the history
By default, Node's spawnSync has a maxBuffer of 1 MB. This bumps it up
to 10 MB, which should reduce the chance of diffs on large images
failing.
  • Loading branch information
anescobar1991 committed Feb 8, 2020
2 parents cdd34e6 + 826ea3a commit 0927826
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions __tests__/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,20 @@ describe('toMatchImageSnapshot', () => {

expect(diffExists(customSnapshotIdentifier)).toBe(false);
});

it('handles diffs for large images', () => {
const largeImageData = fs.readFileSync(fromStubs('LargeTestImage.png'));
const largeFailureImageData = fs.readFileSync(fromStubs('LargeTestImageFailure.png'));
const customSnapshotIdentifier = getIdentifierIndicatingCleanupIsRequired();
// First we need to write a new snapshot image
expect(
() => expect(largeImageData).toMatchImageSnapshot({ customSnapshotIdentifier })
).not.toThrowError();

// then test against a different image
expect(
() => expect(largeFailureImageData).toMatchImageSnapshot({ customSnapshotIdentifier })
).toThrow(/Expected image to match or be a close match/);
});
});
});
Binary file added __tests__/stubs/LargeTestImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/stubs/LargeTestImageFailure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/diff-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ function runDiffImageToSnapshot(options) {

const writeDiffProcess = childProcess.spawnSync(
process.execPath, [`${__dirname}/diff-process.js`],
{ input: Buffer.from(serializedInput), stdio: ['pipe', 'inherit', 'inherit', 'pipe'] }
{
input: Buffer.from(serializedInput),
stdio: ['pipe', 'inherit', 'inherit', 'pipe'],
maxBuffer: 10 * 1024 * 1024, // 10 MB
}
);

if (writeDiffProcess.status === 0) {
Expand Down

0 comments on commit 0927826

Please sign in to comment.