Skip to content

Commit 36b418b

Browse files
authored
👷(poisoning) Move to Vitest (#5353)
**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 83874bd commit 36b418b

12 files changed

+48
-58
lines changed

.changeset/green-owls-tap.md

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

packages/poisoning/babel.config.cjs

-3
This file was deleted.

packages/poisoning/jest.config.js

-4
This file was deleted.

packages/poisoning/package.json

+3-9
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
"typecheck": "tsc --noEmit"
3333
},
3434
"repository": {
@@ -43,15 +43,9 @@
4343
},
4444
"homepage": "https://github.com/dubzzz/fast-check/tree/main/packages/poisoning#readme",
4545
"devDependencies": {
46-
"@babel/core": "^7.25.8",
47-
"@babel/preset-typescript": "^7.25.7",
48-
"@jest/globals": "^29.7.0",
49-
"@types/jest": "^29.5.13",
5046
"@types/node": "^20.14.15",
51-
"babel-jest": "^29.7.0",
52-
"jest": "^29.7.0",
53-
"jest-ts-webcompat-resolver": "^1.0.0",
54-
"typescript": "~5.6.3"
47+
"typescript": "~5.6.3",
48+
"vitest": "^2.1.3"
5549
},
5650
"keywords": [
5751
"poisoning",

packages/poisoning/test/internals/CaptureAllGlobals.spec.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { captureAllGlobals } from '../../src/internals/CaptureAllGlobals.js';
23
import type { PoisoningFreeMap } from '../../src/internals/PoisoningFreeMap.js';
34
import { PoisoningFreeSet } from '../../src/internals/PoisoningFreeSet.js';
@@ -133,7 +134,12 @@ describe('captureAllGlobals', () => {
133134
const globals = captureAllGlobals();
134135

135136
// Assert
136-
expect(globals.get(globalValue)?.rootAncestors).toEqual(expectedRoots);
137+
const rootAncestorsWithoutVitest = new Set(
138+
// We are ignoring any root ancestor related to Vitest as they are likely to evolve over time.
139+
// As such we stick to non test framework related ones.
140+
[...(globals.get(globalValue)?.rootAncestors ?? new Set())].filter((name) => !/__vitest_\w+__/.test(name)),
141+
);
142+
expect(rootAncestorsWithoutVitest).toEqual(expectedRoots);
137143
},
138144
);
139145

packages/poisoning/test/internals/FilterNonEligibleDiffs.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import type { GlobalDetails } from '../../src/internals/types/AllGlobals';
23
import { shouldIgnoreGlobal, shouldIgnoreProperty } from '../../src/internals/FilterNonEligibleDiffs';
34
import { PoisoningFreeSet } from '../../src/internals/PoisoningFreeSet';

packages/poisoning/test/internals/PoisoningFreeArray.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { MapSymbol, PushSymbol, SortSymbol, PoisoningFreeArray } from '../../src/internals/PoisoningFreeArray.js';
23

34
describe('PoisoningFreeArray', () => {

packages/poisoning/test/internals/PoisoningFreeMap.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import {
23
EntriesSymbol,
34
GetSymbol,

packages/poisoning/test/internals/PoisoningFreeSet.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { AddSymbol, HasSymbol, PoisoningFreeSet } from '../../src/internals/PoisoningFreeSet.js';
23

34
describe('PoisoningFreeSet', () => {

packages/poisoning/test/internals/TrackDiffsOnGlobal.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { PoisoningFreeMap } from '../../src/internals/PoisoningFreeMap.js';
23
import { PoisoningFreeSet } from '../../src/internals/PoisoningFreeSet.js';
34
import { trackDiffsOnGlobals } from '../../src/internals/TrackDiffsOnGlobal.js';

packages/poisoning/test/main.spec.ts

+27-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { jest } from '@jest/globals';
1+
import { describe, it, expect, vi } from 'vitest';
22
import { assertNoPoisoning, restoreGlobals } from '../src/main.js';
33

4+
const options = { ignoredRootRegex: /__vitest_worker__/ };
5+
46
describe('assertNoPoisoning', () => {
57
it('should not throw any Error if no poisoning occurred', () => {
68
// Arrange / Act / Assert
7-
expect(() => assertNoPoisoning()).not.toThrow();
8-
restoreGlobals();
9-
expect(() => assertNoPoisoning()).not.toThrow();
9+
expect(() => assertNoPoisoning(options)).not.toThrow();
10+
restoreGlobals(options);
11+
expect(() => assertNoPoisoning(options)).not.toThrow();
1012
});
1113

1214
it('should throw an Error if new global appeared and be able to revert the change', () => {
@@ -17,9 +19,9 @@ describe('assertNoPoisoning', () => {
1719

1820
// Act / Assert
1921
try {
20-
expect(() => assertNoPoisoning()).toThrowError(/Poisoning detected/);
21-
restoreGlobals();
22-
expect(() => assertNoPoisoning()).not.toThrow();
22+
expect(() => assertNoPoisoning(options)).toThrowError(/Poisoning detected/);
23+
restoreGlobals(options);
24+
expect(() => assertNoPoisoning(options)).not.toThrow();
2325
} finally {
2426
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2527
// @ts-ignore
@@ -36,9 +38,9 @@ describe('assertNoPoisoning', () => {
3638

3739
// Act / Assert
3840
try {
39-
expect(() => assertNoPoisoning()).toThrowError(/Poisoning detected/);
40-
restoreGlobals();
41-
expect(() => assertNoPoisoning()).not.toThrow();
41+
expect(() => assertNoPoisoning(options)).toThrowError(/Poisoning detected/);
42+
restoreGlobals(options);
43+
expect(() => assertNoPoisoning(options)).not.toThrow();
4244
} finally {
4345
globalThis.Function = F;
4446
}
@@ -47,13 +49,13 @@ describe('assertNoPoisoning', () => {
4749
it('should throw an Error if global altered via globalThis and be able to revert the change', () => {
4850
// Arrange
4951
const F = globalThis.Function;
50-
globalThis.Function = jest.fn() as any;
52+
globalThis.Function = vi.fn() as any;
5153

5254
// Act / Assert
5355
try {
54-
expect(() => assertNoPoisoning()).toThrowError(/Poisoning detected/);
55-
restoreGlobals();
56-
expect(() => assertNoPoisoning()).not.toThrow();
56+
expect(() => assertNoPoisoning(options)).toThrowError(/Poisoning detected/);
57+
restoreGlobals(options);
58+
expect(() => assertNoPoisoning(options)).not.toThrow();
5759
} finally {
5860
globalThis.Function = F;
5961
}
@@ -63,13 +65,13 @@ describe('assertNoPoisoning', () => {
6365
// Arrange
6466
const F = Function;
6567
// eslint-disable-next-line no-global-assign
66-
Function = jest.fn() as any;
68+
Function = vi.fn() as any;
6769

6870
// Act / Assert
6971
try {
70-
expect(() => assertNoPoisoning()).toThrowError(/Poisoning detected/);
71-
restoreGlobals();
72-
expect(() => assertNoPoisoning()).not.toThrow();
72+
expect(() => assertNoPoisoning(options)).toThrowError(/Poisoning detected/);
73+
restoreGlobals(options);
74+
expect(() => assertNoPoisoning(options)).not.toThrow();
7375
} finally {
7476
// eslint-disable-next-line no-global-assign
7577
Function = F;
@@ -85,7 +87,7 @@ describe('assertNoPoisoning', () => {
8587
// Act / Assert
8688
let error: unknown = undefined;
8789
try {
88-
assertNoPoisoning();
90+
assertNoPoisoning(options);
8991
} catch (err) {
9092
error = err;
9193
}
@@ -100,8 +102,8 @@ describe('assertNoPoisoning', () => {
100102
throw new Error(`Received error does not fulfill expectations, got: ${error}`);
101103
}
102104
try {
103-
restoreGlobals();
104-
expect(() => assertNoPoisoning()).not.toThrow();
105+
restoreGlobals(options);
106+
expect(() => assertNoPoisoning(options)).not.toThrow();
105107
} finally {
106108
// eslint-disable-next-line no-global-assign
107109
(globalThis as any) = G;
@@ -141,11 +143,11 @@ describe('assertNoPoisoning', () => {
141143
dropAll('Error', Error);
142144

143145
// Act / Assert
144-
// Manual expectation mimicing "expect(() => assertNoPoisoning()).toThrowError(/Poisoning detected/)"
146+
// Manual expectation mimicing "expect(() => assertNoPoisoning(options)).toThrowError(/Poisoning detected/)"
145147
// as Jest makes use of Object.keys and probably others in its code
146148
let caughtError: unknown = undefined;
147149
try {
148-
assertNoPoisoning();
150+
assertNoPoisoning(options);
149151
} catch (err) {
150152
caughtError = err;
151153
}
@@ -155,8 +157,8 @@ describe('assertNoPoisoning', () => {
155157
if (!(caughtError instanceof Error)) {
156158
throw new Error('Expected an error of type Error to be thrown during the test');
157159
}
158-
restoreGlobals();
159-
expect(() => assertNoPoisoning()).not.toThrow();
160+
restoreGlobals(options);
161+
expect(() => assertNoPoisoning(options)).not.toThrow();
160162
// WARNING: If restoreGlobals failed, then this test may break others
161163
});
162164
});

yarn.lock

+1-16
Original file line numberDiff line numberDiff line change
@@ -3091,15 +3091,9 @@ __metadata:
30913091
version: 0.0.0-use.local
30923092
resolution: "@fast-check/poisoning@workspace:packages/poisoning"
30933093
dependencies:
3094-
"@babel/core": "npm:^7.25.8"
3095-
"@babel/preset-typescript": "npm:^7.25.7"
3096-
"@jest/globals": "npm:^29.7.0"
3097-
"@types/jest": "npm:^29.5.13"
30983094
"@types/node": "npm:^20.14.15"
3099-
babel-jest: "npm:^29.7.0"
3100-
jest: "npm:^29.7.0"
3101-
jest-ts-webcompat-resolver: "npm:^1.0.0"
31023095
typescript: "npm:~5.6.3"
3096+
vitest: "npm:^2.1.3"
31033097
languageName: unknown
31043098
linkType: soft
31053099

@@ -12786,15 +12780,6 @@ __metadata:
1278612780
languageName: node
1278712781
linkType: hard
1278812782

12789-
"jest-ts-webcompat-resolver@npm:^1.0.0":
12790-
version: 1.0.0
12791-
resolution: "jest-ts-webcompat-resolver@npm:1.0.0"
12792-
peerDependencies:
12793-
jest-resolve: "*"
12794-
checksum: 10c0/0567766de8fc25a9b87fedfdafc3bee093ff09020b1f564fbf8eb5e324c77afee4f43c3bbfe36e09a08526bd5daed4697098192a9815fea09a263a473b9627b4
12795-
languageName: node
12796-
linkType: hard
12797-
1279812783
"jest-util@npm:^29.7.0":
1279912784
version: 29.7.0
1280012785
resolution: "jest-util@npm:29.7.0"

0 commit comments

Comments
 (0)