test(desktop): load ConfigSettings once in beforeAll so the autosave test's 15s budget is not spent on the import

The autosave test did `await import('./config-settings')` inside the test
body. That module graph is large: 1.5s cold on an idle machine, and on a
saturated CI runner (import 1682s aggregate across the run) it alone
crossed the 15s testTimeout twice today on PRs that never touched the file.
The assertions themselves take ~100ms. Hoisting the import into a
beforeAll with its own 60s hookTimeout keeps the test's budget for the
behaviour under test; the fault-injection mocks are hoisted vi.mock calls
and still apply.
This commit is contained in:
teknium1
2026-09-13 09:26:26 -07:00
committed by Teknium
parent 5dea46d13d
commit 7d2bb463c4
@@ -3,7 +3,9 @@ import { cleanup, render, screen } from '@testing-library/react'
import { atom } from 'nanostores'
import { createRef } from 'react'
import { MemoryRouter } from 'react-router'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import type { ConfigSettings as ConfigSettingsType } from './config-settings'
const getHermesConfigRecord = vi.fn()
const getHermesConfigSchema = vi.fn()
@@ -36,6 +38,15 @@ vi.mock('@/store/projects', () => ({
scanAndRecordRepos: vi.fn().mockResolvedValue(undefined)
}))
// The module graph behind ConfigSettings is large (1.5s cold here, >10s on a
// saturated CI runner); load it once under the hook timeout so the 15s test
// budget is spent on the autosave behaviour, not on transform + import.
let ConfigSettings: typeof ConfigSettingsType
beforeAll(async () => {
;({ ConfigSettings } = await import('./config-settings'))
}, 60_000)
beforeEach(() => {
getElevenLabsVoices.mockResolvedValue({ available: false })
getHermesConfigSchema.mockResolvedValue({ fields: {} })
@@ -47,8 +58,7 @@ afterEach(() => {
vi.clearAllMocks()
})
async function renderConfigSettings() {
const { ConfigSettings } = await import('./config-settings')
function renderConfigSettings() {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
const importInputRef = createRef<HTMLInputElement>()
@@ -70,7 +80,7 @@ describe('ConfigSettings autosave', () => {
vi.useFakeTimers({ shouldAdvanceTime: true })
try {
await renderConfigSettings()
renderConfigSettings()
const toggle = await screen.findByRole('switch')