Repository: dubzzz/fast-check
Pull request #2154 (2021-07-30 07:06:01)

🚚 Move commands arbitrary into /arbitrary
<!-- Context of the PR: short description and potentially linked issues -->

<!-- ...a few words to describe the content of this PR...               -->
<!-- ... -->

<!-- Type of PR: [ ] unchecked / [ ] checked -->
**_Category:_**

- [ ] ✨ Introduce new features
- [ ] 📝 Add or update documentation
- [ ] ✅ Add or update tests
- [ ] 🐛 Fix a bug
- [ ] 🏷️ Add or update types
- [ ] ⚡️ Improve performance
- [x] _Other(s):_ Moving code
<!-- Don't forget to add the gitmoji icon in the name of the PR -->
<!-- See: https://gitmoji.dev/                                  -->

<!-- Fixing bugs, adding features... may impact existing ones           -->
<!-- in order to track potential issues that could be related to your PR -->
<!-- please check the impacts and describe more precisely what to expect -->

**_Potential impacts:_**

<!-- 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? -->
- [ ] Generated values
- [ ] Shrink values
- [ ] Performance
- [ ] Typings
- [ ] _Other(s):_ ...


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/2154/builds/154432) or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7ee48e5931b8581358aa8cebce16cf689572c974:

|Sandbox| Source |
|--|--|
|[Vanilla](https://codesandbox.io/s/vanilla-onpr0)| Configuration |
|[fast-check-examples](https://codesandbox.io/s/fast-check-examples-r5m7q)| Configuration |

codecov[bot]: # [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/2154?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) Report
> Merging [#2154](https://codecov.io/gh/dubzzz/fast-check/pull/2154?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) (7ee48e5) into [main](https://codecov.io/gh/dubzzz/fast-check/commit/48607f5bdb32cc345869c8bcbb8246dfe068818d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) (48607f5) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dubzzz/fast-check/pull/2154/graphs/tree.svg?width=650&height=150&src=pr&token=fRi2fJN730&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN)](https://codecov.io/gh/dubzzz/fast-check/pull/2154?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN)

```diff
@@           Coverage Diff           @@
##             main    #2154   +/-   ##
=======================================
  Coverage   96.41%   96.41%           
=======================================
  Files         196      197    +1     
  Lines        4516     4519    +3     
  Branches      887      887           
=======================================
+ Hits         4354     4357    +3     
  Misses        158      158           
  Partials        4        4           
```

| Flag | Coverage Δ | |
|---|---|---|
| unit-tests | `96.41% <100.00%> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/dubzzz/fast-check/pull/2154?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | Coverage Δ | |
|---|---|---|
| [src/arbitrary/\_internals/CommandsArbitrary.ts](https://codecov.io/gh/dubzzz/fast-check/pull/2154/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#diff-c3JjL2FyYml0cmFyeS9faW50ZXJuYWxzL0NvbW1hbmRzQXJiaXRyYXJ5LnRz) | `96.38% <100.00%> (ø)` | |
| [src/arbitrary/commands.ts](https://codecov.io/gh/dubzzz/fast-check/pull/2154/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#diff-c3JjL2FyYml0cmFyeS9jb21tYW5kcy50cw==) | `100.00% <100.00%> (ø)` | |
| [src/fast-check-default.ts](https://codecov.io/gh/dubzzz/fast-check/pull/2154/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#diff-c3JjL2Zhc3QtY2hlY2stZGVmYXVsdC50cw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/2154?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/2154?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN). Last update [48607f5...7ee48e5](https://codecov.io/gh/dubzzz/fast-check/pull/2154?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN).


Patch:
diff --git a/src/check/model/commands/CommandsArbitrary.ts b/src/arbitrary/_internals/CommandsArbitrary.ts
similarity index 56%
rename from src/check/model/commands/CommandsArbitrary.ts
rename to src/arbitrary/_internals/CommandsArbitrary.ts
index 8ee0396f..9584f83e 100644
--- a/src/check/model/commands/CommandsArbitrary.ts
+++ b/src/arbitrary/_internals/CommandsArbitrary.ts
@@ -1,19 +1,16 @@
-import { Random } from '../../../random/generator/Random';
-import { Stream } from '../../../stream/Stream';
-import { Arbitrary } from '../../arbitrary/definition/Arbitrary';
-import { oneof } from '../../../arbitrary/oneof';
-import { AsyncCommand } from '../command/AsyncCommand';
-import { Command } from '../command/Command';
-import { ICommand } from '../command/ICommand';
-import { ReplayPath } from '../ReplayPath';
-import { CommandsIterable } from './CommandsIterable';
-import { CommandsContraints } from './CommandsContraints';
-import { CommandWrapper } from './CommandWrapper';
-import { makeLazy } from '../../../stream/LazyIterableIterator';
-import { NextArbitrary } from '../../arbitrary/definition/NextArbitrary';
-import { IntegerArbitrary } from '../../../arbitrary/_internals/IntegerArbitrary';
-import { convertFromNext, convertToNext } from '../../arbitrary/definition/Converters';
-import { NextValue } from '../../arbitrary/definition/NextValue';
+import { Arbitrary } from '../../check/arbitrary/definition/Arbitrary';
+import { convertToNext } from '../../check/arbitrary/definition/Converters';
+import { NextArbitrary } from '../../check/arbitrary/definition/NextArbitrary';
+import { NextValue } from '../../check/arbitrary/definition/NextValue';
+import { ICommand } from '../../check/model/command/ICommand';
+import { CommandsIterable } from '../../check/model/commands/CommandsIterable';
+import { CommandWrapper } from '../../check/model/commands/CommandWrapper';
+import { ReplayPath } from '../../check/model/ReplayPath';
+import { Random } from '../../random/generator/Random';
+import { makeLazy } from '../../stream/LazyIterableIterator';
+import { Stream } from '../../stream/Stream';
+import { oneof } from '../oneof';
+import { IntegerArbitrary } from './IntegerArbitrary';
 
 // eslint-disable-next-line @typescript-eslint/ban-types
 type CommandsArbitraryContext<Model extends object, Real, RunResult, CheckAsync extends boolean> = {
@@ -23,7 +20,7 @@ type CommandsArbitraryContext<Model extends object, Real, RunResult, CheckAsync
 
 /** @internal */
 // eslint-disable-next-line @typescript-eslint/ban-types
-class CommandsArbitrary<Model extends object, Real, RunResult, CheckAsync extends boolean> extends NextArbitrary<
+export class CommandsArbitrary<Model extends object, Real, RunResult, CheckAsync extends boolean> extends NextArbitrary<
   CommandsIterable<Model, Real, RunResult, CheckAsync>
 > {
   readonly oneCommandArb: NextArbitrary<CommandWrapper<Model, Real, RunResult, CheckAsync>>;
@@ -173,98 +170,3 @@ class CommandsArbitrary<Model extends object, Real, RunResult, CheckAsync extend
     });
   }
 }
-
-/**
- * For arrays of {@link AsyncCommand} to be executed by {@link asyncModelRun}
- *
- * This implementation comes with a shrinker adapted for commands.
- * It should shrink more efficiently than {@link array} for {@link AsyncCommand} arrays.
- *
- * @param commandArbs - Arbitraries responsible to build commands
- * @param maxCommands - Maximal number of commands to build
- *
- * @deprecated
- * Superceded by `fc.commands(commandArbs, {maxCommands})` - see {@link https://github.com/dubzzz/fast-check/issues/992 | #992}.
- * Ease the migration with {@link https://github.com/dubzzz/fast-check/tree/main/codemods/unify-signatures | our codemod script}.
- *
- * @remarks Since 1.5.0
- * @public
- */
-// eslint-disable-next-line @typescript-eslint/ban-types
-function commands<Model extends object, Real, CheckAsync extends boolean>(
-  commandArbs: Arbitrary<AsyncCommand<Model, Real, CheckAsync>>[],
-  maxCommands?: number
-): Arbitrary<Iterable<AsyncCommand<Model, Real, CheckAsync>>>;
-/**
- * For arrays of {@link Command} to be executed by {@link modelRun}
- *
- * This implementation comes with a shrinker adapted for commands.
- * It should shrink more efficiently than {@link array} for {@link Command} arrays.
- *
- * @param commandArbs - Arbitraries responsible to build commands
- * @param maxCommands - Maximal number of commands to build
- *
- * @deprecated
- * Superceded by `fc.commands(commandArbs, {maxCommands})` - see {@link https://github.com/dubzzz/fast-check/issues/992 | #992}.
- * Ease the migration with {@link https://github.com/dubzzz/fast-check/tree/main/codemods/unify-signatures | our codemod script}.
- *
- * @remarks Since 1.5.0
- * @public
- */
-// eslint-disable-next-line @typescript-eslint/ban-types
-function commands<Model extends object, Real>(
-  commandArbs: Arbitrary<Command<Model, Real>>[],
-  maxCommands?: number
-): Arbitrary<Iterable<Command<Model, Real>>>;
-/**
- * For arrays of {@link AsyncCommand} to be executed by {@link asyncModelRun}
- *
- * This implementation comes with a shrinker adapted for commands.
- * It should shrink more efficiently than {@link array} for {@link AsyncCommand} arrays.
- *
- * @param commandArbs - Arbitraries responsible to build commands
- * @param constraints - Contraints to be applied when generating the commands
- *
- * @remarks Since 1.11.0
- * @public
- */
-// eslint-disable-next-line @typescript-eslint/ban-types
-function commands<Model extends object, Real, CheckAsync extends boolean>(
-  commandArbs: Arbitrary<AsyncCommand<Model, Real, CheckAsync>>[],
-  constraints?: CommandsContraints
-): Arbitrary<Iterable<AsyncCommand<Model, Real, CheckAsync>>>;
-/**
- * For arrays of {@link Command} to be executed by {@link modelRun}
- *
- * This implementation comes with a shrinker adapted for commands.
- * It should shrink more efficiently than {@link array} for {@link Command} arrays.
- *
- * @param commandArbs - Arbitraries responsible to build commands
- * @param constraints - Constraints to be applied when generating the commands
- *
- * @remarks Since 1.11.0
- * @public
- */
-// eslint-disable-next-line @typescript-eslint/ban-types
-function commands<Model extends object, Real>(
-  commandArbs: Arbitrary<Command<Model, Real>>[],
-  constraints?: CommandsContraints
-): Arbitrary<Iterable<Command<Model, Real>>>;
-// eslint-disable-next-line @typescript-eslint/ban-types
-function commands<Model extends object, Real, RunResult, CheckAsync extends boolean>(
-  commandArbs: Arbitrary<ICommand<Model, Real, RunResult, CheckAsync>>[],
-  constraints?: number | CommandsContraints
-): Arbitrary<Iterable<ICommand<Model, Real, RunResult, CheckAsync>>> {
-  const config =
-    constraints == null ? {} : typeof constraints === 'number' ? { maxCommands: constraints } : constraints;
-  return convertFromNext(
-    new CommandsArbitrary(
-      commandArbs,
-      config.maxCommands != null ? config.maxCommands : 10,
-      config.replayPath != null ? config.replayPath : null,
-      !!config.disableReplayLog
-    )
-  );
-}
-
-export { commands };
diff --git a/src/arbitrary/commands.ts b/src/arbitrary/commands.ts
new file mode 100644
index 00000000..f4ad8860
--- /dev/null
+++ b/src/arbitrary/commands.ts
@@ -0,0 +1,101 @@
+import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
+import { convertFromNext } from '../check/arbitrary/definition/Converters';
+import { AsyncCommand } from '../check/model/command/AsyncCommand';
+import { Command } from '../check/model/command/Command';
+import { ICommand } from '../check/model/command/ICommand';
+import { CommandsContraints } from '../check/model/commands/CommandsContraints';
+import { CommandsArbitrary } from './_internals/CommandsArbitrary';
+
+/**
+ * For arrays of {@link AsyncCommand} to be executed by {@link asyncModelRun}
+ *
+ * This implementation comes with a shrinker adapted for commands.
+ * It should shrink more efficiently than {@link array} for {@link AsyncCommand} arrays.
+ *
+ * @param commandArbs - Arbitraries responsible to build commands
+ * @param maxCommands - Maximal number of commands to build
+ *
+ * @deprecated
+ * Superceded by `fc.commands(commandArbs, {maxCommands})` - see {@link https://github.com/dubzzz/fast-check/issues/992 | #992}.
+ * Ease the migration with {@link https://github.com/dubzzz/fast-check/tree/main/codemods/unify-signatures | our codemod script}.
+ *
+ * @remarks Since 1.5.0
+ * @public
+ */
+// eslint-disable-next-line @typescript-eslint/ban-types
+function commands<Model extends object, Real, CheckAsync extends boolean>(
+  commandArbs: Arbitrary<AsyncCommand<Model, Real, CheckAsync>>[],
+  maxCommands?: number
+): Arbitrary<Iterable<AsyncCommand<Model, Real, CheckAsync>>>;
+/**
+ * For arrays of {@link Command} to be executed by {@link modelRun}
+ *
+ * This implementation comes with a shrinker adapted for commands.
+ * It should shrink more efficiently than {@link array} for {@link Command} arrays.
+ *
+ * @param commandArbs - Arbitraries responsible to build commands
+ * @param maxCommands - Maximal number of commands to build
+ *
+ * @deprecated
+ * Superceded by `fc.commands(commandArbs, {maxCommands})` - see {@link https://github.com/dubzzz/fast-check/issues/992 | #992}.
+ * Ease the migration with {@link https://github.com/dubzzz/fast-check/tree/main/codemods/unify-signatures | our codemod script}.
+ *
+ * @remarks Since 1.5.0
+ * @public
+ */
+// eslint-disable-next-line @typescript-eslint/ban-types
+function commands<Model extends object, Real>(
+  commandArbs: Arbitrary<Command<Model, Real>>[],
+  maxCommands?: number
+): Arbitrary<Iterable<Command<Model, Real>>>;
+/**
+ * For arrays of {@link AsyncCommand} to be executed by {@link asyncModelRun}
+ *
+ * This implementation comes with a shrinker adapted for commands.
+ * It should shrink more efficiently than {@link array} for {@link AsyncCommand} arrays.
+ *
+ * @param commandArbs - Arbitraries responsible to build commands
+ * @param constraints - Contraints to be applied when generating the commands
+ *
+ * @remarks Since 1.11.0
+ * @public
+ */
+// eslint-disable-next-line @typescript-eslint/ban-types
+function commands<Model extends object, Real, CheckAsync extends boolean>(
+  commandArbs: Arbitrary<AsyncCommand<Model, Real, CheckAsync>>[],
+  constraints?: CommandsContraints
+): Arbitrary<Iterable<AsyncCommand<Model, Real, CheckAsync>>>;
+/**
+ * For arrays of {@link Command} to be executed by {@link modelRun}
+ *
+ * This implementation comes with a shrinker adapted for commands.
+ * It should shrink more efficiently than {@link array} for {@link Command} arrays.
+ *
+ * @param commandArbs - Arbitraries responsible to build commands
+ * @param constraints - Constraints to be applied when generating the commands
+ *
+ * @remarks Since 1.11.0
+ * @public
+ */
+// eslint-disable-next-line @typescript-eslint/ban-types
+function commands<Model extends object, Real>(
+  commandArbs: Arbitrary<Command<Model, Real>>[],
+  constraints?: CommandsContraints
+): Arbitrary<Iterable<Command<Model, Real>>>;
+// eslint-disable-next-line @typescript-eslint/ban-types
+function commands<Model extends object, Real, RunResult, CheckAsync extends boolean>(
+  commandArbs: Arbitrary<ICommand<Model, Real, RunResult, CheckAsync>>[],
+  constraints?: number | CommandsContraints
+): Arbitrary<Iterable<ICommand<Model, Real, RunResult, CheckAsync>>> {
+  const config =
+    constraints == null ? {} : typeof constraints === 'number' ? { maxCommands: constraints } : constraints;
+  return convertFromNext(
+    new CommandsArbitrary(
+      commandArbs,
+      config.maxCommands != null ? config.maxCommands : 10,
+      config.replayPath != null ? config.replayPath : null,
+      !!config.disableReplayLog
+    )
+  );
+}
+export { commands };
diff --git a/src/fast-check-default.ts b/src/fast-check-default.ts
index 18541aeb..df2797a0 100644
--- a/src/fast-check-default.ts
+++ b/src/fast-check-default.ts
@@ -96,7 +96,7 @@ import { webUrl, WebUrlConstraints } from './arbitrary/webUrl';
 import { AsyncCommand } from './check/model/command/AsyncCommand';
 import { Command } from './check/model/command/Command';
 import { ICommand } from './check/model/command/ICommand';
-import { commands } from './check/model/commands/CommandsArbitrary';
+import { commands } from './arbitrary/commands';
 import {
   asyncModelRun,
   modelRun,


Test patch:
diff --git a/test/unit/check/model/commands/CommandsArbitrary.spec.ts b/test/unit/check/model/commands/CommandsArbitrary.spec.ts
index 342b60c1..d9bc0087 100644
--- a/test/unit/check/model/commands/CommandsArbitrary.spec.ts
+++ b/test/unit/check/model/commands/CommandsArbitrary.spec.ts
@@ -4,7 +4,7 @@ import * as fc from '../../../../../lib/fast-check';
 import { Command } from '../../../../../src/check/model/command/Command';
 import { Random } from '../../../../../src/random/generator/Random';
 import { constant } from '../../../../../src/arbitrary/constant';
-import { commands } from '../../../../../src/check/model/commands/CommandsArbitrary';
+import { commands } from '../../../../../src/arbitrary/commands';
 import { genericTuple } from '../../../../../src/arbitrary/genericTuple';
 import { nat } from '../../../../../src/arbitrary/nat';
 import { Arbitrary } from '../../../../../src/check/arbitrary/definition/Arbitrary';