Skip to content

Commit a35ec53

Browse files
authored
👷(vitest) Move to Vitest (#5350)
**Description** <!-- Please provide a short description and potentially linked issues justifying the need for this PR --> Change our test runner to Vitest. Jest is great but it's partial support for ESM is putting us in troubles. As such we passed fast-check to Vitest a while ago and want to unify all others so that we preserve a unique test runner in our CI. <!-- * Your PR is fixing a bug or regression? Check for existing issues related to this bug and link them --> <!-- * Your PR is adding a new feature? Make sure there is a related issue or discussion attached to it --> <!-- You can provide any additional context to help into understanding what's this PR is attempting to solve: reproduction of a bug, code snippets... --> **Checklist** — _Don't delete this checklist and make sure you do the following before opening the PR_ - [x] The name of my PR follows [gitmoji](https://gitmoji.dev/) specification - [x] My PR references one of several related issues (if any) - [x] New features or breaking changes must come with an associated Issue or Discussion - [x] My PR does not add any new dependency without an associated Issue or Discussion - [x] My PR includes bumps details, please run `yarn bump` and flag the impacts properly - [x] My PR adds relevant tests and they would have failed without my PR (when applicable) <!-- More about contributing at https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md --> **Advanced** <!-- How to fill the advanced section is detailed below! --> - [x] Category: 👷 Build tools & CI - [x] Impacts: Test runner <!-- [Category] Please use one of the categories below, it will help us into better understanding the urgency of the PR --> <!-- * ✨ Introduce new features --> <!-- * 📝 Add or update documentation --> <!-- * ✅ Add or update tests --> <!-- * 🐛 Fix a bug --> <!-- * 🏷️ Add or update types --> <!-- * ⚡️ Improve performance --> <!-- * _Other(s):_ ... --> <!-- [Impacts] Please provide a comma separated list of the potential impacts that might be introduced by this change --> <!-- * Generated values: Can your change impact any of the existing generators in terms of generated values, if so which ones? when? --> <!-- * Shrink values: Can your change impact any of the existing generators in terms of shrink values, if so which ones? when? --> <!-- * Performance: Can it require some typings changes on user side? Please give more details --> <!-- * Typings: Is there a potential performance impact? In which cases? -->
1 parent fcd5e3b commit a35ec53

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

.changeset/seven-owls-hammer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fast-check/vitest": patch
3+
---
4+
5+
👷(vitest) Move to Vitest

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ packages/*/dist/
66
packages/*/lib/
77
packages/*/lib-*/
88
packages/fast-check/docs/
9+
packages/*/.test-artifacts/
910
*.tgz
1011
deopt.out
1112
v8.log

packages/vitest/package.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/cjs",
2929
"build:publish-cjs": "tsc -p tsconfig.publish.json --outDir lib/cjs && cp package.cjs-template.json lib/cjs/package.json",
3030
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node",
31-
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
31+
"test": "vitest",
3232
"test-bundle": "node test-bundle/basic.mjs && vitest --config test-bundle/vitest.config.mjs",
3333
"typecheck": "tsc --noEmit"
3434
},
@@ -50,14 +50,8 @@
5050
"vitest": ">=0.28.1 <1.0.0 || ^1 || ^2"
5151
},
5252
"devDependencies": {
53-
"@babel/core": "^7.25.8",
54-
"@babel/preset-typescript": "^7.25.7",
55-
"@jest/globals": "^29.7.0",
56-
"@types/jest": "^29.5.13",
5753
"@types/node": "^20.14.15",
58-
"babel-jest": "^29.7.0",
5954
"fast-check": "workspace:*",
60-
"jest": "^29.7.0",
6155
"typescript": "~5.6.3",
6256
"vite": "^5.4.9",
6357
"vitest": "^2.1.3"

packages/vitest/test/vitest-fast-check.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as url from 'url';
33
import { promises as fs } from 'fs';
44
import { promisify } from 'util';
55
import { execFile as _execFile } from 'child_process';
6-
import { jest } from '@jest/globals';
6+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
77

88
const execFile = promisify(_execFile);
99
// @ts-expect-error --module must be higher
@@ -14,13 +14,11 @@ import type { test as _test, it as _it } from '@fast-check/vitest';
1414
declare const fc: typeof _fc;
1515
declare const runner: typeof _test | typeof _it;
1616

17-
const generatedTestsDirectoryName = 'generated-tests';
18-
const generatedTestsDirectory = path.join(__dirname, generatedTestsDirectoryName);
17+
const generatedTestsDirectoryName = '.test-artifacts';
18+
const generatedTestsDirectory = path.join(__dirname, '..', generatedTestsDirectoryName);
1919

2020
type RunnerType = 'test' | 'it';
2121

22-
jest.setTimeout(60_000);
23-
2422
beforeAll(async () => {
2523
await fs.mkdir(generatedTestsDirectory, { recursive: true });
2624
});
@@ -220,7 +218,7 @@ async function writeToFile(
220218

221219
// Prepare jest config itself
222220
const vitestConfigName = `vitest.config-${specFileSeed}.mjs`;
223-
const vitestConfigRelativePath = `test/${generatedTestsDirectoryName}/${vitestConfigName}`;
221+
const vitestConfigRelativePath = `${generatedTestsDirectoryName}/${vitestConfigName}`;
224222
const vitestConfigPath = path.join(generatedTestsDirectory, vitestConfigName);
225223

226224
// Write the files
@@ -229,7 +227,7 @@ async function writeToFile(
229227
fs.writeFile(
230228
vitestConfigPath,
231229
`import { defineConfig } from 'vite';\n` +
232-
`export default defineConfig({ test: { include: ['test/${generatedTestsDirectoryName}/${specFileName}'], }, });`,
230+
`export default defineConfig({ test: { include: ['${generatedTestsDirectoryName}/${specFileName}'], }, });`,
233231
),
234232
]);
235233

packages/vitest/vitest.config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
testTimeout: 60000, // 60s
6+
include: ['**/test/*.{test,spec}.?(c|m)[jt]s?(x)'],
7+
},
8+
});

yarn.lock

-6
Original file line numberDiff line numberDiff line change
@@ -3107,14 +3107,8 @@ __metadata:
31073107
version: 0.0.0-use.local
31083108
resolution: "@fast-check/vitest@workspace:packages/vitest"
31093109
dependencies:
3110-
"@babel/core": "npm:^7.25.8"
3111-
"@babel/preset-typescript": "npm:^7.25.7"
3112-
"@jest/globals": "npm:^29.7.0"
3113-
"@types/jest": "npm:^29.5.13"
31143110
"@types/node": "npm:^20.14.15"
3115-
babel-jest: "npm:^29.7.0"
31163111
fast-check: "workspace:*"
3117-
jest: "npm:^29.7.0"
31183112
typescript: "npm:~5.6.3"
31193113
vite: "npm:^5.4.9"
31203114
vitest: "npm:^2.1.3"

0 commit comments

Comments
 (0)