Skip to content

Commit

Permalink
👷(vitest) Move to Vitest (#5350)
Browse files Browse the repository at this point in the history
**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?
-->
  • Loading branch information
dubzzz authored Oct 21, 2024
1 parent fcd5e3b commit a35ec53
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-owls-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fast-check/vitest": patch
---

👷(vitest) Move to Vitest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ packages/*/dist/
packages/*/lib/
packages/*/lib-*/
packages/fast-check/docs/
packages/*/.test-artifacts/
*.tgz
deopt.out
v8.log
Expand Down
8 changes: 1 addition & 7 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/cjs",
"build:publish-cjs": "tsc -p tsconfig.publish.json --outDir lib/cjs && cp package.cjs-template.json lib/cjs/package.json",
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node",
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
"test": "vitest",
"test-bundle": "node test-bundle/basic.mjs && vitest --config test-bundle/vitest.config.mjs",
"typecheck": "tsc --noEmit"
},
Expand All @@ -50,14 +50,8 @@
"vitest": ">=0.28.1 <1.0.0 || ^1 || ^2"
},
"devDependencies": {
"@babel/core": "^7.25.8",
"@babel/preset-typescript": "^7.25.7",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.13",
"@types/node": "^20.14.15",
"babel-jest": "^29.7.0",
"fast-check": "workspace:*",
"jest": "^29.7.0",
"typescript": "~5.6.3",
"vite": "^5.4.9",
"vitest": "^2.1.3"
Expand Down
12 changes: 5 additions & 7 deletions packages/vitest/test/vitest-fast-check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as url from 'url';
import { promises as fs } from 'fs';
import { promisify } from 'util';
import { execFile as _execFile } from 'child_process';
import { jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

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

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

type RunnerType = 'test' | 'it';

jest.setTimeout(60_000);

beforeAll(async () => {
await fs.mkdir(generatedTestsDirectory, { recursive: true });
});
Expand Down Expand Up @@ -220,7 +218,7 @@ async function writeToFile(

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

// Write the files
Expand All @@ -229,7 +227,7 @@ async function writeToFile(
fs.writeFile(
vitestConfigPath,
`import { defineConfig } from 'vite';\n` +
`export default defineConfig({ test: { include: ['test/${generatedTestsDirectoryName}/${specFileName}'], }, });`,
`export default defineConfig({ test: { include: ['${generatedTestsDirectoryName}/${specFileName}'], }, });`,
),
]);

Expand Down
8 changes: 8 additions & 0 deletions packages/vitest/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
testTimeout: 60000, // 60s
include: ['**/test/*.{test,spec}.?(c|m)[jt]s?(x)'],
},
});
6 changes: 0 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3107,14 +3107,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@fast-check/vitest@workspace:packages/vitest"
dependencies:
"@babel/core": "npm:^7.25.8"
"@babel/preset-typescript": "npm:^7.25.7"
"@jest/globals": "npm:^29.7.0"
"@types/jest": "npm:^29.5.13"
"@types/node": "npm:^20.14.15"
babel-jest: "npm:^29.7.0"
fast-check: "workspace:*"
jest: "npm:^29.7.0"
typescript: "npm:~5.6.3"
vite: "npm:^5.4.9"
vitest: "npm:^2.1.3"
Expand Down

0 comments on commit a35ec53

Please sign in to comment.