Skip to content

Commit 0927826

Browse files
feat(diff): increase the maxBuffer to 10MB for the diff process (#167)
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.
2 parents cdd34e6 + 826ea3a commit 0927826

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

__tests__/integration.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,20 @@ describe('toMatchImageSnapshot', () => {
306306

307307
expect(diffExists(customSnapshotIdentifier)).toBe(false);
308308
});
309+
310+
it('handles diffs for large images', () => {
311+
const largeImageData = fs.readFileSync(fromStubs('LargeTestImage.png'));
312+
const largeFailureImageData = fs.readFileSync(fromStubs('LargeTestImageFailure.png'));
313+
const customSnapshotIdentifier = getIdentifierIndicatingCleanupIsRequired();
314+
// First we need to write a new snapshot image
315+
expect(
316+
() => expect(largeImageData).toMatchImageSnapshot({ customSnapshotIdentifier })
317+
).not.toThrowError();
318+
319+
// then test against a different image
320+
expect(
321+
() => expect(largeFailureImageData).toMatchImageSnapshot({ customSnapshotIdentifier })
322+
).toThrow(/Expected image to match or be a close match/);
323+
});
309324
});
310325
});

__tests__/stubs/LargeTestImage.png

456 KB
Loading
442 KB
Loading

src/diff-snapshot.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ function runDiffImageToSnapshot(options) {
240240

241241
const writeDiffProcess = childProcess.spawnSync(
242242
process.execPath, [`${__dirname}/diff-process.js`],
243-
{ input: Buffer.from(serializedInput), stdio: ['pipe', 'inherit', 'inherit', 'pipe'] }
243+
{
244+
input: Buffer.from(serializedInput),
245+
stdio: ['pipe', 'inherit', 'inherit', 'pipe'],
246+
maxBuffer: 10 * 1024 * 1024, // 10 MB
247+
}
244248
);
245249

246250
if (writeDiffProcess.status === 0) {

0 commit comments

Comments
 (0)