Skip to content

Commit 95a43cd

Browse files
committed
test: use a common fake clock baseline
Amp-Thread-ID: https://ampcode.com/threads/T-019feeff-305b-73a5-bb82-3ae3a74e816d
1 parent cb2b7c6 commit 95a43cd

16 files changed

Lines changed: 58 additions & 83 deletions

src/composables/queue/useJobList.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ describe('useJobList', () => {
555555
})
556556

557557
it('groups terminal jobs without an execution end timestamp by create time', async () => {
558-
vi.setSystemTime(new Date('2024-01-10T12:00:00Z'))
559558
queueStoreMock.historyTasks = [
560559
createTask({
561560
jobId: 'failed-before-execution',
@@ -583,7 +582,6 @@ describe('useJobList', () => {
583582
})
584583

585584
it('groups job items by date label and sorts by total generation time when requested', async () => {
586-
vi.setSystemTime(new Date('2024-01-10T12:00:00Z'))
587585
queueStoreMock.historyTasks = [
588586
createTask({
589587
jobId: 'today-small',

src/composables/queue/useQueueNotificationBanners.test.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ describe(useQueueNotificationBanners, () => {
119119
}
120120

121121
beforeEach(() => {
122-
vi.setSystemTime(0)
123122
resetState()
124123
})
125124

@@ -204,14 +203,15 @@ describe(useQueueNotificationBanners, () => {
204203

205204
it('shows a completed notification from a finished batch', async () => {
206205
const { unmount, composable } = mountComposable()
206+
const now = Date.now()
207207

208208
try {
209209
await runBatch({
210-
start: 1_000,
211-
finish: 1_200,
210+
start: now + 1_000,
211+
finish: now + 1_200,
212212
tasks: [
213213
createTask({
214-
ts: 1_050,
214+
ts: now + 1_050,
215215
previewUrl: 'https://example.com/preview.png'
216216
})
217217
]
@@ -229,13 +229,14 @@ describe(useQueueNotificationBanners, () => {
229229

230230
it('shows one completion notification when history updates after queue becomes idle', async () => {
231231
const { unmount, composable } = mountComposable()
232+
const now = Date.now()
232233

233234
try {
234-
vi.setSystemTime(4_000)
235+
vi.setSystemTime(now + 4_000)
235236
executionStore().isIdle = false
236237
await nextTick()
237238

238-
vi.setSystemTime(4_100)
239+
vi.setSystemTime(now + 4_100)
239240
executionStore().isIdle = true
240241
queueStore().historyTasks = []
241242
await nextTick()
@@ -244,7 +245,7 @@ describe(useQueueNotificationBanners, () => {
244245

245246
queueStore().historyTasks = [
246247
createTask({
247-
ts: 4_050,
248+
ts: now + 4_050,
248249
previewUrl: 'https://example.com/race-preview.png'
249250
})
250251
]
@@ -270,19 +271,20 @@ describe(useQueueNotificationBanners, () => {
270271

271272
it('queues both completed and failed notifications for mixed batches', async () => {
272273
const { unmount, composable } = mountComposable()
274+
const now = Date.now()
273275

274276
try {
275277
await runBatch({
276-
start: 2_000,
277-
finish: 2_200,
278+
start: now + 2_000,
279+
finish: now + 2_200,
278280
tasks: [
279281
createTask({
280-
ts: 2_050,
282+
ts: now + 2_050,
281283
previewUrl: 'https://example.com/result.png'
282284
}),
283-
createTask({ ts: 2_060 }),
284-
createTask({ ts: 2_070 }),
285-
createTask({ state: 'Failed', ts: 2_080 })
285+
createTask({ ts: now + 2_060 }),
286+
createTask({ ts: now + 2_070 }),
287+
createTask({ state: 'Failed', ts: now + 2_080 })
286288
]
287289
})
288290

@@ -306,26 +308,27 @@ describe(useQueueNotificationBanners, () => {
306308

307309
it('uses up to two completion thumbnails for notification icon previews', async () => {
308310
const { unmount, composable } = mountComposable()
311+
const now = Date.now()
309312

310313
try {
311314
await runBatch({
312-
start: 3_000,
313-
finish: 3_300,
315+
start: now + 3_000,
316+
finish: now + 3_300,
314317
tasks: [
315318
createTask({
316-
ts: 3_050,
319+
ts: now + 3_050,
317320
previewUrl: 'https://example.com/preview-1.png'
318321
}),
319322
createTask({
320-
ts: 3_060,
323+
ts: now + 3_060,
321324
previewUrl: 'https://example.com/preview-2.png'
322325
}),
323326
createTask({
324-
ts: 3_070,
327+
ts: now + 3_070,
325328
previewUrl: 'https://example.com/preview-3.png'
326329
}),
327330
createTask({
328-
ts: 3_080,
331+
ts: now + 3_080,
329332
previewUrl: 'https://example.com/preview-4.png'
330333
})
331334
]

src/platform/assets/composables/useMediaAssetFiltering.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ describe('useMediaAssetFiltering', () => {
380380
})
381381

382382
it('combines media type and date before sorting', () => {
383-
const now = new Date(2026, 6, 27, 12).getTime()
384-
vi.setSystemTime(now)
383+
const now = Date.now()
385384

386385
const assets = ref<AssetItem[]>([
387386
makeAsset({

src/platform/surveys/NightlySurveyPopover.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ describe('NightlySurveyPopover', () => {
4646
beforeEach(() => {
4747
localStorage.clear()
4848
vi.resetModules()
49-
vi.setSystemTime(new Date('2024-06-15T12:00:00Z'))
5049

5150
mockIsNightly.value = true
5251
mockIsCloud.value = false

src/platform/surveys/useFeatureUsageTracker.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ describe('useFeatureUsageTracker', () => {
3232
})
3333

3434
it('sets firstUsed only on first use', () => {
35-
const firstTs = 1000000
36-
vi.setSystemTime(firstTs)
35+
const firstTs = Date.now()
3736
const { usage, trackUsage } = useFeatureUsageTracker('test-feature-3')
3837

3938
trackUsage()
4039
expect(usage.value?.firstUsed).toBe(firstTs)
4140

42-
vi.setSystemTime(firstTs + 5000)
41+
vi.advanceTimersByTime(5_000)
4342
trackUsage()
4443
expect(usage.value?.firstUsed).toBe(firstTs)
4544
})

src/platform/surveys/useSurveyEligibility.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe('useSurveyEligibility', () => {
3131

3232
beforeEach(() => {
3333
localStorage.clear()
34-
vi.setSystemTime(new Date('2024-06-15T12:00:00Z'))
3534

3635
mockDistribution.isNightly = true
3736
mockDistribution.isCloud = false

src/platform/telemetry/topupTracker.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ vi.mock('@/platform/telemetry', () => ({
1919

2020
describe('topupTracker', () => {
2121
beforeEach(() => {
22-
vi.setSystemTime(new Date('2026-08-07T12:00:00Z'))
2322
localStorage.clear()
2423
})
2524

src/platform/updates/common/versionCompatibilityStore.test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ describe('useVersionCompatibilityStore', () => {
274274

275275
describe('dismissal persistence', () => {
276276
it('should save dismissal to reactive storage with expiration', async () => {
277-
const mockNow = 1000000
278-
vi.setSystemTime(mockNow)
277+
const now = Date.now()
279278

280279
mockSystemStatsStore.systemStats = {
281280
system: {
@@ -290,7 +289,7 @@ describe('useVersionCompatibilityStore', () => {
290289

291290
// Check that the dismissal was added to reactive storage
292291
expect(mockDismissalStorage.value).toEqual({
293-
'1.24.0-1.25.0-1.25.0': mockNow + 7 * 24 * 60 * 60 * 1000
292+
'1.24.0-1.25.0-1.25.0': now + 7 * 24 * 60 * 60 * 1000
294293
})
295294
})
296295

@@ -481,8 +480,7 @@ describe('useVersionCompatibilityStore', () => {
481480
})
482481

483482
it('should include outdated packages in dismissal key', async () => {
484-
const mockNow = 1000000
485-
vi.setSystemTime(mockNow)
483+
const now = Date.now()
486484

487485
mockSystemStatsStore.systemStats = {
488486
system: {
@@ -504,14 +502,11 @@ describe('useVersionCompatibilityStore', () => {
504502

505503
expect(mockDismissalStorage.value).toEqual({
506504
'1.24.0-1.24.0-1.24.0-comfyui-workflow-templates@0.9.0->0.9.5':
507-
mockNow + 7 * 24 * 60 * 60 * 1000
505+
now + 7 * 24 * 60 * 60 * 1000
508506
})
509507
})
510508

511509
it('should produce the same dismissal key regardless of package order', async () => {
512-
const mockNow = 1000000
513-
vi.setSystemTime(mockNow)
514-
515510
const packageA = {
516511
name: 'comfy-aimdo',
517512
installed: '0.1.0',
@@ -551,12 +546,11 @@ describe('useVersionCompatibilityStore', () => {
551546
})
552547

553548
it('should prune expired dismissals when writing a new one', async () => {
554-
const mockNow = 10_000_000
555-
vi.setSystemTime(mockNow)
549+
const now = Date.now()
556550

557551
mockDismissalStorage.value = {
558-
'expired-key': mockNow - 1,
559-
'still-valid-key': mockNow + 5000
552+
'expired-key': now - 1,
553+
'still-valid-key': now + 5000
560554
}
561555

562556
mockSystemStatsStore.systemStats = {
@@ -575,9 +569,6 @@ describe('useVersionCompatibilityStore', () => {
575569
})
576570

577571
it('should allow dismissal when only package warnings are present', async () => {
578-
const mockNow = 1000000
579-
vi.setSystemTime(mockNow)
580-
581572
mockSystemStatsStore.systemStats = {
582573
system: {
583574
comfyui_version: '',

src/platform/workflow/persistence/composables/useWorkflowPersistenceV2.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ describe('useWorkflowPersistenceV2', () => {
186186
}> = []
187187

188188
beforeEach(() => {
189-
vi.setSystemTime(new Date('2025-01-01T00:00:00Z'))
190189
setActivePinia(createTestingPinia({ stubActions: false }))
191190
localStorage.clear()
192191
sessionStorage.clear()

src/platform/workflow/persistence/stores/workflowDraftStoreV2.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,20 @@ describe('workflowDraftStoreV2', () => {
8282
it('keeps payload updatedAt stable when only recency is refreshed', () => {
8383
const store = useWorkflowDraftStoreV2()
8484

85-
vi.setSystemTime(new Date('2026-03-21T10:00:00Z'))
8685
store.saveDraft('workflows/a.json', '{"id":"a"}', {
8786
name: 'a',
8887
isTemporary: true
8988
})
9089
const initialUpdatedAt = store.getDraft('workflows/a.json')!.updatedAt
9190

92-
vi.setSystemTime(new Date('2026-03-21T10:01:00Z'))
91+
vi.advanceTimersByTime(60_000)
9392
store.saveDraft('workflows/b.json', '{"id":"b"}', {
9493
name: 'b',
9594
isTemporary: true
9695
})
9796
expect(store.getMostRecentPath()).toBe('workflows/b.json')
9897

99-
vi.setSystemTime(new Date('2026-03-21T10:02:00Z'))
98+
vi.advanceTimersByTime(60_000)
10099
store.markDraftUsed('workflows/a.json')
101100

102101
expect(store.getDraft('workflows/a.json')!.updatedAt).toBe(
@@ -212,14 +211,13 @@ describe('workflowDraftStoreV2', () => {
212211
it('preserves payload updatedAt when moving a draft', () => {
213212
const store = useWorkflowDraftStoreV2()
214213

215-
vi.setSystemTime(new Date('2026-05-13T00:00:00Z'))
216214
store.saveDraft('workflows/old.json', '{"data":"test"}', {
217215
name: 'old',
218216
isTemporary: true
219217
})
220218
const originalUpdatedAt = store.getDraft('workflows/old.json')!.updatedAt
221219

222-
vi.setSystemTime(new Date('2026-05-13T00:05:00Z'))
220+
vi.advanceTimersByTime(5 * 60_000)
223221
store.moveDraft('workflows/old.json', 'workflows/new.json', 'new')
224222

225223
expect(store.getDraft('workflows/new.json')!.updatedAt).toBe(

0 commit comments

Comments
 (0)