-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfastify.ts
More file actions
32 lines (25 loc) · 1.15 KB
/
fastify.ts
File metadata and controls
32 lines (25 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
import type { FastifyInstance } from 'fastify'
import Fastify from 'fastify'
import app from '../../src/app.js'
import { setTestEmailProvider } from '../../src/lib/auth.js'
import { FakeEmailProvider } from './fake-email.js'
export async function buildTestApp(): Promise<FastifyInstance> {
// Create fake email provider first
const fakeEmailProvider = new FakeEmailProvider()
// Set test email provider BEFORE creating Fastify instance
setTestEmailProvider(fakeEmailProvider)
const logLevel =
(process.env.TEST_LOG_LEVEL as 'silent' | 'fatal' | 'error' | 'warn' | 'info' | 'debug') ??
'silent'
const fastify = Fastify({
logger: { level: logLevel },
pluginTimeout: 30_000,
}).withTypeProvider<TypeBoxTypeProvider>()
await fastify.register(app)
await fastify.ready()
// Attach fake email provider to fastify instance for test access
;(fastify as FastifyInstance & { fakeEmail: FakeEmailProvider }).fakeEmail = fakeEmailProvider
return fastify as FastifyInstance & { fakeEmail: FakeEmailProvider }
}
export type TestApp = Awaited<ReturnType<typeof buildTestApp>>