Skip to content

Commit 04d5812

Browse files
committed
fix(frontend): fix tests
1 parent 05c022b commit 04d5812

5 files changed

Lines changed: 37 additions & 21 deletions

File tree

frontend/pnpm-lock.yaml

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

frontend/test/component/StandingsUnit.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,20 @@ const {
1414
authReadyMock,
1515
updateTeamMock,
1616
assignLeadMock,
17-
routeMock,
18-
routerMock,
1917
nowMock,
2018
} = vi.hoisted(() => ({
2119
queryMock: vi.fn(),
2220
authMock: vi.fn(),
2321
authReadyMock: vi.fn(),
2422
updateTeamMock: vi.fn(),
2523
assignLeadMock: vi.fn(),
26-
routeMock: vi.fn(),
27-
routerMock: vi.fn(),
2824
nowMock: vi.fn(),
2925
}))
3026
mockNuxtImport('useStandingsUnitPageQuery', () => queryMock)
3127
mockNuxtImport('useAuth', () => authMock)
3228
mockNuxtImport('useAuthReady', () => authReadyMock)
3329
mockNuxtImport('useUpdateTeamMutation', () => updateTeamMock)
3430
mockNuxtImport('useAssignTeamLeadMutation', () => assignLeadMock)
35-
mockNuxtImport('useRoute', () => routeMock)
36-
mockNuxtImport('useRouter', () => routerMock)
3731
mockNuxtImport('useNow', () => nowMock)
3832

3933
type Member = { id: string; name: string; rank?: number; tags?: string[] }
@@ -74,8 +68,6 @@ function mountWith(state: QueryState) {
7468
})
7569
updateTeamMock.mockReturnValue({ executeMutation: vi.fn() })
7670
assignLeadMock.mockReturnValue({ executeMutation: vi.fn() })
77-
routeMock.mockReturnValue({ query: {} })
78-
routerMock.mockReturnValue({ replace: vi.fn() })
7971
nowMock.mockReturnValue(ref(new Date('2020-01-01T00:00:00Z')))
8072
// All child components render for real; only the data composables are mocked.
8173
return mountSuspended(StandingsUnit)

frontend/test/component/StandingsUnitEdit.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,37 @@ const {
1616
authReadyMock,
1717
updateTeamMock,
1818
assignLeadMock,
19-
routeMock,
20-
routerMock,
2119
nowMock,
20+
routerReplace,
2221
} = vi.hoisted(() => ({
2322
queryMock: vi.fn(),
2423
authMock: vi.fn(),
2524
authReadyMock: vi.fn(),
2625
updateTeamMock: vi.fn(),
2726
assignLeadMock: vi.fn(),
28-
routeMock: vi.fn(),
29-
routerMock: vi.fn(),
3027
nowMock: vi.fn(),
28+
routerReplace: vi.fn(),
3129
}))
3230
mockNuxtImport('useStandingsUnitPageQuery', () => queryMock)
3331
mockNuxtImport('useAuth', () => authMock)
3432
mockNuxtImport('useAuthReady', () => authReadyMock)
3533
mockNuxtImport('useUpdateTeamMutation', () => updateTeamMock)
3634
mockNuxtImport('useAssignTeamLeadMutation', () => assignLeadMock)
37-
mockNuxtImport('useRoute', () => routeMock)
38-
mockNuxtImport('useRouter', () => routerMock)
3935
mockNuxtImport('useNow', () => nowMock)
36+
// v4 (@nuxt/test-utils 4) inits Nuxt in beforeAll, so its router plugin calls
37+
// beforeEach/options on useRouter() during setup. Wrap the *real* router (via
38+
// the original passed to the factory) and only override replace with our spy,
39+
// rather than replacing the whole router with a bare stub.
40+
mockNuxtImport('useRouter', (original) => () => {
41+
const router = original()
42+
router.replace = routerReplace
43+
return router
44+
})
4045

4146
// Spies we assert against.
4247
const updateTeam = vi.fn()
4348
const assignLead = vi.fn()
4449
const refetch = vi.fn()
45-
const routerReplace = vi.fn()
4650

4751
// --- Stubs -------------------------------------------------------------------
4852
// Only two child components are stubbed, and both for a concrete reason:
@@ -96,8 +100,6 @@ async function mountEdit(opts: { now?: Date } = {}) {
96100
})
97101
updateTeamMock.mockReturnValue({ executeMutation: updateTeam })
98102
assignLeadMock.mockReturnValue({ executeMutation: assignLead })
99-
routeMock.mockReturnValue({ query: {} })
100-
routerMock.mockReturnValue({ replace: routerReplace })
101103
nowMock.mockReturnValue(ref(opts.now ?? new Date('2030-01-01T00:00:00Z')))
102104

103105
const wrapper = await mountSuspended(StandingsUnit, { global: { stubs } })

frontend/test/component/setup.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ vi.mock('@sentry/nuxt', () => ({
2020
addBreadcrumb: vi.fn(),
2121
}))
2222

23+
// The firebase client plugin (app/plugins/5.firebase.client.ts) statically
24+
// imports firebase/firestore, which pulls in the Node Firestore SDK (grpc +
25+
// protobufjs) — irrelevant to component rendering and prone to CJS/ESM interop
26+
// crashes in the test env. Stub the firebase entry points so nothing loads it.
27+
vi.mock('firebase/app', () => ({
28+
initializeApp: vi.fn(() => ({})),
29+
getApps: vi.fn(() => []),
30+
}))
31+
vi.mock('firebase/auth', () => ({
32+
getAuth: vi.fn(() => ({})),
33+
signInWithCustomToken: vi.fn(),
34+
signOut: vi.fn(),
35+
}))
36+
vi.mock('firebase/firestore', () => ({
37+
getFirestore: vi.fn(() => ({})),
38+
doc: vi.fn(),
39+
onSnapshot: vi.fn(() => vi.fn()),
40+
}))
41+
2342
vi.mock('@auth0/auth0-vue', () => ({
2443
// The auth0 plugin (app/plugins/1.auth0.ts) installs this as a Vue plugin.
2544
createAuth0: () => ({ install: () => {} }),

frontend/vitest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export default defineConfig({
2626
include: ['test/component/**/*.{test,spec}.ts'],
2727
environment: 'nuxt',
2828
setupFiles: ['test/component/setup.ts'],
29+
// The Nuxt test env (setupNuxt) builds on first run; 10s is too short.
30+
hookTimeout: 120000,
31+
testTimeout: 30000,
2932
},
3033
}),
3134
],

0 commit comments

Comments
 (0)