Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
db634ea
wip: rework snapshot state
hi-ogawa Oct 30, 2024
7cf11f5
wip: remove more
hi-ogawa Oct 30, 2024
047badf
wip: test
hi-ogawa Oct 30, 2024
0aea548
wip: clear inline snapshots
hi-ogawa Oct 30, 2024
4c835ed
wip: clear file
hi-ogawa Oct 30, 2024
99abe4c
fix: reset to _initialData
hi-ogawa Oct 30, 2024
c174615
fix: fix retry partial
hi-ogawa Oct 30, 2024
3dcf25d
chore: cleanup more
hi-ogawa Oct 30, 2024
8817ac5
test: more
hi-ogawa Oct 30, 2024
c5e4527
wip: _testIdToKeys state
hi-ogawa Oct 30, 2024
558ba71
test: more
hi-ogawa Oct 30, 2024
5b1182b
wip: _testIdToKeys
hi-ogawa Oct 30, 2024
940dbb3
fix: fix markSnapshotsAsCheckedForTest
hi-ogawa Oct 30, 2024
83741e0
Merge branch 'main' into rework-snapshot-state
hi-ogawa Oct 31, 2024
80accd6
refactor: minor
hi-ogawa Oct 31, 2024
3fc11d5
fix: clear added/updated stats
hi-ogawa Oct 31, 2024
de9b88e
chore: comment
hi-ogawa Oct 31, 2024
4a69ec1
test: move some snapshot test
hi-ogawa Oct 31, 2024
fd8d60c
test: test same title
hi-ogawa Oct 31, 2024
1cdaa67
test: test retry
hi-ogawa Oct 31, 2024
e0768a1
test: cleanup
hi-ogawa Oct 31, 2024
5bd6a34
test: test summary
hi-ogawa Oct 31, 2024
09a4bcd
chore: cleanup
hi-ogawa Oct 31, 2024
671344f
refactor: minor
hi-ogawa Oct 31, 2024
eae4ed7
Merge branch 'main' into rework-snapshot-state
hi-ogawa Nov 4, 2024
63d9817
test: use import.meta.glob
hi-ogawa Nov 4, 2024
99c64e6
fix: ensure test context
hi-ogawa Nov 4, 2024
ebbadda
fix: tweak api
hi-ogawa Nov 4, 2024
04e1ddf
chore: make `testId` optional
hi-ogawa Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: minor
  • Loading branch information
hi-ogawa committed Oct 31, 2024
commit 671344fe76e7ad9b29b7c68f5cc0339a37a52619
18 changes: 6 additions & 12 deletions packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface SaveStatus {
}

export default class SnapshotState {
private _counters: Map<string, number>
private _counters = new CounterMap<string>()
private _dirty: boolean
private _updateSnapshot: SnapshotUpdateState
private _snapshotData: SnapshotData
Expand Down Expand Up @@ -83,7 +83,6 @@ export default class SnapshotState {
this._inlineSnapshotStacks = []
this._rawSnapshots = []
this._uncheckedKeys = new Set(Object.keys(this._snapshotData))
this._counters = new Map()
this.expand = options.expand || false
this._updateSnapshot = options.updateSnapshot
this._snapshotFormat = {
Expand Down Expand Up @@ -124,17 +123,12 @@ export default class SnapshotState {
// clear file
for (const key of this._testIdToKeys.get(testId)) {
const name = keyToTestName(key)
const counter = this._counters.get(name)
if (typeof counter !== 'undefined') {
const count = this._counters.get(name)
if (count > 0) {
if (key in this._snapshotData || key in this._initialData) {
this._snapshotData[key] = this._initialData[key]
}
if (counter > 0) {
this._counters.set(name, counter - 1)
}
else {
this._counters.delete(name)
}
this._counters.set(name, count - 1)
}
}
this._testIdToKeys.delete(testId)
Expand Down Expand Up @@ -256,8 +250,8 @@ export default class SnapshotState {
rawSnapshot,
}: SnapshotMatchOptions): SnapshotReturnOptions {
// this also increments counter for inline snapshots. maybe we shouldn't?
this._counters.set(testName, (this._counters.get(testName) || 0) + 1)
const count = Number(this._counters.get(testName))
this._counters.increment(testName)
const count = this._counters.get(testName)

if (!key) {
key = testNameToKey(testName, count)
Expand Down
8 changes: 6 additions & 2 deletions packages/snapshot/src/port/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,13 @@ export class DefaultMap<K, V> extends Map<K, V> {
}
}

export class CounterMap<K> extends Map<K, number> {
export class CounterMap<K> extends DefaultMap<K, number> {
constructor() {
super(() => 0)
}

increment(key: K): void {
this.set(key, (this.get(key) ?? 0) + 1)
this.set(key, this.get(key) + 1)
}

total(): number {
Expand Down