Testing
CI runs lint + format:check + test (npm run check) and prepack dry-run — PRs should pass the same.
Run
bash
# One-time
npm run dev:prepare # so playground .nuxt + node_modules exist
# All suites (unit + e2e)
npm run test
# Watch / coverage
npm run test:watch
npm run test:coverage
# Types (independent of Vitest)
npm run test:types # vue-tsc --noEmitConfig: vitest.config.ts (environment happy-dom), test/* as run entries. Tests do not need a live playground on ports 3000/3001 — e2e suites launch an isolated Nuxt fixture when available.
Suites
| File | Coverage |
|---|---|
test/detect-content-major.test.ts | src/utils/detect-content-major.ts:32 — walking detection for `2 |
test/normalize-toc.test.ts | src/runtime/utils/normalize-toc.ts:21 — Toc vs body.toc vs toc vs garbage, TocLink shape guard |
test/limit-toc-depth.test.ts (if present) | limitTocDepth / resolveEffectiveDepth / isSublistShown legacy |
test/content-v3.test.ts | E2e against content-v3 playground — pass-in, auto-fetch, props, settings, contentMajor === 3 runtime config |
test/content-v2.test.ts | E2e against content-v2 playground — queryContent, pass-in, auto-fetch (path only), contentMajor === 2 |
New functionality should add:
- Unit tests to
test/for pure helpers (normalize-toc,limit-toc-depth,scroll-to-heading,detect-content-major) before touching runtime. - E2e assertions that exercise a prop or module option in both playgrounds (or add a
/propsvariation) — browsing the repo’s/settingspage during review is not enough.
When tests need playgrounds
detect-content-majorunit tests use temporary directories — no playground.content-v2.test.ts/content-v3.test.tsrequireplaygrounds/*/node_modulesand.nuxt/— hencenpm run dev:preparebefore first run. If a playground install is stale, re-rundev:prepare(it reinstalls per playground prefix).
Failures to watch for
- Changing
src/module.tsdefaults without updatingnormalizeOptions+NuxtTocPublicRuntimeConfigwill often surface only incontentMajororscrollSpy/smoothe2e expectations. - Adding a prop without adding it to
docs/api/props.md+definePropsis caught byvue-tscand by the e2e for unknown-props behavior (vuewarnings inhappy-domstdio).
Release gate
See .github/workflows/ci.yml for the exact order: checkout → setup node 20 → npm ci → npm run dev:prepare → npm run lint / format:check / test matrix → npm run prepack -- --dry-run. Match it locally with npm run check && npm run prepack.
Also see: Development setup and Playgrounds.
