1 | import type { RandomType } from './RandomType.js';
|
2 | import type { VerbosityLevel } from './VerbosityLevel.js';
|
3 | import type { RunDetails } from '../reporter/RunDetails.js';
|
4 | import type { RandomGenerator } from 'pure-rand';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export interface Parameters<T = void> {
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | seed?: number;
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
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 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | asyncReporter?: (runDetails: RunDetails<T>) => Promise<void>;
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | errorWithCause?: boolean;
|
203 | }
|