Repository: dubzzz/fast-check
Pull request #1306 (2020-12-30 17:11:03)

💬 Prefer unique symbols over `Symbol.for`
<!-- Why is this PR for? -->
<!-- Describe the reason why you opened this PR or give a link towards the associated issue. -->

## In a nutshell

❌ New feature
❌ Fix an issue
❌ Documentation improvement
✔️ Other: *refactoring*

(✔️: yes, ❌: no)

## Potential impacts

Symbols changed but no problem expected except if you users are importing different versions of fast-check at the same time. In that case, symbols will differ between the versions. 

github-actions[bot]: Give a try to https://github.com/dubzzz/fast-check/pull/1306/commits/247986b8cd9450078505d58ab75c9d96a45a0966 with:

```bash
yarn add https://pkg.csb.dev/dubzzz/fast-check/commit/247986b8/fast-check
npm i https://pkg.csb.dev/dubzzz/fast-check/commit/247986b8/fast-check
```

⚠️ Package might not be accessible yet. Wait for CodeSandbox.

⚠️ By running one of these commands you will install the package defined by the head of the PR. But, tests are run against the result of the merge of the PR, not against the head of the PR*. *_If needed, you can install the package used for the tests by manually retrieving and installing the artifact bundle stored into GitHub Actions._

Useful links: [Codeclimate](https://codeclimate.com/github/dubzzz/fast-check/pull/1306), [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306), [CodeSandbox](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306) and [GitHub Actions](https://github.com/dubzzz/fast-check/actions/runs/453059448).
codesandbox[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306/builds/86916) or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 247986b8cd9450078505d58ab75c9d96a45a0966:

|Sandbox| Source |
|--|--|
|[Vanilla](https://codesandbox.io/s/vanilla-2bemh)| Configuration |

codecov[bot]: # [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306?src=pr&el=h1) Report
> Merging [#1306](https://codecov.io/gh/dubzzz/fast-check/pull/1306?src=pr&el=desc) (247986b) into [master](https://codecov.io/gh/dubzzz/fast-check/commit/52ded58354511c509b3f42e1d9a82125823941e5?el=desc) (52ded58) will **decrease** coverage by `8.75%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dubzzz/fast-check/pull/1306/graphs/tree.svg?width=650&height=150&src=pr&token=fRi2fJN730)](https://codecov.io/gh/dubzzz/fast-check/pull/1306?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1306      +/-   ##
==========================================
- Coverage   98.76%   90.01%   -8.76%     
==========================================
  Files          89       89              
  Lines        2914     2914              
  Branches      540      540              
==========================================
- Hits         2878     2623     -255     
- Misses         33      285     +252     
- Partials        3        6       +3     
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-tests | `90.01% <100.00%> (ø)` | |
| e2e-tests-10.x-Linux | `90.01% <100.00%> (+0.03%)` | :arrow_up: |
| e2e-tests-10.x-Windows | `?` | |
| e2e-tests-10.x-macOS | `?` | |
| e2e-tests-12.x-Linux | `89.97% <100.00%> (-0.04%)` | :arrow_down: |
| e2e-tests-12.x-Windows | `?` | |
| e2e-tests-12.x-macOS | `?` | |
| e2e-tests-14.x-Linux | `90.01% <100.00%> (+0.03%)` | :arrow_up: |
| e2e-tests-14.x-Windows | `?` | |
| e2e-tests-14.x-macOS | `?` | |
| unit-tests | `?` | |
| unit-tests-10.x-Linux | `?` | |
| unit-tests-12.x-Linux | `?` | |
| unit-tests-14.x-Linux | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/dubzzz/fast-check/pull/1306?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/check/runner/configuration/GlobalParameters.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL3J1bm5lci9jb25maWd1cmF0aW9uL0dsb2JhbFBhcmFtZXRlcnMudHM=) | `100.00% <100.00%> (ø)` | |
| [src/check/property/TimeoutProperty.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL3Byb3BlcnR5L1RpbWVvdXRQcm9wZXJ0eS50cw==) | `11.76% <0.00%> (-88.24%)` | :arrow_down: |
| [src/check/model/commands/ScheduledCommand.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL21vZGVsL2NvbW1hbmRzL1NjaGVkdWxlZENvbW1hbmQudHM=) | `7.14% <0.00%> (-82.15%)` | :arrow_down: |
| [src/utils/hash.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL3V0aWxzL2hhc2gudHM=) | `29.62% <0.00%> (-70.38%)` | :arrow_down: |
| [src/stream/LazyIterableIterator.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL3N0cmVhbS9MYXp5SXRlcmFibGVJdGVyYXRvci50cw==) | `63.63% <0.00%> (-36.37%)` | :arrow_down: |
| [src/check/property/AsyncProperty.generic.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL3Byb3BlcnR5L0FzeW5jUHJvcGVydHkuZ2VuZXJpYy50cw==) | `66.66% <0.00%> (-33.34%)` | :arrow_down: |
| [src/check/model/ModelRunner.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL21vZGVsL01vZGVsUnVubmVyLnRz) | `58.33% <0.00%> (-31.26%)` | :arrow_down: |
| [src/check/property/Property.generic.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL3Byb3BlcnR5L1Byb3BlcnR5LmdlbmVyaWMudHM=) | `70.58% <0.00%> (-29.42%)` | :arrow_down: |
| [.../check/runner/configuration/QualifiedParameters.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL3J1bm5lci9jb25maWd1cmF0aW9uL1F1YWxpZmllZFBhcmFtZXRlcnMudHM=) | `73.13% <0.00%> (-25.38%)` | :arrow_down: |
| [src/check/arbitrary/AsyncSchedulerArbitrary.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL2FyYml0cmFyeS9Bc3luY1NjaGVkdWxlckFyYml0cmFyeS50cw==) | `73.27% <0.00%> (-25.00%)` | :arrow_down: |
| ... and [30 more](https://codecov.io/gh/dubzzz/fast-check/pull/1306/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306?src=pr&el=footer). Last update [52ded58...bfde105](https://codecov.io/gh/dubzzz/fast-check/pull/1306?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

github-actions[bot]: Give a try to https://github.com/dubzzz/fast-check/pull/1306/commits/bfde1056488d24aa5ff90c1f4347447ff3603d22 with:

```bash
yarn add https://pkg.csb.dev/dubzzz/fast-check/commit/bfde1056/fast-check
npm i https://pkg.csb.dev/dubzzz/fast-check/commit/bfde1056/fast-check
```

⚠️ Package might not be accessible yet. Wait for CodeSandbox.

⚠️ By running one of these commands you will install the package defined by the head of the PR. But, tests are run against the result of the merge of the PR, not against the head of the PR*. *_If needed, you can install the package used for the tests by manually retrieving and installing the artifact bundle stored into GitHub Actions._

Useful links: [Codeclimate](https://codeclimate.com/github/dubzzz/fast-check/pull/1306), [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306), [CodeSandbox](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306) and [GitHub Actions](https://github.com/dubzzz/fast-check/actions/runs/453061149).
github-actions[bot]: Give a try to https://github.com/dubzzz/fast-check/pull/1306/commits/5b959a4fad83bb6ab2889ca2d59fe683ef9012db with:

```bash
yarn add https://pkg.csb.dev/dubzzz/fast-check/commit/5b959a4f/fast-check
npm i https://pkg.csb.dev/dubzzz/fast-check/commit/5b959a4f/fast-check
```

⚠️ Package might not be accessible yet. Wait for CodeSandbox.

⚠️ By running one of these commands you will install the package defined by the head of the PR. But, tests are run against the result of the merge of the PR, not against the head of the PR*. *_If needed, you can install the package used for the tests by manually retrieving and installing the artifact bundle stored into GitHub Actions._

Useful links: [Codeclimate](https://codeclimate.com/github/dubzzz/fast-check/pull/1306), [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306), [CodeSandbox](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306) and [GitHub Actions](https://github.com/dubzzz/fast-check/actions/runs/453062107).
github-actions[bot]: Give a try to https://github.com/dubzzz/fast-check/pull/1306/commits/7edf5c551ce964eb287f362f66817b9c89ac9e1e with:

```bash
yarn add https://pkg.csb.dev/dubzzz/fast-check/commit/7edf5c55/fast-check
npm i https://pkg.csb.dev/dubzzz/fast-check/commit/7edf5c55/fast-check
```

⚠️ Package might not be accessible yet. Wait for CodeSandbox.

⚠️ By running one of these commands you will install the package defined by the head of the PR. But, tests are run against the result of the merge of the PR, not against the head of the PR*. *_If needed, you can install the package used for the tests by manually retrieving and installing the artifact bundle stored into GitHub Actions._

Useful links: [Codeclimate](https://codeclimate.com/github/dubzzz/fast-check/pull/1306), [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306), [CodeSandbox](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306) and [GitHub Actions](https://github.com/dubzzz/fast-check/actions/runs/453072993).
github-actions[bot]: Give a try to https://github.com/dubzzz/fast-check/pull/1306/commits/c75411195b7088e7a41a22e569f84cc9265ca6d1 with:

```bash
yarn add https://pkg.csb.dev/dubzzz/fast-check/commit/c7541119/fast-check
npm i https://pkg.csb.dev/dubzzz/fast-check/commit/c7541119/fast-check
```

⚠️ Package might not be accessible yet. Wait for CodeSandbox.

⚠️ By running one of these commands you will install the package defined by the head of the PR. But, tests are run against the result of the merge of the PR, not against the head of the PR*. *_If needed, you can install the package used for the tests by manually retrieving and installing the artifact bundle stored into GitHub Actions._

Useful links: [Codeclimate](https://codeclimate.com/github/dubzzz/fast-check/pull/1306), [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306), [CodeSandbox](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306) and [GitHub Actions](https://github.com/dubzzz/fast-check/actions/runs/453079702).
github-actions[bot]: Give a try to https://github.com/dubzzz/fast-check/pull/1306/commits/0f6e506da297821dae76a553a1d170bdf58bb0ea with:

```bash
yarn add https://pkg.csb.dev/dubzzz/fast-check/commit/0f6e506d/fast-check
npm i https://pkg.csb.dev/dubzzz/fast-check/commit/0f6e506d/fast-check
```

⚠️ Package might not be accessible yet. Wait for CodeSandbox.

⚠️ By running one of these commands you will install the package defined by the head of the PR. But, tests are run against the result of the merge of the PR, not against the head of the PR*. *_If needed, you can install the package used for the tests by manually retrieving and installing the artifact bundle stored into GitHub Actions._

Useful links: [Codeclimate](https://codeclimate.com/github/dubzzz/fast-check/pull/1306), [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306), [CodeSandbox](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306) and [GitHub Actions](https://github.com/dubzzz/fast-check/actions/runs/453113346).
github-actions[bot]: Give a try to https://github.com/dubzzz/fast-check/pull/1306/commits/72d33e49be2c20060b5096243e91bc16cd146723 with:

```bash
yarn add https://pkg.csb.dev/dubzzz/fast-check/commit/72d33e49/fast-check
npm i https://pkg.csb.dev/dubzzz/fast-check/commit/72d33e49/fast-check
```

⚠️ Package might not be accessible yet. Wait for CodeSandbox.

⚠️ By running one of these commands you will install the package defined by the head of the PR. But, tests are run against the result of the merge of the PR, not against the head of the PR*. *_If needed, you can install the package used for the tests by manually retrieving and installing the artifact bundle stored into GitHub Actions._

Useful links: [Codeclimate](https://codeclimate.com/github/dubzzz/fast-check/pull/1306), [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1306), [CodeSandbox](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1306) and [GitHub Actions](https://github.com/dubzzz/fast-check/actions/runs/453121169).
dubzzz: Required for #1305

Patch:
diff --git a/src/check/precondition/PreconditionFailure.ts b/src/check/precondition/PreconditionFailure.ts
index 3ed3b2b4..7be205d9 100644
--- a/src/check/precondition/PreconditionFailure.ts
+++ b/src/check/precondition/PreconditionFailure.ts
@@ -3,7 +3,7 @@
  * @public
  */
 export class PreconditionFailure extends Error {
-  private static readonly SharedFootPrint: symbol = Symbol.for('fast-check/PreconditionFailure');
+  private static readonly SharedFootPrint: symbol = Symbol('fast-check/PreconditionFailure');
   private readonly footprint: symbol;
   constructor(readonly interruptExecution: boolean = false) {
     super();
diff --git a/src/check/runner/configuration/GlobalParameters.ts b/src/check/runner/configuration/GlobalParameters.ts
index fe7e75ce..a963a2b7 100644
--- a/src/check/runner/configuration/GlobalParameters.ts
+++ b/src/check/runner/configuration/GlobalParameters.ts
@@ -2,7 +2,7 @@ import { getGlobal } from '../../../utils/globalThis';
 import { Parameters } from './Parameters';
 
 /** @internal */
-const globalParametersSymbol = Symbol.for('fast-check/GlobalParameters');
+const globalParametersSymbol = Symbol('fast-check/GlobalParameters');
 
 /**
  * Type of legal hook function that can be used in the global parameter `beforeEach` and/or `afterEach`
diff --git a/src/check/symbols.ts b/src/check/symbols.ts
index 16307a85..95d86a0a 100644
--- a/src/check/symbols.ts
+++ b/src/check/symbols.ts
@@ -10,7 +10,7 @@
  *
  * @public
  */
-export const cloneMethod = Symbol.for('fast-check/cloneMethod');
+export const cloneMethod = Symbol('fast-check/cloneMethod');
 
 /** @internal */
 export interface WithCloneMethod<T> {


Test patch:
diff --git a/test/unit/check/precondition/Pre.spec.ts b/test/unit/check/precondition/Pre.spec.ts
index 0cb8e607..10fad440 100644
--- a/test/unit/check/precondition/Pre.spec.ts
+++ b/test/unit/check/precondition/Pre.spec.ts
@@ -1,5 +1,6 @@
 import { pre } from '../../../../src/check/precondition/Pre';
 import { PreconditionFailure } from '../../../../src/check/precondition/PreconditionFailure';
+import * as fc from '../../../../lib/fast-check';
 
 describe('pre', () => {
   it('should not throw on thruthy condition', () => {
@@ -15,4 +16,14 @@ describe('pre', () => {
     }
     expect(failed).toBe(true);
   });
+  it('should not understand PreconditionFailure thrown by other instances', () => {
+    let failed = false;
+    try {
+      fc.pre(false);
+    } catch (err) {
+      failed = true;
+      expect(PreconditionFailure.isFailure(err)).toBe(false);
+    }
+    expect(failed).toBe(true);
+  });
 });
diff --git a/test/unit/check/runner/configuration/GlobalParameters.spec.ts b/test/unit/check/runner/configuration/GlobalParameters.spec.ts
index 00bbd66b..59fdd0f2 100644
--- a/test/unit/check/runner/configuration/GlobalParameters.spec.ts
+++ b/test/unit/check/runner/configuration/GlobalParameters.spec.ts
@@ -3,6 +3,7 @@ import {
   readConfigureGlobal,
   resetConfigureGlobal,
 } from '../../../../../src/check/runner/configuration/GlobalParameters';
+import * as fc from '../../../../../lib/fast-check';
 
 describe('GlobalParameters', () => {
   afterEach(() => {
@@ -20,4 +21,11 @@ describe('GlobalParameters', () => {
     resetConfigureGlobal();
     expect(readConfigureGlobal()).toBe(undefined);
   });
+  it('should use distinct global configurations for distinct instances of fast-check', () => {
+    const myGlobalConfiguration = { numRuns: 123 };
+
+    configureGlobal(myGlobalConfiguration);
+    expect(readConfigureGlobal()).toBe(myGlobalConfiguration);
+    expect(fc.readConfigureGlobal()).not.toBe(myGlobalConfiguration);
+  });
 });
diff --git a/test/unit/check/symbols.spec.ts b/test/unit/check/symbols.spec.ts
new file mode 100644
index 00000000..c7149393
--- /dev/null
+++ b/test/unit/check/symbols.spec.ts
@@ -0,0 +1,8 @@
+import { cloneMethod } from '../../../src/check/symbols';
+import * as fc from '../../../lib/fast-check';
+
+describe('symbols', () => {
+  it('should declare distinct cloneMethod for distinct libraries', () => {
+    expect(cloneMethod).not.toBe(fc.cloneMethod);
+  });
+});