wip - claude --resume 742969c2-ab50-4a79-b7bd-3971e9fd314d

This commit is contained in:
Samuel Newman
2026-05-15 21:58:48 +03:00
parent f04b350f05
commit 1c60734e84
40 changed files with 1209 additions and 1571 deletions
+2 -2
View File
@@ -1,10 +1,10 @@
import {jest} from '@jest/globals'
import {beforeEach, describe, expect, it, vi} from 'vitest'
import {transparentifyColor} from '../colorGeneration'
describe('transparentifyColor', () => {
beforeEach(() => {
jest.clearAllMocks()
vi.clearAllMocks()
})
it('converts hsl() to hsla()', () => {
+25 -23
View File
@@ -1,39 +1,41 @@
jest.mock('#/storage', () => ({
import {beforeEach, describe, expect, it, vi} from 'vitest'
vi.mock('#/storage', () => ({
device: {
get: jest.fn(),
set: jest.fn(),
get: vi.fn(),
set: vi.fn(),
},
}))
jest.mock('#/analytics/identifiers/util', () => ({
isSessionIdExpired: jest.fn(),
vi.mock('#/analytics/identifiers/util', () => ({
isSessionIdExpired: vi.fn(),
}))
jest.mock('#/lib/appState', () => ({
onAppStateChange: jest.fn(() => ({remove: jest.fn()})),
vi.mock('#/lib/appState', () => ({
onAppStateChange: vi.fn(() => ({remove: vi.fn()})),
}))
beforeEach(() => {
jest.resetModules()
jest.clearAllMocks()
vi.resetModules()
vi.clearAllMocks()
})
function getMocks() {
const {device} = require('#/storage')
const {isSessionIdExpired} = require('#/analytics/identifiers/util')
async function getMocks() {
const {device} = await import('#/storage')
const {isSessionIdExpired} = await import('#/analytics/identifiers/util')
return {
device: jest.mocked(device),
isSessionIdExpired: jest.mocked(isSessionIdExpired),
device: vi.mocked(device),
isSessionIdExpired: vi.mocked(isSessionIdExpired),
}
}
describe('session initialization', () => {
it('creates new session and sets timestamp when none exists', () => {
const {device, isSessionIdExpired} = getMocks()
it('creates new session and sets timestamp when none exists', async () => {
const {device, isSessionIdExpired} = await getMocks()
device.get.mockReturnValue(undefined)
isSessionIdExpired.mockReturnValue(false)
const {getInitialSessionId} = require('./session')
const {getInitialSessionId} = await import('./session')
const id = getInitialSessionId()
expect(id).toBeDefined()
@@ -45,8 +47,8 @@ describe('session initialization', () => {
)
})
it('reuses existing session when not expired', () => {
const {device, isSessionIdExpired} = getMocks()
it('reuses existing session when not expired', async () => {
const {device, isSessionIdExpired} = await getMocks()
const existingId = 'existing-session-id'
device.get.mockImplementation((key: string[]) => {
if (key[0] === 'nativeSessionId') return existingId
@@ -55,13 +57,13 @@ describe('session initialization', () => {
})
isSessionIdExpired.mockReturnValue(false)
const {getInitialSessionId} = require('./session')
const {getInitialSessionId} = await import('./session')
expect(getInitialSessionId()).toBe(existingId)
})
it('creates new session when existing is expired', () => {
const {device, isSessionIdExpired} = getMocks()
it('creates new session when existing is expired', async () => {
const {device, isSessionIdExpired} = await getMocks()
const existingId = 'existing-session-id'
device.get.mockImplementation((key: string[]) => {
if (key[0] === 'nativeSessionId') return existingId
@@ -70,7 +72,7 @@ describe('session initialization', () => {
})
isSessionIdExpired.mockReturnValue(true)
const {getInitialSessionId} = require('./session')
const {getInitialSessionId} = await import('./session')
const id = getInitialSessionId()
expect(id).not.toBe(existingId)
+23 -21
View File
@@ -1,26 +1,28 @@
import {afterEach, beforeEach, describe, expect, it, type Mock, vi} from 'vitest'
import {MetricsClient} from './client'
let appStateCallback: (state: string) => void
jest.mock('#/lib/appState', () => ({
onAppStateChange: jest.fn(cb => {
vi.mock('#/lib/appState', () => ({
onAppStateChange: vi.fn(cb => {
appStateCallback = cb
return {remove: jest.fn()}
return {remove: vi.fn()}
}),
}))
jest.mock('#/logger', () => ({
vi.mock('#/logger', () => ({
Logger: {
create: () => ({
info: jest.fn(),
debug: jest.fn(),
error: jest.fn(),
info: vi.fn(),
debug: vi.fn(),
error: vi.fn(),
}),
Context: {Metric: 'metric'},
},
}))
jest.mock('#/env', () => ({
vi.mock('#/env', () => ({
METRICS_API_HOST: 'https://test.metrics.api',
IS_WEB: false,
}))
@@ -31,13 +33,13 @@ type TestEvents = {
}
describe('MetricsClient', () => {
let fetchMock: jest.Mock
let fetchMock: Mock
let fetchRequests: {body: any}[]
beforeEach(() => {
jest.useFakeTimers({advanceTimers: true})
vi.useFakeTimers({shouldAdvanceTime: true})
fetchRequests = []
fetchMock = jest.fn().mockImplementation(async (_url, options) => {
fetchMock = vi.fn().mockImplementation(async (_url, options) => {
const body = JSON.parse(options.body)
fetchRequests.push({body})
return {ok: true, status: 200}
@@ -46,8 +48,8 @@ describe('MetricsClient', () => {
})
afterEach(() => {
jest.useRealTimers()
jest.clearAllMocks()
vi.useRealTimers()
vi.clearAllMocks()
})
it('flushes events on interval', async () => {
@@ -58,7 +60,7 @@ describe('MetricsClient', () => {
expect(fetchRequests).toHaveLength(0)
// Advance past the 10 second interval
await jest.advanceTimersByTimeAsync(10_000)
await vi.advanceTimersByTimeAsync(10_000)
expect(fetchRequests).toHaveLength(1)
expect(fetchRequests[0].body.events).toHaveLength(2)
@@ -81,7 +83,7 @@ describe('MetricsClient', () => {
client.track('click', {button: 'btn-trigger'})
// Allow microtasks to run
await jest.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(0)
expect(fetchRequests).toHaveLength(1)
expect(fetchRequests[0].body.events).toHaveLength(6)
@@ -112,14 +114,14 @@ describe('MetricsClient', () => {
client.track('click', {button: 'submit'})
// Trigger flush via interval
await jest.advanceTimersByTimeAsync(10_000)
await vi.advanceTimersByTimeAsync(10_000)
expect(requestCount).toBe(1)
expect(fetchRequests).toHaveLength(0)
// Simulate app coming to foreground to trigger retry
appStateCallback('active')
await jest.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(0)
expect(requestCount).toBe(2)
expect(fetchRequests).toHaveLength(1)
@@ -144,19 +146,19 @@ describe('MetricsClient', () => {
client.track('click', {button: 'submit'})
// First flush fails
await jest.advanceTimersByTimeAsync(10_000)
await vi.advanceTimersByTimeAsync(10_000)
expect(requestCount).toBe(1)
// Retry also fails
appStateCallback('active')
await jest.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(0)
expect(requestCount).toBe(2)
// Another foreground event should not retry again (events are dropped)
appStateCallback('active')
await jest.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(0)
expect(requestCount).toBe(2) // No additional requests
})
@@ -169,7 +171,7 @@ describe('MetricsClient', () => {
// Simulate app going to background
appStateCallback('background')
await jest.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(0)
expect(fetchRequests).toHaveLength(1)
})
@@ -1,11 +1,11 @@
import {describe, test} from '@jest/globals'
import {describe, expect, test, vi} from 'vitest'
import {
computeCompletedState,
syncCompletedState,
} from '#/components/PolicyUpdateOverlay/usePolicyUpdateState'
jest.mock('../../../state/queries/nuxs')
vi.mock('../../../state/queries/nuxs')
describe('computeCompletedState', () => {
test(`initial state`, () => {
@@ -67,8 +67,8 @@ describe('computeCompletedState', () => {
describe('syncCompletedState', () => {
describe('!nuxIsReady', () => {
test(`!completedForDevice, no-op`, () => {
const save = jest.fn()
const setCompletedForDevice = jest.fn()
const save = vi.fn()
const setCompletedForDevice = vi.fn()
syncCompletedState({
nuxIsReady: false,
nuxIsCompleted: false,
@@ -83,8 +83,8 @@ describe('syncCompletedState', () => {
})
test(`completedForDevice, no-op`, () => {
const save = jest.fn()
const setCompletedForDevice = jest.fn()
const save = vi.fn()
const setCompletedForDevice = vi.fn()
syncCompletedState({
nuxIsReady: false,
nuxIsCompleted: false,
@@ -103,8 +103,8 @@ describe('syncCompletedState', () => {
describe(`!nuxIsCompleted`, () => {
describe(`!nuxIsOptimisticallyCompleted`, () => {
test(`!completedForDevice, no-op`, () => {
const save = jest.fn()
const setCompletedForDevice = jest.fn()
const save = vi.fn()
const setCompletedForDevice = vi.fn()
syncCompletedState({
nuxIsReady: true,
nuxIsCompleted: false,
@@ -119,8 +119,8 @@ describe('syncCompletedState', () => {
})
test(`completedForDevice, syncs to server`, () => {
const save = jest.fn()
const setCompletedForDevice = jest.fn()
const save = vi.fn()
const setCompletedForDevice = vi.fn()
syncCompletedState({
nuxIsReady: true,
nuxIsCompleted: false,
@@ -141,8 +141,8 @@ describe('syncCompletedState', () => {
*/
describe(`nuxIsOptimisticallyCompleted`, () => {
test(`completedForDevice, no-op`, () => {
const save = jest.fn()
const setCompletedForDevice = jest.fn()
const save = vi.fn()
const setCompletedForDevice = vi.fn()
syncCompletedState({
nuxIsReady: true,
nuxIsCompleted: false,
@@ -160,8 +160,8 @@ describe('syncCompletedState', () => {
describe(`nuxIsCompleted`, () => {
test(`!completedForDevice, syncs to device`, () => {
const save = jest.fn()
const setCompletedForDevice = jest.fn()
const save = vi.fn()
const setCompletedForDevice = vi.fn()
syncCompletedState({
nuxIsReady: true,
nuxIsCompleted: true,
@@ -176,8 +176,8 @@ describe('syncCompletedState', () => {
})
test(`completedForDevice, no-op`, () => {
const save = jest.fn()
const setCompletedForDevice = jest.fn()
const save = vi.fn()
const setCompletedForDevice = vi.fn()
syncCompletedState({
nuxIsReady: true,
nuxIsCompleted: true,
+1 -1
View File
@@ -1,4 +1,4 @@
import {describe, expect, it} from '@jest/globals'
import {describe, expect, it} from 'vitest'
import {parseLinkingUrl} from '../parseLinkingUrl'
@@ -1,6 +1,6 @@
import {beforeEach, describe, expect, it, jest} from '@jest/globals'
import {beforeEach, describe, expect, it, vi} from 'vitest'
jest.mock('@bsky.app/react-native-mmkv', () => ({
vi.mock('@bsky.app/react-native-mmkv', () => ({
MMKV: class MMKVMock {
_store = new Map<string, string>()
+1 -1
View File
@@ -1,4 +1,4 @@
import {describe, expect, it} from '@jest/globals'
import {describe, expect, it} from 'vitest'
import {addDays, subDays, subHours, subMinutes, subSeconds} from 'date-fns'
import {dateDiff} from '../useTimeAgo'
+1 -1
View File
@@ -1,4 +1,4 @@
import {expect, test} from '@jest/globals'
import {expect, test} from 'vitest'
import {sanitizeAppLanguageSetting} from '#/locale/helpers'
import {AppLanguage} from '#/locale/languages'
+1 -1
View File
@@ -1,4 +1,4 @@
import {expect, test} from '@jest/globals'
import {expect, test} from 'vitest'
import {add, type ConsoleTransportEntry, getEntries} from '#/logger/logDump'
import {LogContext, LogLevel} from '#/logger/types'
+20 -20
View File
@@ -1,4 +1,4 @@
import {beforeAll, describe, expect, jest, test} from '@jest/globals'
import {beforeAll, describe, expect, test, vi} from 'vitest'
import * as Sentry from '@sentry/react-native'
import {nanoid} from 'nanoid/non-secure'
@@ -6,14 +6,14 @@ import {Logger} from '#/logger'
import {sentryTransport} from '#/logger/transports/sentry'
import {LogLevel} from '#/logger/types'
jest.mock('@sentry/react-native', () => ({
addBreadcrumb: jest.fn(),
captureException: jest.fn(),
captureMessage: jest.fn(),
vi.mock('@sentry/react-native', () => ({
addBreadcrumb: vi.fn(),
captureException: vi.fn(),
captureMessage: vi.fn(),
}))
beforeAll(() => {
jest.useFakeTimers()
vi.useFakeTimers()
})
describe('general functionality', () => {
@@ -41,7 +41,7 @@ describe('general functionality', () => {
const timestamp = Date.now()
const logger = new Logger({})
const mockTransport = jest.fn()
const mockTransport = vi.fn()
logger.addTransport(mockTransport)
@@ -63,7 +63,7 @@ describe('general functionality', () => {
metadata: {bar: true},
})
const mockTransport = jest.fn()
const mockTransport = vi.fn()
logger.addTransport(mockTransport)
@@ -83,7 +83,7 @@ describe('general functionality', () => {
const timestamp = Date.now()
const logger = new Logger({})
const mockTransport = jest.fn()
const mockTransport = vi.fn()
const remove = logger.addTransport(mockTransport)
@@ -181,7 +181,7 @@ describe('general functionality', () => {
level: 'log',
timestamp: sentryTimestamp,
})
jest.runAllTimers()
vi.runAllTimers()
expect(Sentry.captureMessage).toHaveBeenCalledWith(message, {
level: 'log',
tags: {category: 'logger'},
@@ -203,7 +203,7 @@ describe('general functionality', () => {
level: 'warning',
timestamp: sentryTimestamp,
})
jest.runAllTimers()
vi.runAllTimers()
expect(Sentry.captureMessage).toHaveBeenCalledWith(message, {
level: 'warning',
tags: {category: 'logger'},
@@ -262,7 +262,7 @@ describe('general functionality', () => {
test('add/remove transport', () => {
const timestamp = Date.now()
const logger = new Logger({})
const mockTransport = jest.fn()
const mockTransport = vi.fn()
const remove = logger.addTransport(mockTransport)
@@ -286,7 +286,7 @@ describe('general functionality', () => {
describe('create', () => {
test('create', () => {
const mockTransport = jest.fn()
const mockTransport = vi.fn()
const timestamp = Date.now()
const message = nanoid()
const logger = Logger.create(Logger.Context.Default)
@@ -306,7 +306,7 @@ describe('create', () => {
describe('debug contexts', () => {
test('specific', () => {
const mockTransport = jest.fn()
const mockTransport = vi.fn()
const timestamp = Date.now()
const message = nanoid()
const logger = new Logger({
@@ -328,7 +328,7 @@ describe('debug contexts', () => {
})
test('namespaced', () => {
const mockTransport = jest.fn()
const mockTransport = vi.fn()
const timestamp = Date.now()
const message = nanoid()
const logger = new Logger({
@@ -351,7 +351,7 @@ describe('debug contexts', () => {
})
test('ignores inactive', () => {
const mockTransport = jest.fn()
const mockTransport = vi.fn()
const timestamp = Date.now()
const message = nanoid()
const logger = new Logger({
@@ -380,7 +380,7 @@ describe('supports levels', () => {
level: LogLevel.Debug,
})
const message = nanoid()
const mockTransport = jest.fn()
const mockTransport = vi.fn()
logger.addTransport(mockTransport)
@@ -428,7 +428,7 @@ describe('supports levels', () => {
level: LogLevel.Info,
})
const message = nanoid()
const mockTransport = jest.fn()
const mockTransport = vi.fn()
logger.addTransport(mockTransport)
@@ -451,7 +451,7 @@ describe('supports levels', () => {
level: LogLevel.Warn,
})
const message = nanoid()
const mockTransport = jest.fn()
const mockTransport = vi.fn()
logger.addTransport(mockTransport)
@@ -477,7 +477,7 @@ describe('supports levels', () => {
level: LogLevel.Error,
})
const message = nanoid()
const mockTransport = jest.fn()
const mockTransport = vi.fn()
logger.addTransport(mockTransport)
+1 -1
View File
@@ -1,4 +1,4 @@
import {describe, expect, it} from '@jest/globals'
import {describe, expect, it} from 'vitest'
import {parseSearchQuery} from '#/screens/Search/utils'
+1 -1
View File
@@ -1,4 +1,4 @@
import {describe, it} from '@jest/globals'
import {describe, it} from 'vitest'
describe(`#/state/messages/convo`, () => {
describe(`init`, () => {
+5 -5
View File
@@ -1,25 +1,25 @@
import {jest} from '@jest/globals'
import {vi} from 'vitest'
export {Nux} from '#/state/queries/nuxs/definitions'
export const useNuxs = jest.fn(() => {
export const useNuxs = vi.fn(() => {
return {
nuxs: undefined,
status: 'loading' as const,
}
})
export const useNux = jest.fn((id: string) => {
export const useNux = vi.fn((id: string) => {
return {
nux: undefined,
status: 'loading' as const,
}
})
export const useSaveNux = jest.fn(() => {
export const useSaveNux = vi.fn(() => {
return {}
})
export const useResetNuxs = jest.fn(() => {
export const useResetNuxs = vi.fn(() => {
return {}
})
+6 -6
View File
@@ -1,21 +1,21 @@
import {BskyAgent} from '@atproto/api'
import {describe, expect, it, jest} from '@jest/globals'
import {describe, expect, it, vi} from 'vitest'
import {agentToSessionAccountOrThrow} from '../agent'
import {type Action, getInitialState, reducer, type State} from '../reducer'
jest.mock('jwt-decode', () => ({
vi.mock('jwt-decode', () => ({
jwtDecode(_token: string) {
return {}
},
}))
jest.mock('../../birthdate')
jest.mock('../../../ageAssurance/data')
jest.mock('../../../ageAssurance/state', () => ({
vi.mock('../../birthdate')
vi.mock('../../../ageAssurance/data')
vi.mock('../../../ageAssurance/state', () => ({
getAndComputeAgeAssuranceState: () => ({}),
}))
jest.mock('#/lib/notifications/notifications', () => ({
vi.mock('#/lib/notifications/notifications', () => ({
unregisterPushToken(_agents: BskyAgent[]) {
return Promise.resolve()
},
+2 -2
View File
@@ -1,8 +1,8 @@
import {beforeEach, expect, jest, test} from '@jest/globals'
import {beforeEach, expect, test, vi} from 'vitest'
import {Storage} from '#/storage'
jest.mock('@bsky.app/react-native-mmkv', () => ({
vi.mock('@bsky.app/react-native-mmkv', () => ({
MMKV: class MMKVMock {
_store = new Map()