Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ Update vitest monorepo to v2 (major) #5108

Merged
merged 13 commits into from
Jul 12, 2024
5 changes: 5 additions & 0 deletions .yarn/versions/942403b3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releases:
"@fast-check/vitest": patch

declined:
- fast-check
4 changes: 2 additions & 2 deletions packages/fast-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@
"@fast-check/poisoning": "workspace:*",
"@microsoft/api-extractor": "^7.47.0",
"@types/node": "^20.14.10",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/coverage-v8": "^2.0.1",
"cross-env": "^7.0.3",
"glob": "^11.0.0",
"not-node-buffer": "npm:buffer@^6.0.3",
"regexp-tree": "^0.1.27",
"replace-in-file": "^8.1.0",
"typedoc": "^0.26.3",
"typescript": "~5.5.3",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"keywords": [
"property-based testing",
Expand Down
5 changes: 3 additions & 2 deletions packages/fast-check/test/unit/__test-helpers__/Mocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ type MockableFunction = (...args: any[]) => any;
type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never;
type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never;

export interface MockWithArgs<T extends MockableFunction> extends MockInstance<ArgumentsOf<T>, ReturnType<T>> {
export interface MockWithArgs<T extends MockableFunction>
extends MockInstance<(...args: ArgumentsOf<T>) => ReturnType<T>> {
new (...args: ConstructorArgumentsOf<T>): T;
(...args: ArgumentsOf<T>): ReturnType<T>;
}
Expand All @@ -17,7 +18,7 @@ type PropertyKeysOf<T> = {
[K in keyof T]: T[K] extends MockableFunction ? never : K;
}[keyof T];
type MaybeMockedConstructor<T> = T extends new (...args: any[]) => infer R
? MockInstance<ConstructorArgumentsOf<T>, R>
? MockInstance<(...args: ConstructorArgumentsOf<T>) => R>
: T;
type MockedFunction<T extends MockableFunction> = MockWithArgs<T> & {
[K in keyof T]: T[K];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('AdapterArbitrary', () => {
generate.mockReturnValueOnce(value);
const { instance: mrng } = fakeRandom();
const adapterFunction = vi
.fn<[any], AdapterOutput<any>>()
.fn<(arg0: any) => AdapterOutput<any>>()
.mockImplementation((v) => ({ adapted: false, value: v }));

// Act
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('AdapterArbitrary', () => {
generate.mockReturnValueOnce(value);
const { instance: mrng } = fakeRandom();
const adapterFunction = vi
.fn<[any], AdapterOutput<any>>()
.fn<(arg0: any) => AdapterOutput<any>>()
.mockImplementation(() => ({ adapted: true, value: vAdapted }));

// Act
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('AdapterArbitrary', () => {
const { instance, canShrinkWithoutContext } = fakeArbitrary();
canShrinkWithoutContext.mockReturnValueOnce(canShrink);
const adapterFunction = vi
.fn<[any], AdapterOutput<any>>()
.fn<(arg0: any) => AdapterOutput<any>>()
.mockImplementation(() => ({ adapted: hasToAdapt, value: vA }));

// Act
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('AdapterArbitrary', () => {
canShrinkWithoutContext.mockReturnValue(canShrinkIfAdapted);
const { instance: mrng } = fakeRandom();
const adapterFunction = vi
.fn<[any], AdapterOutput<any>>()
.fn<(arg0: any) => AdapterOutput<any>>()
.mockImplementation((v) => (Object.is(v, vA) ? adaptedA : Object.is(v, vAA) ? adaptedAA : adaptedAB));

// Act
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('AdapterArbitrary', () => {
canShrinkWithoutContext.mockReturnValueOnce(canShrinkIfAdapted);
const { instance: mrng } = fakeRandom();
const adapterFunction = vi
.fn<[any], AdapterOutput<any>>()
.fn<(arg0: any) => AdapterOutput<any>>()
.mockImplementation((v) =>
Object.is(v, vA)
? adaptedA
Expand Down Expand Up @@ -287,7 +287,7 @@ describe('AdapterArbitrary', () => {
const { instance, generate, shrink, canShrinkWithoutContext } = fakeArbitrary();
shrink.mockReturnValueOnce(Stream.of(valueAA, valueAB));
const adapterFunction = vi
.fn<[any], AdapterOutput<any>>()
.fn<(arg0: any) => AdapterOutput<any>>()
.mockImplementation((v) => (Object.is(v, vAA) ? adaptedAA : adaptedAB));

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ describe('ArrayArbitrary', () => {
const minLength = Math.min(Math.max(0, value.length - offsetMin), maxGeneratedLength);
const maxLength = Math.max(Math.min(MaxLengthUpperBound, value.length + offsetMax), maxGeneratedLength);
const { instance, canShrinkWithoutContext } = fakeArbitrary();
canShrinkWithoutContext.mockImplementation((vTest) => value.find((v) => Object.is(v[0], vTest))![1]);
canShrinkWithoutContext.mockImplementation(
(vTest): vTest is any => value.find((v) => Object.is(v[0], vTest))![1],
);
const data: any[] = [];
const customSet: CustomSet<Value<any>> = {
size: () => data.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ describe('IntegerArbitrary', () => {
}
nextInt.mockReturnValueOnce(mid); // Remark: this value will most of the time be outside of requested range
const biasNumericRange = vi.spyOn(BiasNumericRangeMock, 'biasNumericRange') as unknown as MockInstance<
[min: number, max: number, logLike: (n: number) => number],
{ min: number; max: number }[]
(min: number, max: number, logLike: (n: number) => number) => { min: number; max: number }[]
>;
biasNumericRange.mockReturnValueOnce(ranges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('patternsToStringUnmapperFor', () => {
// Arrange
const sourceChunksSet = new Set(sourceChunks);
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation((value) => sourceChunksSet.has(value as string));
canShrinkWithoutContext.mockImplementation((value): value is string => sourceChunksSet.has(value as string));

// Act
const unmapper = patternsToStringUnmapperFor(instance, constraints);
Expand All @@ -52,7 +52,7 @@ describe('patternsToStringUnmapperFor', () => {
// Arrange
const sourceChunksSet = new Set(sourceChunks);
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation((value) => sourceChunksSet.has(value as string));
canShrinkWithoutContext.mockImplementation((value): value is string => sourceChunksSet.has(value as string));

// Act / Assert
const unmapper = patternsToStringUnmapperFor(instance, constraints);
Expand All @@ -70,7 +70,7 @@ describe('patternsToStringUnmapperFor', () => {
// Arrange
const sourceChunksSet = new Set(sourceChunks);
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation((value) => sourceChunksSet.has(value as string));
canShrinkWithoutContext.mockImplementation((value): value is string => sourceChunksSet.has(value as string));
const source = sourceMods.map((mod) => sourceChunks[mod % sourceChunks.length]).join('');

// Act
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('patternsToStringUnmapperFor', () => {
// Arrange
const sourceChunksSet = new Set(sourceChunks);
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation((value) => sourceChunksSet.has(value as string));
canShrinkWithoutContext.mockImplementation((value): value is string => sourceChunksSet.has(value as string));
const source = sourceMods.map((mod) => sourceChunks[mod % sourceChunks.length]).join('');
const constraints = {
minLength: Math.max(0, sourceMods.length - constraintsMinOffset),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('wordsToJoinedStringUnmapperFor', () => {
// Arrange
const { instance: wordsArbitrary, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello', 'world', 'winter', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello', 'world', 'winter', 'summer'].includes(value),
);

// Act
Expand All @@ -57,7 +57,7 @@ describe('wordsToJoinedStringUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello,', 'world,', 'winter', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello,', 'world,', 'winter', 'summer'].includes(value),
);

// Act
Expand All @@ -72,7 +72,7 @@ describe('wordsToJoinedStringUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello,', 'world,', 'spring', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello,', 'world,', 'spring', 'summer'].includes(value),
);

// Act / Assert
Expand All @@ -85,7 +85,9 @@ describe('wordsToJoinedStringUnmapperFor', () => {
fc.property(wordsArrayArbitrary, (words) => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation((value) => typeof value === 'string' && words.includes(value));
canShrinkWithoutContext.mockImplementation(
(value): value is string => typeof value === 'string' && words.includes(value),
);

// Act
const mapped = wordsToJoinedStringMapper(words);
Expand Down Expand Up @@ -120,7 +122,7 @@ describe('wordsToSentenceUnmapperFor', () => {
// Arrange
const { instance: wordsArbitrary, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello', 'world', 'winter', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello', 'world', 'winter', 'summer'].includes(value),
);

// Act
Expand All @@ -135,7 +137,7 @@ describe('wordsToSentenceUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello,', 'world,', 'winter', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello,', 'world,', 'winter', 'summer'].includes(value),
);

// Act
Expand All @@ -150,7 +152,7 @@ describe('wordsToSentenceUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello', 'world,', 'spring', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello', 'world,', 'spring', 'summer'].includes(value),
);

// Act / Assert
Expand All @@ -163,7 +165,7 @@ describe('wordsToSentenceUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello', 'world,', 'winter', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello', 'world,', 'winter', 'summer'].includes(value),
);

// Act / Assert
Expand All @@ -176,7 +178,7 @@ describe('wordsToSentenceUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello', 'world,', 'winter', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello', 'world,', 'winter', 'summer'].includes(value),
);

// Act / Assert
Expand All @@ -189,7 +191,7 @@ describe('wordsToSentenceUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello', 'world,', 'winter', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello', 'world,', 'winter', 'summer'].includes(value),
);

// Act / Assert
Expand All @@ -202,7 +204,7 @@ describe('wordsToSentenceUnmapperFor', () => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation(
(value) => typeof value === 'string' && ['hello', 'world,', 'winter,', 'summer'].includes(value),
(value): value is string => typeof value === 'string' && ['hello', 'world,', 'winter,', 'summer'].includes(value),
);

// Act / Assert
Expand All @@ -216,7 +218,9 @@ describe('wordsToSentenceUnmapperFor', () => {
fc.property(wordsArrayArbitrary, (words) => {
// Arrange
const { instance, canShrinkWithoutContext } = fakeArbitrary<string>();
canShrinkWithoutContext.mockImplementation((value) => typeof value === 'string' && words.includes(value));
canShrinkWithoutContext.mockImplementation(
(value): value is string => typeof value === 'string' && words.includes(value),
);

// Act
const mapped = wordsToSentenceMapper(words);
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"fast-check": "^3.0.0"
},
"peerDependencies": {
"vitest": ">=0.28.1 <1.0.0 || ^1"
"vitest": ">=0.28.1 <1.0.0 || ^1 || ^2"
},
"devDependencies": {
"@babel/core": "^7.24.7",
Expand All @@ -60,7 +60,7 @@
"jest": "^29.7.0",
"typescript": "~5.5.3",
"vite": "^5.3.3",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"keywords": [
"vitest",
Expand Down
Loading
Loading