Skip to content

Added tsx loading for bree job workers under Vitest#28048

Closed
9larsons wants to merge 1 commit into
mainfrom
vitest-bree-worker-tsx
Closed

Added tsx loading for bree job workers under Vitest#28048
9larsons wants to merge 1 commit into
mainfrom
vitest-bree-worker-tsx

Conversation

@9larsons
Copy link
Copy Markdown
Contributor

Extends the tsx scoping from the unified watch-mode work (#28038) so bree job workers can load Ghost's .ts server source under Vitest.

Background

#28038 scoped tsx to ghost/core's Vitest workers via require('tsx/cjs') (instead of a global NODE_OPTIONS='--import tsx', which broke the app projects). That hook is registered only in the test's own thread — it doesn't reach the worker threads bree spawns for "offloaded" jobs, so a job worker requiring .ts server source fails with Cannot find module.

This surfaced in the Phase A spike for the Mocha retirement: test/integration/jobs/update-check.test.js failed because the update-check job runs in a bree worker.

The fix

A Worker inherits the process.execArgv snapshot taken at process startup — mutating the live array does not propagate to spawned workers. So the fix:

  1. Adds tsx's loader to process.execArgv.
  2. Patches worker_threads.Worker so every spawned worker is passed the live execArgv explicitly.

Both are scoped to ghost/core's Vitest setup file — no effect on the app projects.

Why now

No current test hits this — no unit test offloads a .ts-loading job. But the integration and e2e suites run jobs heavily, so this unblocks migrating them off Mocha.

Testing

  • test/integration/jobs/update-check.test.js (which spawns a bree job worker) now passes under Vitest.
  • Full ghost/core unit suite green — 550 files / 6573 tests — confirming the Worker patch causes no regression.

- the unified watch-mode change registers tsx in ghost/core's Vitest worker
  via require('tsx/cjs'); bree runs "offloaded" jobs in their own worker
  threads, which can't see that hook and so can't require()/import Ghost's
  .ts server source
- a new Worker inherits the process.execArgv snapshot taken at process
  startup — mutating the live array does not propagate — so the fix adds
  tsx's loader to execArgv and patches Worker to pass the live execArgv
  explicitly to every spawned worker
- no current test hits this (no unit test offloads a .ts-loading job), but
  the integration and e2e suites run jobs heavily; this unblocks migrating
  them off Mocha
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98ed22f4-dc07-4ec9-b743-4b125a8bb714

📥 Commits

Reviewing files that changed from the base of the PR and between 263ee04 and 74e29bb.

📒 Files selected for processing (1)
  • ghost/core/test/utils/vitest-setup.ts

Walkthrough

This PR adds Vitest setup code to ensure TypeScript sources can be loaded within worker threads. The change conditionally appends the tsx CommonJS loader to process.execArgv and monkey-patches the worker_threads.Worker constructor so spawned workers inherit the updated loader configuration. This prevents workers from failing when requiring Ghost's .ts files during test execution.

Possibly related PRs

  • TryGhost/Ghost#27898: Modifies the same Vitest setup file to adjust test initialization.
  • TryGhost/Ghost#28038: Also fixes tsx/cjs loader hook application for Vitest runs including worker-thread execution.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding tsx loading support for bree job workers in Vitest, which is the core focus of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the background, the fix implementation, and testing results for the tsx loader issue in bree workers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 vitest-bree-worker-tsx

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.

@9larsons 9larsons closed this May 28, 2026
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