Add unit tests for otsUtils and coverage evaluation report#1
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a test coverage evaluation document and a new unit test suite for otsUtils.ts. The tests utilize a custom mock filesystem to verify file recursion, repository hashing, and OpenTimestamps integration. Review feedback suggests enhancing test isolation by clearing global state in afterEach, expanding test coverage for time-based upgrade logic, and adopting Vitest's fake timers to manage internal timeouts.
| beforeEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); |
There was a problem hiding this comment.
The tests modify the global window.OpenTimestamps object. To prevent side effects and ensure test isolation, you should reset this property after each test.
| beforeEach(() => { | |
| vi.restoreAllMocks(); | |
| }); | |
| afterEach(() => { | |
| vi.restoreAllMocks(); | |
| delete (window as any).OpenTimestamps; | |
| }); |
| (window as any).OpenTimestamps = ots; | ||
|
|
||
| const fs = makeFs({ | ||
| '/.tool/settings/ots/pending.json': JSON.stringify({ abc123: null }), |
There was a problem hiding this comment.
| @@ -0,0 +1,186 @@ | |||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | |||
There was a problem hiding this comment.
The upgradeAll function in otsUtils.ts uses a setTimeout for a 30-second timeout during the upgrade process. In a testing environment, this can lead to hanging processes or flaky tests if the timer is not managed. It is recommended to use Vitest's fake timers to control time-dependent logic.
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | |
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
Motivation
otsUtilsutilities and document current coverage state for protocol and utils.Description
COVERAGE_EVALUATION.mdsummarizing scope checked, well-covered areas, uncovered behaviors, tooling status, and recommended next tests.src/otsUtils.test.tswhich provides a mocked in-memory filesystem and mockedwindow.OpenTimestampsto unit-testotsUtilbehaviors.getAllFilesRecursivefiltering,generateRepoHashprotocol equivalence,upgradeAllbehaviors for missing and stale entries (rewrites.otsand clears pending registry), andstampHash/getInfodelegation to OpenTimestamps.vitesttest helpers and spies (vi) to assert interactions and side effects.Testing
src/otsUtils.test.tssuite; tests completed and asserted expected behavior for all covered cases.npx vitest run --config vitest.config.ts --coverage, but it failed due to a missing provider dependency:@vitest/coverage-v8which prevented line/branch coverage output.Codex Task