UNPKG

7.62 kBTypeScriptView Raw
1import type { RandomType } from './RandomType.js';
2import type { VerbosityLevel } from './VerbosityLevel.js';
3import type { RunDetails } from '../reporter/RunDetails.js';
4import type { RandomGenerator } from 'pure-rand';
5/**
6 * Customization of the parameters used to run the properties
7 * @remarks Since 0.0.6
8 * @public
9 */
10export interface Parameters<T = void> {
11 /**
12 * Initial seed of the generator: `Date.now()` by default
13 *
14 * It can be forced to replay a failed run.
15 *
16 * In theory, seeds are supposed to be 32-bit integers.
17 * In case of double value, the seed will be rescaled into a valid 32-bit integer (eg.: values between 0 and 1 will be evenly spread into the range of possible seeds).
18 *
19 * @remarks Since 0.0.6
20 */
21 seed?: number;
22 /**
23 * Random number generator: `xorshift128plus` by default
24 *
25 * Random generator is the core element behind the generation of random values - changing it might directly impact the quality and performances of the generation of random values.
26 * It can be one of: 'mersenne', 'congruential', 'congruential32', 'xorshift128plus', 'xoroshiro128plus'
27 * Or any function able to build a `RandomGenerator` based on a seed
28 *
29 * As required since pure-rand v6.0.0, when passing a builder for {@link RandomGenerator},
30 * the random number generator must generate values between -0x80000000 and 0x7fffffff.
31 *
32 * @remarks Since 1.6.0
33 */
34 randomType?: RandomType | ((seed: number) => RandomGenerator);
35 /**
36 * Number of runs before success: 100 by default
37 * @remarks Since 1.0.0
38 */
39 numRuns?: number;
40 /**
41 * Maximal number of skipped values per run
42 *
43 * Skipped is considered globally, so this value is used to compute maxSkips = maxSkipsPerRun * numRuns.
44 * Runner will consider a run to have failed if it skipped maxSkips+1 times before having generated numRuns valid entries.
45 *
46 * See {@link pre} for more details on pre-conditions
47 *
48 * @remarks Since 1.3.0
49 */
50 maxSkipsPerRun?: number;
51 /**
52 * Maximum time in milliseconds for the predicate to answer: disabled by default
53 *
54 * WARNING: Only works for async code (see {@link asyncProperty}), will not interrupt a synchronous code.
55 * @remarks Since 0.0.11
56 */
57 timeout?: number;
58 /**
59 * Skip all runs after a given time limit: disabled by default
60 *
61 * NOTE: Relies on `Date.now()`.
62 *
63 * NOTE:
64 * Useful to stop too long shrinking processes.
65 * Replay capability (see `seed`, `path`) can resume the shrinking.
66 *
67 * WARNING:
68 * It skips runs. Thus test might be marked as failed.
69 * Indeed, it might not reached the requested number of successful runs.
70 *
71 * @remarks Since 1.15.0
72 */
73 skipAllAfterTimeLimit?: number;
74 /**
75 * Interrupt test execution after a given time limit: disabled by default
76 *
77 * NOTE: Relies on `Date.now()`.
78 *
79 * NOTE:
80 * Useful to avoid having too long running processes in your CI.
81 * Replay capability (see `seed`, `path`) can still be used if needed.
82 *
83 * WARNING:
84 * If the test got interrupted before any failure occured
85 * and before it reached the requested number of runs specified by `numRuns`
86 * it will be marked as success. Except if `markInterruptAsFailure` has been set to `true`
87 *
88 * @remarks Since 1.19.0
89 */
90 interruptAfterTimeLimit?: number;
91 /**
92 * Mark interrupted runs as failed runs if preceded by one success or more: disabled by default
93 * Interrupted with no success at all always defaults to failure whatever the value of this flag.
94 * @remarks Since 1.19.0
95 */
96 markInterruptAsFailure?: boolean;
97 /**
98 * Skip runs corresponding to already tried values.
99 *
100 * WARNING:
101 * Discarded runs will be retried. Under the hood they are simple calls to `fc.pre`.
102 * In other words, if you ask for 100 runs but your generator can only generate 10 values then the property will fail as 100 runs will never be reached.
103 * Contrary to `ignoreEqualValues` you always have the number of runs you requested.
104 *
105 * NOTE: Relies on `fc.stringify` to check the equality.
106 *
107 * @remarks Since 2.14.0
108 */
109 skipEqualValues?: boolean;
110 /**
111 * Discard runs corresponding to already tried values.
112 *
113 * WARNING:
114 * Discarded runs will not be replaced.
115 * In other words, if you ask for 100 runs and have 2 discarded runs you will only have 98 effective runs.
116 *
117 * NOTE: Relies on `fc.stringify` to check the equality.
118 *
119 * @remarks Since 2.14.0
120 */
121 ignoreEqualValues?: boolean;
122 /**
123 * Way to replay a failing property directly with the counterexample.
124 * It can be fed with the counterexamplePath returned by the failing test (requires `seed` too).
125 * @remarks Since 1.0.0
126 */
127 path?: string;
128 /**
129 * Logger (see {@link statistics}): `console.log` by default
130 * @remarks Since 0.0.6
131 */
132 logger?(v: string): void;
133 /**
134 * Force the use of unbiased arbitraries: biased by default
135 * @remarks Since 1.1.0
136 */
137 unbiased?: boolean;
138 /**
139 * Enable verbose mode: {@link VerbosityLevel.None} by default
140 *
141 * Using `verbose: true` is equivalent to `verbose: VerbosityLevel.Verbose`
142 *
143 * It can prove very useful to troubleshoot issues.
144 * See {@link VerbosityLevel} for more details on each level.
145 *
146 * @remarks Since 1.1.0
147 */
148 verbose?: boolean | VerbosityLevel;
149 /**
150 * Custom values added at the beginning of generated ones
151 *
152 * It enables users to come with examples they want to test at every run
153 *
154 * @remarks Since 1.4.0
155 */
156 examples?: T[];
157 /**
158 * Stop run on failure
159 *
160 * It makes the run stop at the first encountered failure without shrinking.
161 *
162 * When used in complement to `seed` and `path`,
163 * it replays only the minimal counterexample.
164 *
165 * @remarks Since 1.11.0
166 */
167 endOnFailure?: boolean;
168 /**
169 * Replace the default reporter handling errors by a custom one
170 *
171 * Reporter is responsible to throw in case of failure: default one throws whenever `runDetails.failed` is true.
172 * But you may want to change this behaviour in yours.
173 *
174 * Only used when calling {@link assert}
175 * Cannot be defined in conjonction with `asyncReporter`
176 *
177 * @remarks Since 1.25.0
178 */
179 reporter?: (runDetails: RunDetails<T>) => void;
180 /**
181 * Replace the default reporter handling errors by a custom one
182 *
183 * Reporter is responsible to throw in case of failure: default one throws whenever `runDetails.failed` is true.
184 * But you may want to change this behaviour in yours.
185 *
186 * Only used when calling {@link assert}
187 * Cannot be defined in conjonction with `reporter`
188 * Not compatible with synchronous properties: runner will throw
189 *
190 * @remarks Since 1.25.0
191 */
192 asyncReporter?: (runDetails: RunDetails<T>) => Promise<void>;
193 /**
194 * Should the thrown Error include a cause leading to the original Error?
195 *
196 * In such case the original Error will disappear from the message of the Error thrown by fast-check
197 * and only appear within the cause part of it.
198 *
199 * Remark: At the moment, only node (≥16.14.0) and vitest seem to properly display such errors.
200 * Others will just discard the cause at display time.
201 */
202 errorWithCause?: boolean;
203}