Add comprehensive testing covering 420 unit/handler tests across 24 Vitest files, 9 Playwright E2E specs, accessibility scans, and visual regression. Includes GitHub Actions CI, Husky pre-push hook, and TESTING.md docs.
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import { vi } from 'vitest'
|
|
import {
|
|
getCookie,
|
|
setCookie,
|
|
getMethod,
|
|
getHeader,
|
|
getHeaders,
|
|
setHeader,
|
|
getRequestURL,
|
|
createError,
|
|
defineEventHandler,
|
|
readBody,
|
|
getQuery,
|
|
getRouterParam,
|
|
sendRedirect
|
|
} from 'h3'
|
|
|
|
// Register real h3 functions as globals so server code that relies on
|
|
// Nitro auto-imports can find them in the test environment.
|
|
vi.stubGlobal('getCookie', getCookie)
|
|
vi.stubGlobal('setCookie', setCookie)
|
|
vi.stubGlobal('getMethod', getMethod)
|
|
vi.stubGlobal('getHeader', getHeader)
|
|
vi.stubGlobal('getHeaders', getHeaders)
|
|
vi.stubGlobal('setHeader', setHeader)
|
|
vi.stubGlobal('getRequestURL', getRequestURL)
|
|
vi.stubGlobal('createError', createError)
|
|
vi.stubGlobal('defineEventHandler', defineEventHandler)
|
|
vi.stubGlobal('readBody', readBody)
|
|
vi.stubGlobal('getQuery', getQuery)
|
|
vi.stubGlobal('getRouterParam', getRouterParam)
|
|
vi.stubGlobal('sendRedirect', sendRedirect)
|
|
|
|
vi.stubGlobal('useRuntimeConfig', () => ({
|
|
jwtSecret: 'test-jwt-secret',
|
|
helcimApiToken: 'test-helcim-token'
|
|
}))
|
|
|
|
// Stubs for Nitro auto-imported server/utils (used by handlers that don't explicitly import them)
|
|
vi.stubGlobal('requireAuth', vi.fn())
|
|
vi.stubGlobal('requireAdmin', vi.fn())
|
|
vi.stubGlobal('validateBody', vi.fn(async (event) => readBody(event)))
|