Update Prisma and harden tests
This commit is contained in:
parent
a2f9d4bd1a
commit
d8eb38fe52
17 changed files with 171 additions and 119 deletions
|
|
@ -10,14 +10,14 @@ process.env.BETTER_AUTH_URL ??= process.env.NEXT_PUBLIC_APP_URL
|
|||
const OriginalDate = Date
|
||||
let fixedTimestamp: number | null = null
|
||||
|
||||
type MutableVi = typeof vi & {
|
||||
mocked?: <T>(item: T) => T
|
||||
setSystemTime?: (value: number | Date) => void
|
||||
useFakeTimers?: (...args: Array<unknown>) => void
|
||||
useRealTimers?: (...args: Array<unknown>) => void
|
||||
type ExtendedVi = typeof vi & {
|
||||
mocked?: typeof vi.mocked
|
||||
setSystemTime?: typeof vi.setSystemTime
|
||||
useFakeTimers?: typeof vi.useFakeTimers
|
||||
useRealTimers?: typeof vi.useRealTimers
|
||||
}
|
||||
|
||||
const viExtended = vi as MutableVi
|
||||
const viExtended = vi as ExtendedVi
|
||||
|
||||
if (typeof window === "undefined" || typeof document === "undefined") {
|
||||
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
|
||||
|
|
@ -57,40 +57,48 @@ const applyFixedDate = () => {
|
|||
}
|
||||
|
||||
if (!viExtended.mocked) {
|
||||
viExtended.mocked = <T>(item: T) => item
|
||||
viExtended.mocked = ((item: unknown) => item) as typeof vi.mocked
|
||||
}
|
||||
|
||||
if (!viExtended.setSystemTime) {
|
||||
viExtended.setSystemTime = (value: number | Date) => {
|
||||
fixedTimestamp = typeof value === "number" ? value : value.getTime()
|
||||
viExtended.setSystemTime = ((value: string | number | Date) => {
|
||||
if (typeof value === "string") {
|
||||
const parsed = Date.parse(value)
|
||||
fixedTimestamp = Number.isFinite(parsed) ? parsed : Date.now()
|
||||
} else {
|
||||
fixedTimestamp = value instanceof Date ? value.getTime() : value
|
||||
}
|
||||
applyFixedDate()
|
||||
}
|
||||
return viExtended
|
||||
}) as typeof vi.setSystemTime
|
||||
}
|
||||
|
||||
if (!viExtended.useFakeTimers) {
|
||||
viExtended.useFakeTimers = () => {
|
||||
// Bun's fake timers are not required for our current tests. This is a noop
|
||||
// placeholder to keep compatibility with the previous Vitest API.
|
||||
}
|
||||
viExtended.useFakeTimers = ((..._args: Parameters<typeof vi.useFakeTimers>) => {
|
||||
return viExtended
|
||||
}) as typeof vi.useFakeTimers
|
||||
} else {
|
||||
const originalUseFakeTimers = viExtended.useFakeTimers.bind(vi)
|
||||
viExtended.useFakeTimers = (...args: Array<unknown>) => {
|
||||
originalUseFakeTimers(...args)
|
||||
}
|
||||
viExtended.useFakeTimers = ((...args: Parameters<typeof vi.useFakeTimers>) => {
|
||||
const result = originalUseFakeTimers(...args)
|
||||
return result ?? viExtended
|
||||
}) as typeof vi.useFakeTimers
|
||||
}
|
||||
|
||||
if (!viExtended.useRealTimers) {
|
||||
viExtended.useRealTimers = () => {
|
||||
viExtended.useRealTimers = ((..._args: Parameters<typeof vi.useRealTimers>) => {
|
||||
fixedTimestamp = null
|
||||
applyFixedDate()
|
||||
}
|
||||
return viExtended
|
||||
}) as typeof vi.useRealTimers
|
||||
} else {
|
||||
const originalUseRealTimers = viExtended.useRealTimers.bind(vi)
|
||||
viExtended.useRealTimers = (...args: Array<unknown>) => {
|
||||
originalUseRealTimers(...args)
|
||||
viExtended.useRealTimers = ((...args: Parameters<typeof vi.useRealTimers>) => {
|
||||
const result = originalUseRealTimers(...args)
|
||||
fixedTimestamp = null
|
||||
applyFixedDate()
|
||||
}
|
||||
return result ?? viExtended
|
||||
}) as typeof vi.useRealTimers
|
||||
}
|
||||
|
||||
applyFixedDate()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue