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

🐛 Better interrupt between multiple versions #4981

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .yarn/versions/eac5c04e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
releases:
fast-check: patch

declined:
- "@fast-check/ava"
- "@fast-check/jest"
- "@fast-check/vitest"
- "@fast-check/worker"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
export class PreconditionFailure extends Error {
/** @internal */
private static readonly SharedFootPrint: symbol = Symbol('fast-check/PreconditionFailure');
private static readonly SharedFootPrint: symbol = Symbol.for('fast-check/PreconditionFailure');
/** @internal */
private readonly footprint: symbol;
constructor(readonly interruptExecution: boolean = false) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/src/check/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @remarks Since 1.8.0
* @public
*/
export const cloneMethod = Symbol('fast-check/cloneMethod');
export const cloneMethod = Symbol.for('fast-check/cloneMethod');

/**
* Object instance that should be cloned from one generation/shrink to another
Expand Down
4 changes: 2 additions & 2 deletions packages/fast-check/src/utils/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const safePositiveInfinity = Number.POSITIVE_INFINITY;
* @remarks Since 2.17.0
* @public
*/
export const toStringMethod = Symbol('fast-check/toStringMethod');
export const toStringMethod = Symbol.for('fast-check/toStringMethod');
/**
* Interface to implement for {@link toStringMethod}
*
Expand Down Expand Up @@ -62,7 +62,7 @@ export function hasToStringMethod<T>(instance: T): instance is T & WithToStringM
* @remarks Since 2.17.0
* @public
*/
export const asyncToStringMethod = Symbol('fast-check/asyncToStringMethod');
export const asyncToStringMethod = Symbol.for('fast-check/asyncToStringMethod');
/**
* Interface to implement for {@link asyncToStringMethod}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ describe('pre', () => {
}
expect(failed).toBe(true);
});
it('should not understand PreconditionFailure thrown by other instances', () => {
it('should understand PreconditionFailure thrown by another instance of fast-check', () => {
let failed = false;
try {
fc.pre(false);
} catch (err) {
failed = true;
expect(PreconditionFailure.isFailure(err)).toBe(false);
expect(PreconditionFailure.isFailure(err)).toBe(true);
}
expect(failed).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/fast-check/test/unit/check/symbols.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { cloneMethod, hasCloneMethod } from '../../../src/check/symbols';
import * as fc from 'fast-check';

describe('symbols', () => {
it('should declare distinct cloneMethod for distinct libraries', () => {
expect(cloneMethod).not.toBe(fc.cloneMethod);
it('should declare identical cloneMethod for distinct instances of fast-check', () => {
expect(cloneMethod).toBe(fc.cloneMethod);
});
});

Expand Down
12 changes: 6 additions & 6 deletions packages/fast-check/test/unit/utils/stringify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe('stringify', () => {
const instance3 = { [toStringMethod]: () => { throw new Error('hello3'); } };
const stringified3 = stringify(instance3);
expect(stringified3.replace(/[\s\n]+/g, ' ')).toEqual(
'{[Symbol("fast-check/toStringMethod")]:() => { throw new Error("hello3"); }}',
'{[Symbol.for("fast-check/toStringMethod")]:() => { throw new Error("hello3"); }}',
); // fallbacking to default

class InProto {
Expand All @@ -435,11 +435,11 @@ describe('stringify', () => {
expect(stringify(instance4)).toEqual('hello4');

const instance5 = { [toStringMethod]: 1 }; // not callable
expect(stringify(instance5)).toEqual('{[Symbol("fast-check/toStringMethod")]:1}');
expect(stringify(instance5)).toEqual('{[Symbol.for("fast-check/toStringMethod")]:1}');
});
it('Should not be able to rely on the output of [asyncToStringMethod] in sync mode', () => {
const instance1 = { [asyncToStringMethod]: () => 'hello1' }; // not even async there
expect(stringify(instance1)).toEqual('{[Symbol("fast-check/asyncToStringMethod")]:() => "hello1"}'); // fallbacking to default
expect(stringify(instance1)).toEqual('{[Symbol.for("fast-check/asyncToStringMethod")]:() => "hello1"}'); // fallbacking to default

const instance2 = { [asyncToStringMethod]: () => 'hello2', [toStringMethod]: () => 'world' };
expect(stringify(instance2)).toEqual('world'); // fallbacking to [toStringMethod]
Expand Down Expand Up @@ -560,7 +560,7 @@ describe('asyncStringify', () => {
const instance4 = { [asyncToStringMethod]: async () => { throw new Error('hello4'); } };
const stringified4 = await asyncStringify(instance4);
expect(stringified4.replace(/[\s\n]+/g, ' ')).toEqual(
'{[Symbol("fast-check/asyncToStringMethod")]:async () => { throw new Error("hello4"); }}',
'{[Symbol.for("fast-check/asyncToStringMethod")]:async () => { throw new Error("hello4"); }}',
); // fallbacking to default

// prettier-ignore
Expand All @@ -571,7 +571,7 @@ describe('asyncStringify', () => {
const instance6 = { [asyncToStringMethod]: () => { throw new Error('hello6'); } }; // throw is sync
const stringified6 = await asyncStringify(instance6);
expect(stringified6.replace(/[\s\n]+/g, ' ')).toEqual(
'{[Symbol("fast-check/asyncToStringMethod")]:() => { throw new Error("hello6"); }}',
'{[Symbol.for("fast-check/asyncToStringMethod")]:() => { throw new Error("hello6"); }}',
); // fallbacking to default

class InProto {
Expand All @@ -583,7 +583,7 @@ describe('asyncStringify', () => {
expect(await asyncStringify(instance7)).toEqual('hello7');

const instance8 = { [asyncToStringMethod]: 1 }; // not callable
expect(await asyncStringify(instance8)).toEqual('{[Symbol("fast-check/asyncToStringMethod")]:1}');
expect(await asyncStringify(instance8)).toEqual('{[Symbol.for("fast-check/asyncToStringMethod")]:1}');

const instance9 = {
[asyncToStringMethod]: async () => {
Expand Down