Skip to content
File

Blob: vitest.config.ts

typescript76 lines
1import { fileURLToPath, URL } from "node:url";
2import { cloudflareTest, readD1Migrations } from "@cloudflare/vitest-pool-workers";
3import { defineConfig, defineProject } from "vitest/config";
4 
5const srcDirectory = fileURLToPath(new URL("./src", import.meta.url));
6const drizzleDirectory = fileURLToPath(new URL("./drizzle", import.meta.url));
7const VITEST_POOL_COMPATIBILITY_FLAGS = [
8 "enable_nodejs_tty_module",
9 "enable_nodejs_fs_module",
10 "enable_nodejs_http_modules",
11 "enable_nodejs_perf_hooks_module",
12 "enable_nodejs_v8_module",
13 "enable_nodejs_process_v2",
14];
15 
16export default defineConfig(async () => {
17 const migrations = await readD1Migrations(drizzleDirectory);
18 const workerPoolOptions = {
19 wrangler: {
20 configPath: "./wrangler.jsonc",
21 },
22 miniflare: {
23 compatibilityFlags: VITEST_POOL_COMPATIBILITY_FLAGS,
24 bindings: {
25 TESSERA_OIDC_ISSUER: "http://127.0.0.1:6174",
26 TESSERA_OIDC_CLIENT_ID: "local-flamemail",
27 TESSERA_OIDC_CLIENT_SECRET: "local-flamemail-secret-change-me",
28 TESSERA_OPERATOR_SUBS: "00000000-0000-4000-8000-000000000001",
29 TURNSTILE_SITE_KEY: "1x00000000000000000000AA",
30 TURNSTILE_SECRET_KEY: "1x0000000000000000000000000000000AA",
31 TEST_MIGRATIONS: migrations,
32 },
33 },
34 };
35 
36 return {
37 test: {
38 projects: [
39 defineProject({
40 resolve: {
41 alias: {
42 "@": srcDirectory,
43 },
44 },
45 test: {
46 name: "client",
47 environment: "jsdom",
48 include: ["tests/client/**/*.test.ts", "tests/client/**/*.test.tsx"],
49 setupFiles: ["./tests/setup/client.ts"],
50 },
51 }),
52 defineProject({
53 plugins: [cloudflareTest(workerPoolOptions)],
54 resolve: {
55 alias: {
56 "@": srcDirectory,
57 },
58 },
59 test: {
60 name: "worker",
61 include: ["tests/worker/**/*.test.ts"],
62 setupFiles: ["./tests/setup/worker.ts"],
63 },
64 }),
65 defineProject({
66 test: {
67 name: "scripts",
68 environment: "node",
69 include: ["tests/scripts/**/*.test.ts"],
70 },
71 }),
72 ],
73 },
74 };
75});