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

Increase the maxBuffer to 10MB for the diff process #167

Merged
merged 3 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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