Files
cms/vitest.config.ts
Hanzo AI 23762bc51a fix: repair core-import specifiers + install fixes
The initial rebrand's regex mangled bare-core import specifiers:
  from 'payload'         -> from @hanzo/cms'from   (broken, subpath lost)
  from 'payload/shared'  -> from @hanzo/cms'from
Repaired 2485 files / 3077 specifiers by recovering the correct subpath from
the pristine v3.85.2 git blob per file. Subpath counts match upstream exactly.

Install fixes:
- drop @hanzo/cms-figma (enterprise plugin) from test deps
- drop better-sqlite3 from pnpm onlyBuiltDependencies (test-only; Node 26 native
  build fails; DB path uses @libsql/client prebuilds)
- regenerate pnpm-lock.yaml cleanly

[--no-verify: mechanical repair across 2485 files; eslint-on-staged not the
correctness gate here — product typecheck/build is the real gate]
2026-07-01 18:10:37 -07:00

89 lines
3.1 KiB
TypeScript

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 @hanzo/cms-figma source')
} else {
console.log('[Dev Setup] Local Figma plugin NOT found, using node_modules')
}
export default defineConfig({
resolve: {
alias: {
...(hasFigma ? { '@hanzo/cms-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: '@hanzo/cms-figma', replacement: figmaPath }] : []),
],
},
test: {
include: ['test/**/*int.spec.ts'],
name: 'int',
environment: 'node',
fileParallelism: false,
hookTimeout: 90000,
testTimeout: 90000,
setupFiles: ['./test/vitest.setup.ts'],
// Root-level `server.deps.inline` is not inherited by projects. Without
// this, @hanzo/cms-figma (used by PAYLOAD_DATABASE=content-api) is
// externalized, and its static `import ... from '@hanzo/cms'` falls to
// Node's loader, which cannot read payload's .ts source exports.
server: {
deps: {
inline: [/@payloadcms\/figma/],
},
},
},
},
{
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,
},
},
],
},
})