diff --git a/src/__snapshots__/multiple-comparison-with-mask-first.png b/src/__snapshots__/multiple-comparison-with-mask-first.png new file mode 100644 index 0000000..ff00a77 Binary files /dev/null and b/src/__snapshots__/multiple-comparison-with-mask-first.png differ diff --git a/src/__snapshots__/multiple-comparison-with-mask-second.png b/src/__snapshots__/multiple-comparison-with-mask-second.png new file mode 100644 index 0000000..ff00a77 Binary files /dev/null and b/src/__snapshots__/multiple-comparison-with-mask-second.png differ diff --git a/src/compare-pdf-to-snapshot.test.ts b/src/compare-pdf-to-snapshot.test.ts index 0ce0791..43e582d 100644 --- a/src/compare-pdf-to-snapshot.test.ts +++ b/src/compare-pdf-to-snapshot.test.ts @@ -1,6 +1,6 @@ import { describe, it } from 'node:test' import * as assert from 'node:assert/strict' -import { Jimp, JimpInstance } from 'jimp' +import { Jimp, JimpInstance, diff } from 'jimp' import { comparePdfToSnapshot, snapshotsDirName, @@ -192,5 +192,23 @@ describe('comparePdfToSnapshot()', () => { ) .then(() => unlinkSync(snapshotPath)) }) + + // https://github.com/moshensky/pdf-visual-diff/issues/71 + it('should apply mask at correct positions if doing multiple PDF comparisons in a single spec file', () => { + const snapshotName1 = 'multiple-comparison-with-mask-first' + const snapshotName2 = 'multiple-comparison-with-mask-second' + const snapshotPath1 = join(__dirname, snapshotsDirName, snapshotName1 + '.png') + const snapshotPath2 = join(__dirname, snapshotsDirName, snapshotName2 + '.png') + + return comparePdfToSnapshot(singlePagePdfPath, __dirname, snapshotName1, opts) + .then((x) => assert.strictEqual(x, true)) + .then(() => comparePdfToSnapshot(singlePagePdfPath, __dirname, snapshotName2, opts)) + .then((x) => assert.strictEqual(x, true)) + .then(() => Promise.all([Jimp.read(snapshotPath1), Jimp.read(snapshotPath2)])) + .then(([img1, img2]) => { + const diffResult = diff(img1, img2) + assert.equal(diffResult.percent, 0) + }) + }) }) })