Skip to content

Commit bcf3ef5

Browse files
KyleAMathewsclaude
andcommitted
fix: use real Temporal objects in hash tests instead of mocks
Add temporal-polyfill as devDependency to db-ivm and replace createTemporalLike mocks with real Temporal.PlainDate, PlainTime, PlainDateTime, and Instant objects in hash tests. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent bfea297 commit bcf3ef5

3 files changed

Lines changed: 23 additions & 37 deletions

File tree

packages/db-ivm/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
},
5656
"devDependencies": {
5757
"@types/debug": "^4.1.12",
58-
"@vitest/coverage-istanbul": "^3.2.4"
58+
"@vitest/coverage-istanbul": "^3.2.4",
59+
"temporal-polyfill": "^0.3.0"
5960
}
6061
}

packages/db-ivm/tests/utils.test.ts

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
import { describe, expect, it } from 'vitest'
2+
import { Temporal } from 'temporal-polyfill'
23
import { DefaultMap } from '../src/utils.js'
34
import { hash } from '../src/hashing/index.js'
45

5-
// Minimal mock that mimics Temporal objects: Symbol.toStringTag + toString()
6-
// without requiring the temporal-polyfill dependency.
7-
function createTemporalLike(
8-
tag: string,
9-
value: string,
10-
): { toString: () => string; [Symbol.toStringTag]: string } {
11-
return Object.create(null, {
12-
[Symbol.toStringTag]: { value: tag },
13-
toString: { value: () => value },
14-
})
15-
}
16-
176
describe(`DefaultMap`, () => {
187
it(`should return default value for missing keys`, () => {
198
const map = new DefaultMap(() => 0)
@@ -183,9 +172,9 @@ describe(`hash`, () => {
183172
})
184173

185174
it(`should hash Temporal objects by value`, () => {
186-
const date1 = createTemporalLike(`Temporal.PlainDate`, `2024-01-15`)
187-
const date2 = createTemporalLike(`Temporal.PlainDate`, `2024-01-15`)
188-
const date3 = createTemporalLike(`Temporal.PlainDate`, `2024-06-15`)
175+
const date1 = Temporal.PlainDate.from(`2024-01-15`)
176+
const date2 = Temporal.PlainDate.from(`2024-01-15`)
177+
const date3 = Temporal.PlainDate.from(`2024-06-15`)
189178

190179
const hash1 = hash(date1)
191180
const hash2 = hash(date2)
@@ -196,34 +185,22 @@ describe(`hash`, () => {
196185
expect(hash1).not.toBe(hash3) // Different Temporal dates should have different hash
197186

198187
// Different Temporal types with overlapping string representations should differ
199-
const plainDate = createTemporalLike(`Temporal.PlainDate`, `2024-01-15`)
200-
const plainDateTime = createTemporalLike(
201-
`Temporal.PlainDateTime`,
202-
`2024-01-15T00:00:00`,
203-
)
188+
const plainDate = Temporal.PlainDate.from(`2024-01-15`)
189+
const plainDateTime = Temporal.PlainDateTime.from(`2024-01-15T00:00:00`)
204190

205191
expect(hash(plainDate)).not.toBe(hash(plainDateTime))
206192

207193
// Other Temporal types should also hash correctly
208-
const time1 = createTemporalLike(`Temporal.PlainTime`, `10:30:00`)
209-
const time2 = createTemporalLike(`Temporal.PlainTime`, `10:30:00`)
210-
const time3 = createTemporalLike(`Temporal.PlainTime`, `14:00:00`)
194+
const time1 = Temporal.PlainTime.from(`10:30:00`)
195+
const time2 = Temporal.PlainTime.from(`10:30:00`)
196+
const time3 = Temporal.PlainTime.from(`14:00:00`)
211197

212198
expect(hash(time1)).toBe(hash(time2))
213199
expect(hash(time1)).not.toBe(hash(time3))
214200

215-
const instant1 = createTemporalLike(
216-
`Temporal.Instant`,
217-
`2024-01-15T00:00:00Z`,
218-
)
219-
const instant2 = createTemporalLike(
220-
`Temporal.Instant`,
221-
`2024-01-15T00:00:00Z`,
222-
)
223-
const instant3 = createTemporalLike(
224-
`Temporal.Instant`,
225-
`2024-06-15T00:00:00Z`,
226-
)
201+
const instant1 = Temporal.Instant.from(`2024-01-15T00:00:00Z`)
202+
const instant2 = Temporal.Instant.from(`2024-01-15T00:00:00Z`)
203+
const instant3 = Temporal.Instant.from(`2024-06-15T00:00:00Z`)
227204

228205
expect(hash(instant1)).toBe(hash(instant2))
229206
expect(hash(instant1)).not.toBe(hash(instant3))

pnpm-lock.yaml

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)