diff --git a/README.md b/README.md index f59a5ef..76b5ee6 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ See [the examples](./examples/README.md) for more detailed usage or read about a * `dumpDiffToConsole`: (default `false`) Will output base64 string of a diff image to console in case of failed tests (in addition to creating a diff image). This string can be copy-pasted to a browser address string to preview the diff for a failed test. * `dumpInlineDiffToConsole`: (default `false`) Will output the image to the terminal using iTerm's [Inline Images Protocol](https://iterm2.com/documentation-images.html). If the term is not compatible, it does the same thing as `dumpDiffToConsole`. * `allowSizeMismatch`: (default `false`) If set to true, the build will not fail when the screenshots to compare have different sizes. +* `maxChildProcessBufferSizeInBytes`: (default `10 * 1024 * 1024`) Sets the max number of bytes for stdout/stderr when running `diff-snapshot` in a child process. * `runtimeHooksPath`: (default `undefined`) This needs to be set to a existing file, like `require.resolve('./runtimeHooksPath.cjs')`. This file can expose a few hooks: * `onBeforeWriteToDisc`: before saving any image to the disc, this function will be called (can be used to write EXIF data to images for instance) `onBeforeWriteToDisc: (arguments: { buffer: Buffer; destination: string; testPath: string; currentTestName: string }) => Buffer` diff --git a/__tests__/__image_snapshots__/cleanup-required-7.png b/__tests__/__image_snapshots__/cleanup-required-7.png new file mode 100644 index 0000000..3044e7f Binary files /dev/null and b/__tests__/__image_snapshots__/cleanup-required-7.png differ diff --git a/__tests__/__snapshots__/index.spec.js.snap b/__tests__/__snapshots__/index.spec.js.snap index eed6cce..8c8ed09 100644 --- a/__tests__/__snapshots__/index.spec.js.snap +++ b/__tests__/__snapshots__/index.spec.js.snap @@ -48,6 +48,7 @@ exports[`toMatchImageSnapshot passes diffImageToSnapshot everything it needs to "diffDirection": "horizontal", "failureThreshold": 0, "failureThresholdType": "pixel", + "maxChildProcessBufferSizeInBytes": 10485760, "onlyDiff": false, "receivedDir": undefined, "receivedImageBuffer": "pretendthisisanimagebuffer", diff --git a/__tests__/index.spec.js b/__tests__/index.spec.js index a52de5a..2b110d2 100644 --- a/__tests__/index.spec.js +++ b/__tests__/index.spec.js @@ -448,6 +448,7 @@ describe('toMatchImageSnapshot', () => { onlyDiff: false, failureThreshold: 0, failureThresholdType: 'pixel', + maxChildProcessBufferSizeInBytes: 10 * 1024 * 1024, receivedDir: undefined, receivedImageBuffer: undefined, runtimeHooksPath: undefined, @@ -500,6 +501,7 @@ describe('toMatchImageSnapshot', () => { failureThresholdType: 'percent', updatePassedSnapshot: true, blur: 1, + maxChildProcessBufferSizeInBytes: 1024 * 1024, comparisonMethod, }); expect.extend({ toMatchImageSnapshot }); @@ -528,6 +530,7 @@ describe('toMatchImageSnapshot', () => { updatePassedSnapshot: true, failureThreshold: 1, failureThresholdType: 'percent', + maxChildProcessBufferSizeInBytes: 1024 * 1024, comparisonMethod, }); expect(Chalk).toHaveBeenCalledWith({ @@ -590,6 +593,7 @@ describe('toMatchImageSnapshot', () => { testPath: path.join('path', 'to', 'test.spec.js'), updateSnapshot: false, updatePassedSnapshot: false, + maxChildProcessBufferSizeInBytes: 10 * 1024 * 1024, failureThreshold: 0, failureThresholdType: 'pixel', comparisonMethod: 'pixelmatch', diff --git a/src/diff-snapshot.js b/src/diff-snapshot.js index fb25f4d..3bf0b36 100644 --- a/src/diff-snapshot.js +++ b/src/diff-snapshot.js @@ -421,7 +421,7 @@ function runDiffImageToSnapshot(options) { { input: Buffer.from(serializedInput), stdio: ['pipe', 'inherit', 'inherit', 'pipe'], - maxBuffer: 10 * 1024 * 1024, // 10 MB + maxBuffer: options.maxChildProcessBufferSizeInBytes, } ); diff --git a/src/index.js b/src/index.js index 4a5aa6a..537193e 100644 --- a/src/index.js +++ b/src/index.js @@ -151,6 +151,10 @@ function configureToMatchImageSnapshot({ dumpDiffToConsole: commonDumpDiffToConsole = false, dumpInlineDiffToConsole: commonDumpInlineDiffToConsole = false, allowSizeMismatch: commonAllowSizeMismatch = false, + // Default to 10 MB instead of node's default 1 MB + // See https://nodejs.org/api/child_process.html#child_processspawnsynccommand-args-options + maxChildProcessBufferSizeInBytes: + commonMaxChildProcessBufferSizeInBytes = 10 * 1024 * 1024, // 10 MB comparisonMethod: commonComparisonMethod = 'pixelmatch', } = {}) { return function toMatchImageSnapshot(received, { @@ -173,6 +177,7 @@ function configureToMatchImageSnapshot({ dumpDiffToConsole = commonDumpDiffToConsole, dumpInlineDiffToConsole = commonDumpInlineDiffToConsole, allowSizeMismatch = commonAllowSizeMismatch, + maxChildProcessBufferSizeInBytes = commonMaxChildProcessBufferSizeInBytes, comparisonMethod = commonComparisonMethod, } = {}) { const { @@ -237,6 +242,7 @@ function configureToMatchImageSnapshot({ updatePassedSnapshot, blur, allowSizeMismatch, + maxChildProcessBufferSizeInBytes, comparisonMethod, runtimeHooksPath, });