Skip to content

✅ Migrate race condition tests to Vitest#6754

Merged
dubzzz merged 4 commits into
mainfrom
claude/migrate-jest-to-vitest-LWzXc
Mar 23, 2026
Merged

✅ Migrate race condition tests to Vitest#6754
dubzzz merged 4 commits into
mainfrom
claude/migrate-jest-to-vitest-LWzXc

Conversation

@dubzzz

@dubzzz dubzzz commented Mar 19, 2026

Copy link
Copy Markdown
Owner

Description

Migrates the race condition detection tutorial test suite from Jest to Vitest. This change updates the test infrastructure to use Vitest as the test runner, which provides better ESM support and improved performance for this use case.

Changes:

  • Replaced Jest with Vitest as the test runner for the race condition detection snippets
  • Updated test configuration from jest.config.cjs to vitest.config.mjs with appropriate Vitest settings
  • Modified test imports to use Vitest's API (vi, test, expect) instead of Jest's
  • Updated the test execution logic to call Vitest with appropriate CLI flags (--run, --no-color)
  • Added alias configuration in Vitest config to resolve fast-check to the local source
  • Removed unused cwd import from process
  • Consolidated stdout and stderr output handling for Vitest's output format

Checklist

  • I have a full understanding of every line in this PR
  • I flagged the impact of my change (minor / patch / major) either by running pnpm run bump or by following the instructions from the changeset bot
  • I kept this PR focused on a single concern and did not bundle unrelated changes
  • I followed the gitmoji specification for the name of the PR
  • Existing tests pass with the new Vitest configuration

https://claude.ai/code/session_01VJVn4FasB8hokBSQsUdnCk

Replace the Jest subprocess runner with Vitest for snippet validation tests.
The snippets themselves remain unchanged - only the test harness is updated:
- Use vitest binary instead of jest binary
- Prepend `import { vi as jest, test, expect } from 'vitest'` (aliasing vi as jest)
- Generate a vitest.config.mjs per test directory with fast-check source alias
- Combine stdout+stderr for output assertions
- Remove unused `cwd` import

https://claude.ai/code/session_01VJVn4FasB8hokBSQsUdnCk
@changeset-bot

changeset-bot Bot commented Mar 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a5408d4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Mar 19, 2026

Copy link
Copy Markdown
@fast-check/ava

npm i https://pkg.pr.new/@fast-check/ava@6754

fast-check

npm i https://pkg.pr.new/fast-check@6754

@fast-check/jest

npm i https://pkg.pr.new/@fast-check/jest@6754

@fast-check/packaged

npm i https://pkg.pr.new/@fast-check/packaged@6754

@fast-check/poisoning

npm i https://pkg.pr.new/@fast-check/poisoning@6754

@fast-check/vitest

npm i https://pkg.pr.new/@fast-check/vitest@6754

@fast-check/worker

npm i https://pkg.pr.new/@fast-check/worker@6754

commit: a5408d4

@dubzzz

dubzzz commented Mar 23, 2026

Copy link
Copy Markdown
Owner Author

@claude it fails with:

