Files
supabase/apps/docs/vitest.globalSetup.ts
Katerina Skroumpelou 4b2e9a206c fix(docs): scope js-libs-update vitest run and make tests self-contained (#46737)
The `Update JS Client Libraries Docs` workflow's "Refresh
reference-content snapshot" step fails because `npx vitest run --update
scripts/build-reference-content.test.ts` is treated as a filter, not a
restriction, under Vitest 4, so all docs tests
run. `CodeSample.test.ts` then fails with ENOENT on
`apps/docs/examples/_internal/fixtures/*` because the workflow bypasses
the `pretest` npm hook that runs `codegen:examples`.
  
This is a regression of #44943 (commit 28ef62cf31), reintroduced by
#46163 when the snapshot step was renamed and rewritten back to the
file-path form.
  
Fixes:
- Workflow: use `--dir scripts` so only the snapshot test runs.
- Tests: add a vitest globalSetup that mirrors `codegen:examples`, so
`npx vitest`, `pnpm test:local`, and IDE single-test runs no longer
depend on the `pretest` lifecycle hook being triggered first.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Updated test infrastructure configuration and initialization process
for improved test suite management.
* Refined test execution workflow to efficiently manage test discovery
and execution across project directories.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-08 15:33:20 +03:00

17 lines
757 B
TypeScript

import { cpSync, existsSync } from 'node:fs'
import { join } from 'node:path'
// Mirrors `pnpm run codegen:examples` so the test suite is self-contained.
// CodeSample.test.ts reads fixtures from apps/docs/examples/_internal/fixtures/,
// which are sourced from the repo-root examples/ directory. Without this,
// `npx vitest`, `pnpm test:local`, or IDE single-test runs all fail with ENOENT
// because they bypass the `pretest` npm lifecycle hook.
export default function setup() {
const source = join(import.meta.dirname, '..', '..', 'examples')
const dest = join(import.meta.dirname, 'examples')
if (!existsSync(source)) {
throw new Error(`Expected repo-root examples directory at ${source}`)
}
cpSync(source, dest, { recursive: true })
}