Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
150 lines (146 loc) · 4.97 KB
/
Copy pathvitest.config.ts
File metadata and controls
150 lines (146 loc) · 4.97 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { createRequire } from 'module'
import path from 'path'
import fs from 'fs'
import { playwright } from '@vitest/browser-playwright'
import { defaultExclude, 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 =
process.env.PAYLOAD_FIGMA_PLUGIN_PATH ??
path.resolve(ROOT_DIR, '../figma/payload/payload-plugin/src/index.ts')
const hasFigma = fs.existsSync(figmaPath)
const evalFixturesDir = path.resolve(ROOT_DIR, 'test/evals/fixtures')
const shouldWriteEvalReport = process.env.VITEST_EVAL_REPORT === 'true'
// 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({
// Vite 8 / oxc reads `jsx: preserve` from the workspace tsconfig (needed by Next.js)
// and refuses to transform JSX. Set jsx explicitly here so oxc transforms it.
oxc: {
jsx: {
runtime: 'automatic',
importSource: 'react',
},
},
resolve: {
alias: {
...(hasFigma ? { '@payloadcms/figma': figmaPath } : {}),
},
},
test: {
reporters: shouldWriteEvalReport
? [
'default',
[
'html',
{
outputDir: 'test/evals/eval-results',
singleFile: true,
},
],
]
: ['default'],
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: {
// Without this, @payloadcms/figma (used by PAYLOAD_DATABASE=content-api) is
// externalized, and its static `import ... from 'payload'` falls to
// Node's loader, which cannot read payload's .ts source exports.
deps: {
inline: [/@payloadcms\/figma/],
},
},
projects: [
{
test: {
exclude: [...defaultExclude, '**/*.rsc.spec.ts'],
include: [
'packages/**/*.spec.ts',
'tools/**/*.spec.ts',
'test/**/*.unit.spec.ts',
'.github/scripts/**/*.spec.mjs',
],
name: 'unit',
environment: 'node',
execArgv: ['--expose-gc'],
},
},
{
optimizeDeps: {
include: ['monaco-editor'],
},
resolve: {
dedupe: ['react', 'react-dom'],
},
test: {
include: ['packages/**/*.spec.tsx'],
name: 'components',
browser: {
enabled: true,
headless: true,
provider: playwright({ launchOptions: { channel: 'chromium' } }),
instances: [{ browser: 'chromium' }],
},
},
},
{
resolve: {
conditions: ['react-server'],
},
test: {
include: ['packages/next/**/*.rsc.spec.ts'],
name: 'rsc',
environment: 'node',
},
},
{
resolve: {
alias: [
{ find: /^graphql\/(.*)/, replacement: graphqlDir + '/$1' },
{ find: /^graphql$/, replacement: path.join(graphqlDir, 'index.js') },
],
},
test: {
include: ['test/**/*int.spec.ts'],
name: 'int',
environment: 'node',
fileParallelism: false,
hookTimeout: 90000,
testTimeout: 90000,
setupFiles: ['./test/vitest.setup.ts'],
},
},
{
resolve: {
// Eval fixture configs use `@/db-stub.js` as a fixture-local alias.
// TSC knows that from `test/evals/fixtures/tsconfig.json`, but runtime
// `verify({ config })` imports generated fixture configs through Vite,
// so this project needs the same alias for those imports to resolve.
alias: [{ find: /^@\//, replacement: `${evalFixturesDir}/` }],
},
test: {
include: ['test/evals/**/*.spec.ts'],
name: 'eval',
environment: 'node',
fileParallelism: false,
globalSetup: ['test/evals/globalSetup.ts'],
// Loads .env
setupFiles: ['./test/evals/vitest.setup.ts'],
// 10 minutes per test: LLM call (~60-120s) + tsc wait + scorer + buffer.
testTimeout: 600000,
},
},
],
},
})