From ab114d1c63f883646779e5c139630844ceea1f4a Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 31 Oct 2024 12:35:21 +0900 Subject: [PATCH] wip: ability to choose snapshot file per test case --- packages/snapshot/src/client.ts | 20 ++++++++++++++++++++ packages/snapshot/src/port/state.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/snapshot/src/client.ts b/packages/snapshot/src/client.ts index b15bee07baea..d651eeda6628 100644 --- a/packages/snapshot/src/client.ts +++ b/packages/snapshot/src/client.ts @@ -75,6 +75,26 @@ export class SnapshotClient { return result } + // TODO: summary also needs to be aggregated here + private testIdTosnapshotPath: Record = {} + private snapshotPathToState = new Map() + + async setupTest( + filepath: string, + testId: string, + options: SnapshotStateOptions, + ): Promise { + 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,