FAIL website docs/tutorials/detect-race-conditions/snippets.spec.mjs�[2m > Playground�[2m > snippet v5�[2m > should pass on extendedExceptions
AssertionError: expected '\n RUN v4.1.0 D:/a/fast-check/fast-c…' to contain '1 passed'

  • Expected
  • Received
  • 1 passed
  • RUN v4.1.0 D:/a/fast-check/fast-check/website/.test-artifacts/test-df22ff501d33
  • ❯ queue.spec.mjs (0 test)
  • Test Files 1 failed (1)
  •   Tests  no tests
    
  • Start at 22:29:08
  • Duration 319ms (transform 33ms, setup 0ms, import 0ms, tests 0ms, environment 0ms)
  • ::error file=D%3A/a/fast-check/fast-check/website/.test-artifacts/test-df22ff501d33/queue.spec.mjs,title=queue.spec.mjs,line=3,column=1::Error: Cannot find package 'fast-check' imported from D:/a/fast-check/fast-check/website/.test-artifacts/test-df22ff501d33/queue.spec.mjs%0A ❯ queue.spec.mjs:3:1%0A%0A⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯%0ASerialized Error: { code: 'ERR_MODULE_NOT_FOUND' }%0A
  • ⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯
  • FAIL queue.spec.mjs [ queue.spec.mjs ]
  • Error: Cannot find package 'fast-check' imported from D:/a/fast-check/fast-check/website/.test-artifacts/test-df22ff501d33/queue.spec.mjs
  • ❯ queue.spec.mjs:3:1
  •   1| import { vi as jest, test, expect } from 'vitest';
    
  •   2| import {queue} from './queue.mjs';
    
  •   3| import fc from "fast-check";
    
  •    | ^
    
  •   4|
    
  •   5| test("should resolve in call order", async () => {
    
  • ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

�[2m❯ docs/tutorials/detect-race-conditions/snippets.spec.mjs:�[2m89:34
87| const specOutput = await runVitest(testDirectoryPath);
88| if (expectedSuccess) {
89| expect(specOutput).toContain('1 passed');
| ^
90| expect(specOutput).not.toContain('1 failed');
91| expect(specOutput).not.toContain('ERR_UNHANDLED_REJECTIO…

�[2m⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[21/21]⎯

�[2m Test Files 1 failed�[2m | 81 passed (82)
�[2m Tests 21 failed�[2m | 975 passed (996)
�[2m Start at 22:28:15
�[2m Duration 53.44s�[2m (transform 4.19s, setup 4.64s, import 12.11s, tests 81.26s, environment 700ms)

Fix it

@claude

claude Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Claude finished @dubzzz's task in 1m 17s —— View job


Fixing Vitest migration for race condition detection tests

  • Read current test file and understand the issue
  • Fix the fast-check module resolution in spawned Vitest processes
  • Commit and push the fix

Root cause

On Windows CI, path.join produces backslashes (e.g. D:\a\fast-check\...). When this path was interpolated into the Vitest config using a template literal with single quotes:

`... alias: { 'fast-check': '${fastCheckSourcePath}' } ...`

The backslashes were interpreted as JS escape characters (e.g. \f → form feed, \a → bell), making the path invalid and causing Cannot find package 'fast-check'.

Fix

Replaced the single-quoted string interpolation with JSON.stringify(fastCheckSourcePath), which properly escapes backslashes in the path, producing valid JS on all platforms.

View commit ·

Use JSON.stringify to properly escape backslashes in the fast-check
source path when writing the Vitest config file. On Windows, path.join
produces backslashes which were interpreted as escape characters in the
JS string literal, causing 'Cannot find package fast-check' errors.

Co-authored-by: Nicolas DUBIEN <[email protected]>
await fs.writeFile(
vitestConfigPath,
`import { defineConfig } from 'vitest/config';\n` +
`export default defineConfig({ test: { include: ['queue.spec.mjs'] }, resolve: { alias: { 'fast-check': ${JSON.stringify(fastCheckSourcePath)} } } });`,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@claude why do we need the alias? Is there a way to drop the need for such alias

@claude claude Bot Mar 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude finished @dubzzz's task in 2m 16s —— View job


  • Analyze why the alias was added
  • Remove the alias and rely on standard Node module resolution
  • Commit and push

Answer

The alias isn't needed. It was pointing to the source .ts file at packages/fast-check/src/fast-check.ts, but that's unnecessary because standard Node module resolution already works here:

  1. The temp test files live under website/.test-artifacts/test-xxx/
  2. Node resolution walks up: .test-artifacts/website/ → finds node_modules/fast-check
  3. website/node_modules/fast-check is a pnpm workspace symlink to packages/fast-check/
  4. CI unpacks the production bundles before running tests, so lib/fast-check.js exists

This is exactly how the original Jest setup worked — no special resolution was needed there either.

I've removed the alias and the fastCheckSourcePath variable. The Vitest config now just sets test.include — same minimal config as the old jest.config.cjs.

View commit ·

…lution

The temp test directories are under website/.test-artifacts/, so Node module
resolution walks up to website/node_modules/fast-check (workspace symlink).
No alias needed — same as the original Jest approach.

Co-authored-by: Nicolas DUBIEN <[email protected]>
@dubzzz
dubzzz enabled auto-merge (squash) March 23, 2026 19:46
@dubzzz
dubzzz disabled auto-merge March 23, 2026 19:46
@dubzzz dubzzz changed the title 🔧 Migrate race condition detection tests from Jest to Vitest ✅ Migrate race condition tests to Vitest Mar 23, 2026
@dubzzz
dubzzz enabled auto-merge (squash) March 23, 2026 19:47
@dubzzz
dubzzz merged commit e75ce5f into main Mar 23, 2026
48 checks passed
@dubzzz
dubzzz deleted the claude/migrate-jest-to-vitest-LWzXc branch March 23, 2026 19:56
@codecov

codecov Bot commented Mar 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.51%. Comparing base (e952168) to head (a5408d4).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6754   +/-   ##
=======================================
  Coverage   94.51%   94.51%           
=======================================
  Files         210      210           
  Lines        5686     5686           
  Branches     1500     1500           
=======================================
  Hits         5374     5374           
  Misses        299      299           
  Partials       13       13           
Flag Coverage Δ
tests 94.51% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants