Skip to content

Commit

Permalink
wip: ability to choose snapshot file per test case
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Oct 31, 2024
1 parent de9b88e commit ab114d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/snapshot/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ export class SnapshotClient {
return result
}

// TODO: summary also needs to be aggregated here
private testIdTosnapshotPath: Record<string, string> = {}
private snapshotPathToState = new Map<string, SnapshotState>()

async setupTest(
filepath: string,
testId: string,
options: SnapshotStateOptions,
): Promise<void> {
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)
Expand Down
2 changes: 1 addition & 1 deletion packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class SnapshotState {
private updated = new CounterMap<string>()
expand: boolean

private constructor(
constructor(
public testFilePath: string,
public snapshotPath: string,
snapshotContent: string | null,
Expand Down

0 comments on commit ab114d1

Please sign in to comment.