From 93756624c2230b505118b4e1817435e9a06e1090 Mon Sep 17 00:00:00 2001 From: sawradip Date: Tue, 3 Nov 2026 02:10:41 +0600 Subject: [PATCH] test(reader): one clock for both packs in the golden gather test A ZIP entry carries the time it was packed (to 2 seconds), and packLesson gives JSZip no fixed date, so two packs made either side of a tick differ and the byte-for-byte check failed now and then (it failed the 0.1.5 and the 0.1.6 release runs). The test now fakes only Date while it packs; its timers still run. Co-Authored-By: Claude Opus 5.5 --- packages/reader/src/author/gather.test.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/reader/src/author/gather.test.ts b/packages/reader/src/author/gather.test.ts index 28c2fcb..57a3a32 100644 --- a/packages/reader/src/author/gather.test.ts +++ b/packages/reader/src/author/gather.test.ts @@ -1,6 +1,6 @@ import { packLesson, type AssetBundle } from '@chalk-format/container'; import { assetKey, parseLesson, referencedAssetIds, type Lesson } from '@chalk-format/model'; -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { gatherAssets, type Gathered } from './gather.js'; import type { SaveProgress } from './save-run.js'; @@ -47,9 +47,15 @@ describe('gathering a book\'s assets for a save', () => { const after: AssetBundle = await gatherAssets({ ids, held, fetchOne }); expect([...after.keys()]).toEqual([...before.keys()]); // the same assets in the same order const fixed = { ...lesson, updatedAt: '2026-02-02T00:00:00Z' }; - const a = await packLesson(fixed, before); - const b = await packLesson(fixed, after); - expect(Buffer.from(b).equals(Buffer.from(a))).toBe(true); // the golden check: the same file, byte for byte + // a ZIP entry carries the time it was packed (to 2 seconds): one clock for both packs, or packs either side of a tick differ + vi.useFakeTimers({ toFake: ['Date'], now: new Date('2026-02-02T00:00:00Z') }); + try { + const a = await packLesson(fixed, before); + const b = await packLesson(fixed, after); + expect(Buffer.from(b).equals(Buffer.from(a))).toBe(true); // the golden check: the same file, byte for byte + } finally { + vi.useRealTimers(); + } }); it('fetches a few at a time, never more than asked, and tells how far it got', async () => {