From cd4fa734dd72f8e590e8b672c3081468a5842a20 Mon Sep 17 00:00:00 2001 From: Jamie King Date: Thu, 25 Aug 2022 16:22:17 -0700 Subject: [PATCH] fix(diff-snapshot): make recievedDir optional (#306) fixes #300 --- __tests__/__snapshots__/index.spec.js.snap | 4 ++-- __tests__/diff-snapshot.spec.js | 1 - __tests__/index.spec.js | 6 +----- src/diff-snapshot.js | 4 ++-- src/index.js | 4 ++-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/__tests__/__snapshots__/index.spec.js.snap b/__tests__/__snapshots__/index.spec.js.snap index 455028d..d941663 100644 --- a/__tests__/__snapshots__/index.spec.js.snap +++ b/__tests__/__snapshots__/index.spec.js.snap @@ -43,11 +43,11 @@ Object { "blur": 0, "comparisonMethod": "pixelmatch", "customDiffConfig": Object {}, - "diffDir": "path/to/__image_snapshots__/__diff_output__", + "diffDir": undefined, "diffDirection": "horizontal", "failureThreshold": 0, "failureThresholdType": "pixel", - "receivedDir": "path/to/__image_snapshots__/__received_output__", + "receivedDir": undefined, "receivedImageBuffer": "pretendthisisanimagebuffer", "snapshotIdentifier": "test-spec-js-test-1", "snapshotsDir": "path/to/__image_snapshots__", diff --git a/__tests__/diff-snapshot.spec.js b/__tests__/diff-snapshot.spec.js index e1aafa9..31dfb4b 100644 --- a/__tests__/diff-snapshot.spec.js +++ b/__tests__/diff-snapshot.spec.js @@ -458,7 +458,6 @@ describe('diff-snapshot', () => { receivedImageBuffer: mockImageBuffer, snapshotIdentifier: mockSnapshotIdentifier, snapshotsDir: mockSnapshotsDir, - receivedDir: mockReceivedDir, diffDir: mockDiffDir, updateSnapshot: false, failureThreshold: 0, diff --git a/__tests__/index.spec.js b/__tests__/index.spec.js index f1a72f5..3ea8fa4 100644 --- a/__tests__/index.spec.js +++ b/__tests__/index.spec.js @@ -250,9 +250,7 @@ describe('toMatchImageSnapshot', () => { const dataArg = runDiffImageToSnapshot.mock.calls[0][0]; // This is to make the test work on windows - ['snapshotsDir', 'diffDir'].forEach((key) => { - dataArg[key] = dataArg[key].replace(/\\/g, '/'); - }); + dataArg.snapshotsDir = dataArg.snapshotsDir.replace(/\\/g, '/'); expect(dataArg).toMatchSnapshot(); }); @@ -448,11 +446,9 @@ describe('toMatchImageSnapshot', () => { blur: 0, comparisonMethod: 'pixelmatch', customDiffConfig: {}, - diffDir: 'path/to/__image_snapshots__/__diff_output__', diffDirection: 'horizontal', failureThreshold: 0, failureThresholdType: 'pixel', - receivedDir: 'path/to/__image_snapshots__/__received_output__', receivedImageBuffer: undefined, snapshotIdentifier: 'test-spec-js-test-1-1', snapshotsDir: 'path/to/__image_snapshots__', diff --git a/src/diff-snapshot.js b/src/diff-snapshot.js index 50f3b32..1f71c1e 100644 --- a/src/diff-snapshot.js +++ b/src/diff-snapshot.js @@ -190,8 +190,8 @@ function diffImageToSnapshot(options) { snapshotIdentifier, snapshotsDir, storeReceivedOnFailure, - receivedDir, - diffDir, + receivedDir = path.join(options.snapshotsDir, '__received_output__'), + diffDir = path.join(options.snapshotsDir, '__diff_output__'), diffDirection, updateSnapshot = false, updatePassedSnapshot = false, diff --git a/src/index.js b/src/index.js index a849f6e..50340a7 100644 --- a/src/index.js +++ b/src/index.js @@ -193,8 +193,8 @@ function configureToMatchImageSnapshot({ }); const snapshotsDir = customSnapshotsDir || path.join(path.dirname(testPath), SNAPSHOTS_DIR); - const receivedDir = customReceivedDir || path.join(snapshotsDir, '__received_output__'); - const diffDir = customDiffDir || path.join(snapshotsDir, '__diff_output__'); + const receivedDir = customReceivedDir; + const diffDir = customDiffDir; const baselineSnapshotPath = path.join(snapshotsDir, `${snapshotIdentifier}-snap.png`); OutdatedSnapshotReporter.markTouchedFile(baselineSnapshotPath);