-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathvitest.config.ts
More file actions
79 lines (75 loc) · 2.67 KB
/
vitest.config.ts
File metadata and controls
79 lines (75 loc) · 2.67 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { createRequire } from 'module'
import path from 'path'
import fs from 'fs'
import { defineConfig } from 'vitest/config'
// Use process.cwd() to be safe in both CJS and ESM contexts within Vitest
const ROOT_DIR = process.cwd()
const figmaPath = path.resolve(ROOT_DIR, '../enterprise-plugins/packages/figma/src/index.ts')
const hasFigma = fs.existsSync(figmaPath)
// Resolve graphql to a single copy to avoid duplicate-instance issues (instanceof checks fail).
// pnpm's isolated linker means graphql isn't hoisted to root node_modules, so we resolve
// the actual path from packages/graphql where it's a direct dependency.
// https://github.com/vitest-dev/vitest/issues/4605
const _require = createRequire(path.resolve(ROOT_DIR, 'packages/graphql/package.json'))
const graphqlDir = path.dirname(_require.resolve('graphql/package.json'))
console.log('[Dev Setup] Checking for local Figma plugin at:', figmaPath)
if (hasFigma) {
console.log('[Dev Setup] Using local @payloadcms/figma source')
} else {
console.log('[Dev Setup] Local Figma plugin NOT found, using node_modules')
}
export default defineConfig({
resolve: {
alias: {
...(hasFigma ? { '@payloadcms/figma': figmaPath } : {}),
},
},
test: {
watch: false, // too troublesome especially with the in memory DB setup
// Retry failed tests up to 2 times in CI to handle flaky tests (e.g. due to timing-sensitive int tests like job queues, installation failures due to temporary network issues)
retry: process.env.CI ? 2 : 0,
server: {
deps: {
inline: [/@payloadcms\/figma/],
},
},
projects: [
{
test: {
include: ['packages/**/*.spec.ts'],
name: 'unit',
environment: 'node',
},
},
{
resolve: {
alias: [
{ find: /^graphql\/(.*)/, replacement: graphqlDir + '/$1' },
{ find: /^graphql$/, replacement: path.join(graphqlDir, 'index.js') },
...(hasFigma ? [{ find: '@payloadcms/figma', replacement: figmaPath }] : []),
],
},
test: {
include: ['test/**/*int.spec.ts'],
name: 'int',
environment: 'node',
fileParallelism: false,
hookTimeout: 90000,
testTimeout: 90000,
setupFiles: ['./test/vitest.setup.ts'],
},
},
{
test: {
include: ['test/evals/**/*.spec.ts'],
name: 'eval',
environment: 'node',
fileParallelism: false,
globalSetup: ['test/evals/globalSetup.ts'],
// 10 minutes per test: LLM call (~60-120s) + tsc wait + scorer + buffer.
testTimeout: 600000,
},
},
],
},
})