Skip to content

refactor: migrate test runner from bun:test to vitest (WIP)#992

Closed
BYK wants to merge 2 commits into
mainfrom
refactor/vitest-migration
Closed

refactor: migrate test runner from bun:test to vitest (WIP)#992
BYK wants to merge 2 commits into
mainfrom
refactor/vitest-migration

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented May 20, 2026

Summary

Phase 3 of the Bun to Node.js migration. Migrates 327 test files from bun:test to vitest.

Results

  • 306/307 test files pass (1 skipped: Bun-specific concurrent DB test)
  • 6994/7014 tests pass (20 skipped: Bun-specific behavior tests)
  • 0 failures

Changes

Infrastructure:

  • Added vitest as devDependency
  • Created vitest.config.ts with setupFiles, forks pool, custom Vite plugins
  • Custom matchers: toStartWith, toEndWith, toBeString, toBeArray
  • Vite plugins: text import (with { type: "text" }), require .js-to-.ts, resolve .js-to-.ts
  • Updated package.json test scripts to use vitest
  • Removed bun:sqlite fallback from sqlite.ts

Test file migration (327 files):

  • from "bun:test" to from "vitest"
  • mock to vi, spyOn to vi.spyOn, mock.module to vi.mock
  • vi.hoisted() for 12 files with mock factory hoisting
  • vi.mock() with importOriginal for 46 files with namespace spy patterns
  • Converted barrel re-export spies to internal module mocks for ESM compatibility

Bun API replacements in tests (40+ files):

  • Bun.spawn/spawnSync to node:child_process
  • Bun.file/write/sleep/gzip to Node.js equivalents
  • Bun.serve mock server to node:http createServer
  • import.meta.dir to import.meta.dirname
  • BUN_TEST_WORKER_ID to VITEST_POOL_ID

Source changes (minimal):

  • src/lib/list-command.ts: try-catch around require("../app.js") for vitest compat
  • src/lib/telemetry.ts: top-level import replacing lazy require

Comment thread src/lib/db/sqlite.ts Outdated
@BYK BYK force-pushed the refactor/vitest-migration branch 9 times, most recently from 19967c5 to 7c4061c Compare May 21, 2026 03:06
@BYK BYK marked this pull request as ready for review May 21, 2026 03:06
Comment thread src/lib/list-command.ts
Comment thread src/lib/db/sqlite.ts
@BYK BYK force-pushed the refactor/vitest-migration branch from 9a05ef5 to ae3fcb6 Compare May 21, 2026 12:39
Comment thread test/commands/dashboard/list.test.ts
@BYK BYK force-pushed the refactor/vitest-migration branch 2 times, most recently from 2410f84 to f276ba6 Compare May 21, 2026 13:04
@BYK BYK enabled auto-merge (squash) May 21, 2026 13:04
@BYK BYK force-pushed the refactor/vitest-migration branch from f276ba6 to e136ce6 Compare May 21, 2026 13:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-992/

Built to branch gh-pages at 2026-05-21 13:35 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@BYK BYK force-pushed the refactor/vitest-migration branch from e136ce6 to 3d5fbd6 Compare May 21, 2026 13:19
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3d5fbd6. Configure here.

Comment thread src/lib/db/sqlite.ts
@BYK BYK force-pushed the refactor/vitest-migration branch from 3d5fbd6 to 56cc841 Compare May 21, 2026 13:26
@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 82.36%. Project has 4055 uncovered lines.
✅ Project coverage is 82.36%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    76.61%    82.36%    +5.75%
==========================================
  Files          324       324         —
  Lines        63171     22986    -40185
  Branches         0     14880    +14880
==========================================
+ Hits         48396     18931    -29465
- Misses       14775      4055    -10720
- Partials         0      1608     +1608

Generated by Codecov Action

@BYK BYK force-pushed the refactor/vitest-migration branch from 56cc841 to 0a35368 Compare May 21, 2026 13:34
Phase 3 of Bun → Node.js migration. Migrates 327 test files from
bun:test to vitest.

Mechanical changes:
- bun:test imports → vitest imports (327 files)
- mock → vi, spyOn → vi.spyOn, mock.module → vi.mock (52 files)
- Bun.spawn/spawnSync → node:child_process in test files (12 files)
- Bun.file/write/sleep/gzip/etc → Node.js equivalents in tests (40 files)
- Bun.serve → node:http createServer in test mock server
- import.meta.dir → import.meta.dirname (16 files)
- BUN_TEST_WORKER_ID → VITEST_POOL_ID
- Added vitest.config.ts with setupFiles, pool: forks, 15s timeout
- Added custom toStartWith/toEndWith matchers in preload.ts
- Removed bun:sqlite fallback from sqlite.ts
- Updated package.json test scripts to use vitest

Known remaining issues (WIP):
- ESM spy limitations (Cannot spy on ESM namespace exports)
- Some vi import gaps in edge cases
- Test API signature changes (vitest 4)
- self is not defined in model-based tests
@BYK BYK force-pushed the refactor/vitest-migration branch from 0a35368 to 6dc85ed Compare May 21, 2026 13:43
@BYK
Copy link
Copy Markdown
Member Author

BYK commented May 21, 2026

Recreating PR with a fresh branch to trigger CI (GitHub stopped triggering ci.yml on the old branch after many force pushes).

@BYK BYK closed this May 21, 2026
auto-merge was automatically disabled May 21, 2026 13:53

Pull request was closed

BYK added a commit that referenced this pull request May 21, 2026
Phase 3 of the Bun to Node.js migration. Migrates 327 test files from
bun:test to vitest. 306/307 test files pass, 6994/7014 tests pass, 0
failures. See closed PR #992 for full description.
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