From 21167157854fbd72b0e547e953adb3766faaee60 Mon Sep 17 00:00:00 2001 From: Thomas Bertet Date: Tue, 15 May 2018 17:53:18 +0200 Subject: [PATCH] fix '-u' suggestion and snapshot summary --- src/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index fecdfbe..3f09308 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,7 @@ import path from 'path'; import { SnapshotState, toMatchSnapshot, addSerializer } from 'jest-snapshot'; const snapshotsStateMap = new Map(); +let commonSnapshotState; function getAbsolutePathToSnapshot(testPath, snapshotFile) { return path.isAbsolute(snapshotFile) @@ -19,13 +20,23 @@ afterAll(() => { } snapshotState.save(); + + if (commonSnapshotState) { + // Update common state so we get the report right with added/update/unmatched snapshots. + // Jest will display the "u" & "i" suggestion, plus displaying the right number of update/added/unmatched snapshots. + commonSnapshotState.unmatched += snapshotState.unmatched; + commonSnapshotState.matched += snapshotState.matched; + commonSnapshotState.updated += snapshotState.updated; + commonSnapshotState.added += snapshotState.added; + } }); }); function toMatchSpecificSnapshot(received, snapshotFile, testName) { const absoluteSnapshotFile = getAbsolutePathToSnapshot(this.testPath, snapshotFile); - const commonSnapshotState = this.snapshotState; + // store the common state to re-use it in "afterAll" hook. + commonSnapshotState = this.snapshotState; let snapshotState = snapshotsStateMap.get(absoluteSnapshotFile); if (!snapshotState) {