diff --git a/__tests__/integration.spec.js b/__tests__/integration.spec.js index a6d8349..f035d48 100644 --- a/__tests__/integration.spec.js +++ b/__tests__/integration.spec.js @@ -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/); + }); }); }); diff --git a/__tests__/stubs/LargeTestImage.png b/__tests__/stubs/LargeTestImage.png new file mode 100644 index 0000000..3044e7f Binary files /dev/null and b/__tests__/stubs/LargeTestImage.png differ diff --git a/__tests__/stubs/LargeTestImageFailure.png b/__tests__/stubs/LargeTestImageFailure.png new file mode 100644 index 0000000..460148d Binary files /dev/null and b/__tests__/stubs/LargeTestImageFailure.png differ diff --git a/src/diff-snapshot.js b/src/diff-snapshot.js index 0c56041..40f2407 100644 --- a/src/diff-snapshot.js +++ b/src/diff-snapshot.js @@ -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) {