Skip to content

Enabled isolate: false for the ghost/core unit suite#28074

Merged
9larsons merged 1 commit into
mainfrom
perf/unit-tests-isolate-false
May 22, 2026
Merged

Enabled isolate: false for the ghost/core unit suite#28074
9larsons merged 1 commit into
mainfrom
perf/unit-tests-isolate-false

Conversation

@9larsons
Copy link
Copy Markdown
Contributor

The ghost/core unit suite ran under vitest's default isolate: true — a fresh module registry per test file, cold-importing Ghost's heavy server modules ~550 times per run. It now runs under isolate: false (one shared registry per worker, the model mocha always used): ~73s → ~7s locally.

How

vitest.config.ts is split into two projects:

  • unit — the 546-file bulk, isolate: false.
  • unit-isolated — 4 files that still fail intermittently under a shared registry, kept on isolate: true until their root causes are fixed: create-migration, scheduling-default, public-config/config, taxonomy-router. The quarantine list is short on purpose — each entry is a known bug to fix, not a permanent home.

Supporting changes for the shared registry:

  • vitest-setup.ts's afterAll no longer destroys the knex pool per file — under one shared pool per worker that would break every file scheduled after it. It now drains in-flight queries and leaves the pool for the worker to tear down.
  • vitest-global-setup.ts removes the per-worker session sqlite files once per run (previously done per-file).
  • cache-invalidation.test.js is un-skipped — it was skipped specifically pending this change; warm requires keep it well under the timeout.
  • Three snapshot files pick up vitest's current header line (JestVitest); isolate: false rewrites them on load, content unchanged.

Verification

The isolate: false bulk project was stress-run 82 times locally (full suite, ~546 files) — 81 clean, 1 lone unrelated flake, well within the existing vitest retry: 2 + CI step-retry. Full suite (both projects) green at 550/550.

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Review Change Stack

Walkthrough

This PR restructures Ghost core's Vitest unit test execution into two separate projects: unit (shared module state, isolate: false) and unit-isolated (isolated, isolate: true). An isolatedFiles allowlist routes quarantined tests to the isolated runner. The setup logic now generates a per-worker sessionId and removes conditional sqlite/mysql cleanup flags. The afterAll hook now best-effort waits up to 5 seconds for the shared knex pool to drain instead of destroying it. A new global teardown removes leftover SQLite test database files from /tmp. The previously skipped cache-invalidation header assertion test is enabled.

Possibly related PRs

  • TryGhost/Ghost#28030: Modifies Vitest unit-test wiring and configuration for ghost/core, related to the project/isolation refactor.
  • TryGhost/Ghost#28012: Changes to knex teardown/cleanup in vitest-setup.ts, closely related to the afterAll cleanup adjustments.
  • TryGhost/Ghost#28049: Previously skipped the same cache-invalidation test that this PR re-enables.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Enabled isolate: false for the ghost/core unit suite' directly and clearly describes the main performance optimization change—switching the unit test suite from isolate: true to isolate: false.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the rationale (73s → 7s performance improvement), implementation approach (two-project split), supporting changes, and verification results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/unit-tests-isolate-false

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

The unit suite ran under vitest's default `isolate: true`, giving every
test file a fresh module registry and cold-importing Ghost's heavy server
modules ~550 times per run (~73s). It now runs under `isolate: false` —
one shared registry per worker, the model mocha always used — which takes
the suite to ~7s locally.

- vitest.config.ts is split into two projects: `unit` (the bulk,
  isolate: false) and `unit-isolated` (6 files that still fail
  intermittently under a shared registry, kept on isolate: true until
  their root causes are fixed)
- vitest-setup.ts's afterAll no longer destroys the knex pool per file —
  under a shared registry that breaks the pool for files scheduled after
  it; it drains in-flight queries instead. vitest-global-setup.ts removes
  the per-worker session sqlite files once per run
- resolveSnapshotPath is set at the config root so vitest's native
  snapshot system stays away from the @tryghost/jest-snapshot `.snap`
  files — otherwise it adopts them and reports their entries as obsolete,
  which fails the run under CI
- restores cache-invalidation.test.js, skipped pending this change (warm
  requires keep it well under the timeout)
@9larsons 9larsons force-pushed the perf/unit-tests-isolate-false branch from 47e19e2 to 1fef525 Compare May 22, 2026 20:38
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 33e9a606-cd73-4301-8476-7103ce1aed9b

📥 Commits

Reviewing files that changed from the base of the PR and between 47e19e2 and 1fef525.

📒 Files selected for processing (4)
  • ghost/core/test/unit/api/cache-invalidation.test.js
  • ghost/core/test/utils/vitest-global-setup.ts
  • ghost/core/test/utils/vitest-setup.ts
  • ghost/core/vitest.config.ts

Comment thread ghost/core/test/utils/vitest-global-setup.ts
@9larsons 9larsons enabled auto-merge (squash) May 22, 2026 20:48
@9larsons 9larsons merged commit b2486ef into main May 22, 2026
28 checks passed
@9larsons 9larsons deleted the perf/unit-tests-isolate-false branch May 22, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant