-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
52 lines (49 loc) · 1.79 KB
/
Copy pathvitest.config.ts
File metadata and controls
52 lines (49 loc) · 1.79 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { cloudflareTest, readD1Migrations } from '@cloudflare/vitest-pool-workers'
import { defineConfig } from 'vitest/config'
import { fileURLToPath } from 'node:url'
// Migrations are read here, in Node, and handed to the tests through `provide`.
// workerd has no filesystem, so a test cannot read them itself — applying the
// real files is what makes these tests fail when a migration and a query drift
// apart, which is the entire reason for testing against D1 rather than mocks.
const migrations = await readD1Migrations(
fileURLToPath(new URL('./migrations', import.meta.url)),
)
const alias = { '~': new URL('./src/', import.meta.url).pathname }
// Two projects, because most of this codebase is pure logic that does not need a
// workerd isolate. Running pkt-line parsing or diffing through the Workers pool
// would only make the suite slower and harder to debug.
//
// unit - parsers, diffing, name encoding, CI plan building
// worker - anything touching D1, KV, R2, or the Artifacts binding
//
// vitest-pool-workers 0.20 (the Vitest 4 rewrite) replaced defineWorkersProject
// with the cloudflareTest() plugin; the old `@cloudflare/vitest-pool-workers/config`
// entrypoint no longer exists.
export default defineConfig({
test: {
projects: [
{
resolve: { alias },
test: {
name: 'unit',
environment: 'node',
include: ['test/unit/**/*.test.ts'],
},
},
{
resolve: { alias },
plugins: [
cloudflareTest({
wrangler: { configPath: './wrangler.test.jsonc' },
}),
],
test: {
name: 'worker',
include: ['test/worker/**/*.test.ts'],
setupFiles: ['./test/worker/setup.ts'],
provide: { migrations },
},
},
],
},
})