diff --git a/packages/snapshot/src/client.ts b/packages/snapshot/src/client.ts index b15bee07baea..95aa1cd02686 100644 --- a/packages/snapshot/src/client.ts +++ b/packages/snapshot/src/client.ts @@ -1,7 +1,7 @@ import type { RawSnapshotInfo } from './port/rawSnapshot' import type { SnapshotResult, SnapshotStateOptions } from './types' import SnapshotState from './port/state' -import { deepMergeSnapshot } from './port/utils' +import { deepMergeSnapshot, DefaultMap } from './port/utils' function createMismatchError( message: string, @@ -75,6 +75,27 @@ export class SnapshotClient { return result } + private fileToTestIds = new DefaultMap>(() => new Set()) + private testIdToSnapshotPath: Record = {} + private snapshotPathToState = new Map() + + async setupTest( + filepath: string, + testId: string, + options: SnapshotStateOptions, + ): Promise { + this.fileToTestIds.get(filepath).add(testId) + const snapshotPath = await options.snapshotEnvironment.resolvePath(filepath) + this.testIdToSnapshotPath[testId] = snapshotPath + if (!this.snapshotPathToState.has(snapshotPath)) { + const content = await options.snapshotEnvironment.readSnapshotFile(snapshotPath) + this.snapshotPathToState.set( + snapshotPath, + new SnapshotState(filepath, snapshotPath, content, options), + ) + } + } + skipTest(filepath: string, testName: string): void { const state = this.getSnapshotState(filepath) state.markSnapshotsAsCheckedForTest(testName) diff --git a/packages/snapshot/src/port/state.ts b/packages/snapshot/src/port/state.ts index c7a0f837932c..3475113d87e4 100644 --- a/packages/snapshot/src/port/state.ts +++ b/packages/snapshot/src/port/state.ts @@ -68,7 +68,7 @@ export default class SnapshotState { private updated = new CounterMap() expand: boolean - private constructor( + constructor( public testFilePath: string, public snapshotPath: string, snapshotContent: string | null,