From eeafd635e4034f0b829472de1469dadf1d71d5fd Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Fri, 28 Jun 2019 21:56:50 -0700 Subject: [PATCH 1/5] Fix bug with snapshots and retries --- .../toMatchInlineSnapshotWithRetries.test.ts | 141 ++++++++++++++++++ .../toMatchSnapshotWithRetries.test.ts | 119 +++++++++++++++ .../package.json | 5 + .../package.json | 5 + packages/expect/src/index.ts | 2 + packages/expect/src/jestMatchersObject.ts | 4 + packages/expect/src/types.ts | 1 + packages/jest-circus/src/eventHandler.ts | 4 + packages/jest-snapshot/src/State.ts | 17 +++ 9 files changed, 298 insertions(+) create mode 100644 e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts create mode 100644 e2e/__tests__/toMatchSnapshotWithRetries.test.ts create mode 100644 e2e/to-match-inline-snapshot-with-retries/package.json create mode 100644 e2e/to-match-snapshot-with-retries/package.json diff --git a/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts b/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts new file mode 100644 index 000000000000..69ea2f12b2d7 --- /dev/null +++ b/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts @@ -0,0 +1,141 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import path from 'path'; +import {cleanup, makeTemplate, writeFiles} from '../Utils'; +import runJest from '../runJest'; + +const DIR = path.resolve(__dirname, '../to-match-inline-snapshot-with-retries'); +const TESTS_DIR = path.resolve(DIR, '__tests__'); + +beforeEach(() => cleanup(TESTS_DIR)); +afterAll(() => cleanup(TESTS_DIR)); + +test('works with a single snapshot', () => { + const filename = 'basic-support.test.js'; + const template = makeTemplate(` + let index = 0; + afterEach(() => { + index += 1; + }); + jest.retryTimes($2); + test('snapshots', () => expect($1).toMatchInlineSnapshot(\`3\`)); + `); + + { + writeFiles(TESTS_DIR, { + [filename]: template(['3', '1' /* retries */]), + }); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); + expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); + expect(status).toBe(0); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '2' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Received: 2'); + expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); + expect(status).toBe(1); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '4' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); + expect(status).toBe(0); + } +}); + +test('works a different assertion is failing', () => { + const filename = 'basic-support.test.js'; + const template = makeTemplate(` + jest.retryTimes($1); + test('snapshots', () => { + expect(3).toMatchInlineSnapshot(\`3\`); + expect(false).toBe(true); + }); + `); + + { + writeFiles(TESTS_DIR, { + [filename]: template(['4']), + }); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); + expect(stderr).toMatch('Test Suites: 1 failed, 1 total'); + expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); + expect(status).toBe(1); + } +}); + +test('works when multiple tests have snapshots but only one of them failed multiple times', () => { + const filename = 'basic-support.test.js'; + const template = makeTemplate(` + test('passing snapshots', () => expect(1).toMatchInlineSnapshot(\`1\`)); + describe('with retries', () => { + let index = 0; + afterEach(() => { + index += 1; + }); + jest.retryTimes($2); + test('snapshots', () => expect($1).toMatchInlineSnapshot(\`3\`)); + }); + `); + + { + writeFiles(TESTS_DIR, { + [filename]: template(['3', '2' /* retries */]), + }); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); + expect(stderr).toMatch('Snapshots: 2 passed, 2 total'); + expect(status).toBe(0); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '2' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Snapshot name: `with retries snapshots 1`'); + expect(stderr).toMatch('Received: 2'); + expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); + expect(status).toBe(1); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '4' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); + expect(status).toBe(0); + } +}); diff --git a/e2e/__tests__/toMatchSnapshotWithRetries.test.ts b/e2e/__tests__/toMatchSnapshotWithRetries.test.ts new file mode 100644 index 000000000000..4e70ec7b7bcc --- /dev/null +++ b/e2e/__tests__/toMatchSnapshotWithRetries.test.ts @@ -0,0 +1,119 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import path from 'path'; +import {cleanup, makeTemplate, writeFiles} from '../Utils'; +import runJest from '../runJest'; + +const DIR = path.resolve(__dirname, '../to-match-snapshot-with-retries'); +const TESTS_DIR = path.resolve(DIR, '__tests__'); + +beforeEach(() => cleanup(TESTS_DIR)); +afterAll(() => cleanup(TESTS_DIR)); + +test('works with a single snapshot', () => { + const filename = 'basic-support.test.js'; + const template = makeTemplate(` + let index = 0; + afterEach(() => { + index += 1; + }); + jest.retryTimes($2); + test('snapshots', () => expect($1).toMatchSnapshot()); + `); + + { + writeFiles(TESTS_DIR, { + [filename]: template(['3', '1' /* retries */]), + }); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); + expect(status).toBe(0); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '2' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Received: 2'); + expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); + expect(status).toBe(1); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '4' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); + expect(status).toBe(0); + } +}); + +test('works when multiple tests have snapshots but only one of them failed multiple times', () => { + const filename = 'basic-support.test.js'; + const template = makeTemplate(` + test('passing snapshots', () => expect('foo').toMatchSnapshot()); + describe('with retries', () => { + let index = 0; + afterEach(() => { + index += 1; + }); + jest.retryTimes($2); + test('snapshots', () => expect($1).toMatchSnapshot()); + }); + `); + + { + writeFiles(TESTS_DIR, { + [filename]: template(['3', '2' /* retries */]), + }); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); + expect(stderr).toMatch('2 snapshots written from 1 test suite.'); + expect(status).toBe(0); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '2' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Received: 2'); + expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); + expect(status).toBe(1); + } + + { + writeFiles(TESTS_DIR, { + [filename]: template(['index', '4' /* retries */]), + }); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + '--testRunner=jest-circus/runner', + filename, + ]); + expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); + expect(status).toBe(0); + } +}); diff --git a/e2e/to-match-inline-snapshot-with-retries/package.json b/e2e/to-match-inline-snapshot-with-retries/package.json new file mode 100644 index 000000000000..148788b25446 --- /dev/null +++ b/e2e/to-match-inline-snapshot-with-retries/package.json @@ -0,0 +1,5 @@ +{ + "jest": { + "testEnvironment": "node" + } +} diff --git a/e2e/to-match-snapshot-with-retries/package.json b/e2e/to-match-snapshot-with-retries/package.json new file mode 100644 index 000000000000..148788b25446 --- /dev/null +++ b/e2e/to-match-snapshot-with-retries/package.json @@ -0,0 +1,5 @@ +{ + "jest": { + "testEnvironment": "node" + } +} diff --git a/packages/expect/src/index.ts b/packages/expect/src/index.ts index e3fbcc70282c..1e83f46d6d01 100644 --- a/packages/expect/src/index.ts +++ b/packages/expect/src/index.ts @@ -43,6 +43,7 @@ import { INTERNAL_MATCHER_FLAG, getState, setState, + clearState, getMatchers, setMatchers, } from './jestMatchersObject'; @@ -402,6 +403,7 @@ expect.assertions = assertions; expect.hasAssertions = hasAssertions; expect.getState = getState; expect.setState = setState; +expect.clearState = clearState; expect.extractExpectedAssertionsErrors = extractExpectedAssertionsErrors; const expectExport = expect as Expect; diff --git a/packages/expect/src/jestMatchersObject.ts b/packages/expect/src/jestMatchersObject.ts index 7a35146558e3..cbedc9340cd1 100644 --- a/packages/expect/src/jestMatchersObject.ts +++ b/packages/expect/src/jestMatchersObject.ts @@ -37,6 +37,10 @@ export const setState = (state: object) => { Object.assign((global as any)[JEST_MATCHERS_OBJECT].state, state); }; +export const clearState = () => { + getState().snapshotState.clear(); +}; + export const getMatchers = () => (global as any)[JEST_MATCHERS_OBJECT].matchers; export const setMatchers = ( diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index 04f3950cbbf9..f03c00393944 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -44,6 +44,7 @@ export type MatcherState = { isExpectingAssertions?: boolean; isNot: boolean; promise: string; + snapshotState: any; suppressedErrors: Array; testPath?: Config.Path; utils: typeof jestMatcherUtils & { diff --git a/packages/jest-circus/src/eventHandler.ts b/packages/jest-circus/src/eventHandler.ts index 1accee9c36a0..4bcfec91dbdf 100644 --- a/packages/jest-circus/src/eventHandler.ts +++ b/packages/jest-circus/src/eventHandler.ts @@ -148,7 +148,11 @@ const eventHandler: Circus.EventHandler = (event, state): void => { break; } case 'test_retry': { + // Clear errors so tests can be retried (and not immediately fail) event.test.errors = []; + // Clear any snapshot data that occurred in previous test run + global.expect.clearState(); + break; } case 'run_start': { diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index c6fd06953b73..f3d4dec0fa02 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -47,6 +47,7 @@ export default class SnapshotState { private _uncheckedKeys: Set; private _getBabelTraverse: () => Function; private _getPrettier: () => null | any; + private _reinitializeData: () => void; added: number; expand: boolean; @@ -60,6 +61,7 @@ export default class SnapshotState { this._snapshotPath, options.updateSnapshot, ); + this._snapshotData = data; this._dirty = dirty; this._getBabelTraverse = options.getBabelTraverse; @@ -74,6 +76,17 @@ export default class SnapshotState { this.unmatched = 0; this._updateSnapshot = options.updateSnapshot; this.updated = 0; + + this._reinitializeData = () => { + this._snapshotData = data; + this._inlineSnapshots = []; + this._counters = new Map(); + this._index = 0; + this.added = 0; + this.matched = 0; + this.unmatched = 0; + this.updated = 0; + }; } markSnapshotsAsCheckedForTest(testName: string) { @@ -108,6 +121,10 @@ export default class SnapshotState { } } + clear() { + this._reinitializeData(); + } + save() { const hasExternalSnapshots = Object.keys(this._snapshotData).length; const hasInlineSnapshots = this._inlineSnapshots.length; From df8a22e6513dfa65b4e3ca73eab0aea59961c118 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Mon, 1 Jul 2019 16:39:58 -0700 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 901b86ea539c..8d2dc2a8fd00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - `[jest-snapshot]` Prevent inline snapshots from drifting when inline snapshots are updated ([#8492](https://github.com/facebook/jest/pull/8492)) - `[jest-haste-map]` Don't throw on missing mapper in Node crawler ([#8558](https://github.com/facebook/jest/pull/8558)) - `[jest-core]` Fix incorrect `passWithNoTests` warning ([#8595](https://github.com/facebook/jest/pull/8595)) +- `[jest-snapshots]` Fix test retries that contain snapshots ([#8629](https://github.com/facebook/jest/pull/8629)) ### Chore & Maintenance From 2d997e67541202772c6c185d2dd63142046d4102 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Tue, 2 Jul 2019 14:16:45 -0700 Subject: [PATCH 3/5] Address e2e tests PR comments --- .../toMatchInlineSnapshotWithRetries.test.ts | 16 ++++++++-------- e2e/__tests__/toMatchSnapshotWithRetries.test.ts | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts b/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts index 69ea2f12b2d7..c293c1e6534d 100644 --- a/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts +++ b/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts @@ -65,7 +65,7 @@ test('works with a single snapshot', () => { } }); -test('works a different assertion is failing', () => { +test('works when a different assertion is failing', () => { const filename = 'basic-support.test.js'; const template = makeTemplate(` jest.retryTimes($1); @@ -90,14 +90,14 @@ test('works when multiple tests have snapshots but only one of them failed multi const filename = 'basic-support.test.js'; const template = makeTemplate(` test('passing snapshots', () => expect(1).toMatchInlineSnapshot(\`1\`)); - describe('with retries', () => { - let index = 0; - afterEach(() => { - index += 1; - }); - jest.retryTimes($2); - test('snapshots', () => expect($1).toMatchInlineSnapshot(\`3\`)); + describe('with retries', () => { + let index = 0; + afterEach(() => { + index += 1; }); + jest.retryTimes($2); + test('snapshots', () => expect($1).toMatchInlineSnapshot(\`3\`)); + }); `); { diff --git a/e2e/__tests__/toMatchSnapshotWithRetries.test.ts b/e2e/__tests__/toMatchSnapshotWithRetries.test.ts index 4e70ec7b7bcc..02c896b3649d 100644 --- a/e2e/__tests__/toMatchSnapshotWithRetries.test.ts +++ b/e2e/__tests__/toMatchSnapshotWithRetries.test.ts @@ -69,14 +69,14 @@ test('works when multiple tests have snapshots but only one of them failed multi const filename = 'basic-support.test.js'; const template = makeTemplate(` test('passing snapshots', () => expect('foo').toMatchSnapshot()); - describe('with retries', () => { - let index = 0; - afterEach(() => { - index += 1; - }); - jest.retryTimes($2); - test('snapshots', () => expect($1).toMatchSnapshot()); + describe('with retries', () => { + let index = 0; + afterEach(() => { + index += 1; }); + jest.retryTimes($2); + test('snapshots', () => expect($1).toMatchSnapshot()); + }); `); { From 8f103bdd2c72e3ce78c1b1f02842af040574a720 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Tue, 2 Jul 2019 14:16:56 -0700 Subject: [PATCH 4/5] Use correct type for snapshotState --- packages/expect/src/types.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index f03c00393944..e688f52e46b8 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -6,6 +6,7 @@ * */ import {Config} from '@jest/types'; +import {SnapshotStateType} from 'jest-snapshot'; import * as jestMatcherUtils from 'jest-matcher-utils'; import {INTERNAL_MATCHER_FLAG} from './jestMatchersObject'; @@ -44,7 +45,7 @@ export type MatcherState = { isExpectingAssertions?: boolean; isNot: boolean; promise: string; - snapshotState: any; + snapshotState: SnapshotStateType; suppressedErrors: Array; testPath?: Config.Path; utils: typeof jestMatcherUtils & { From 313fb53e37c3814a8cd3ff91220f977035827719 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Wed, 3 Jul 2019 10:13:43 -0700 Subject: [PATCH 5/5] Simplify implementation and decouple it from expect --- packages/expect/src/index.ts | 2 -- packages/expect/src/jestMatchersObject.ts | 4 ---- packages/expect/src/types.ts | 2 -- packages/jest-circus/src/eventHandler.ts | 4 ---- .../jestAdapterInit.ts | 14 +++++++++++ packages/jest-snapshot/src/State.ts | 24 ++++++++----------- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/packages/expect/src/index.ts b/packages/expect/src/index.ts index 1e83f46d6d01..e3fbcc70282c 100644 --- a/packages/expect/src/index.ts +++ b/packages/expect/src/index.ts @@ -43,7 +43,6 @@ import { INTERNAL_MATCHER_FLAG, getState, setState, - clearState, getMatchers, setMatchers, } from './jestMatchersObject'; @@ -403,7 +402,6 @@ expect.assertions = assertions; expect.hasAssertions = hasAssertions; expect.getState = getState; expect.setState = setState; -expect.clearState = clearState; expect.extractExpectedAssertionsErrors = extractExpectedAssertionsErrors; const expectExport = expect as Expect; diff --git a/packages/expect/src/jestMatchersObject.ts b/packages/expect/src/jestMatchersObject.ts index cbedc9340cd1..7a35146558e3 100644 --- a/packages/expect/src/jestMatchersObject.ts +++ b/packages/expect/src/jestMatchersObject.ts @@ -37,10 +37,6 @@ export const setState = (state: object) => { Object.assign((global as any)[JEST_MATCHERS_OBJECT].state, state); }; -export const clearState = () => { - getState().snapshotState.clear(); -}; - export const getMatchers = () => (global as any)[JEST_MATCHERS_OBJECT].matchers; export const setMatchers = ( diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index e688f52e46b8..04f3950cbbf9 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -6,7 +6,6 @@ * */ import {Config} from '@jest/types'; -import {SnapshotStateType} from 'jest-snapshot'; import * as jestMatcherUtils from 'jest-matcher-utils'; import {INTERNAL_MATCHER_FLAG} from './jestMatchersObject'; @@ -45,7 +44,6 @@ export type MatcherState = { isExpectingAssertions?: boolean; isNot: boolean; promise: string; - snapshotState: SnapshotStateType; suppressedErrors: Array; testPath?: Config.Path; utils: typeof jestMatcherUtils & { diff --git a/packages/jest-circus/src/eventHandler.ts b/packages/jest-circus/src/eventHandler.ts index 4bcfec91dbdf..1accee9c36a0 100644 --- a/packages/jest-circus/src/eventHandler.ts +++ b/packages/jest-circus/src/eventHandler.ts @@ -148,11 +148,7 @@ const eventHandler: Circus.EventHandler = (event, state): void => { break; } case 'test_retry': { - // Clear errors so tests can be retried (and not immediately fail) event.test.errors = []; - // Clear any snapshot data that occurred in previous test run - global.expect.clearState(); - break; } case 'run_start': { diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index 9804125de04e..eba12e58e12c 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -12,6 +12,7 @@ import {extractExpectedAssertionsErrors, getState, setState} from 'expect'; import {formatExecError, formatResultsErrors} from 'jest-message-util'; import { SnapshotState, + SnapshotStateType, addSerializer, buildSnapshotResolver, } from 'jest-snapshot'; @@ -131,6 +132,8 @@ export const initialize = ({ }); setState({snapshotState, testPath}); + addEventHandler(handleSnapshotStateAfterRetry(snapshotState)); + // Return it back to the outer scope (test runner outside the VM). return {globals, snapshotState}; }; @@ -243,6 +246,17 @@ export const runAndTransformResultsToJestFormat = async ({ }; }; +const handleSnapshotStateAfterRetry = (snapshotState: SnapshotStateType) => ( + event: Circus.Event, +) => { + switch (event.name) { + case 'test_retry': { + // Clear any snapshot data that occurred in previous test run + snapshotState.clear(); + } + } +}; + const eventHandler = (event: Circus.Event) => { switch (event.name) { case 'test_start': { diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index f3d4dec0fa02..8c01e9f3c94c 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -42,12 +42,12 @@ export default class SnapshotState { private _index: number; private _updateSnapshot: Config.SnapshotUpdateState; private _snapshotData: SnapshotData; + private _initialData: SnapshotData; private _snapshotPath: Config.Path; private _inlineSnapshots: Array; private _uncheckedKeys: Set; private _getBabelTraverse: () => Function; private _getPrettier: () => null | any; - private _reinitializeData: () => void; added: number; expand: boolean; @@ -61,7 +61,7 @@ export default class SnapshotState { this._snapshotPath, options.updateSnapshot, ); - + this._initialData = data; this._snapshotData = data; this._dirty = dirty; this._getBabelTraverse = options.getBabelTraverse; @@ -76,17 +76,6 @@ export default class SnapshotState { this.unmatched = 0; this._updateSnapshot = options.updateSnapshot; this.updated = 0; - - this._reinitializeData = () => { - this._snapshotData = data; - this._inlineSnapshots = []; - this._counters = new Map(); - this._index = 0; - this.added = 0; - this.matched = 0; - this.unmatched = 0; - this.updated = 0; - }; } markSnapshotsAsCheckedForTest(testName: string) { @@ -122,7 +111,14 @@ export default class SnapshotState { } clear() { - this._reinitializeData(); + this._snapshotData = this._initialData; + this._inlineSnapshots = []; + this._counters = new Map(); + this._index = 0; + this.added = 0; + this.matched = 0; + this.unmatched = 0; + this.updated = 0; } save() {