UNPKG

4.63 kBTypeScriptView Raw
1import type { Size } from '../../../arbitrary/_internals/helpers/MaxLengthFromMinLength.js';
2import type { Parameters } from './Parameters.js';
3/**
4 * Type of legal hook function that can be used in the global parameter `beforeEach` and/or `afterEach`
5 * @remarks Since 2.3.0
6 * @public
7 */
8export type GlobalPropertyHookFunction = () => void;
9/**
10 * Type of legal hook function that can be used in the global parameter `asyncBeforeEach` and/or `asyncAfterEach`
11 * @remarks Since 2.3.0
12 * @public
13 */
14export type GlobalAsyncPropertyHookFunction = (() => Promise<unknown>) | (() => void);
15/**
16 * Type describing the global overrides
17 * @remarks Since 1.18.0
18 * @public
19 */
20export type GlobalParameters = Pick<Parameters<unknown>, Exclude<keyof Parameters<unknown>, 'path' | 'examples'>> & {
21 /**
22 * Specify a function that will be called before each execution of a property.
23 * It behaves as-if you manually called `beforeEach` method on all the properties you execute with fast-check.
24 *
25 * The function will be used for both {@link fast-check#property} and {@link fast-check#asyncProperty}.
26 * This global override should never be used in conjunction with `asyncBeforeEach`.
27 *
28 * @remarks Since 2.3.0
29 */
30 beforeEach?: GlobalPropertyHookFunction;
31 /**
32 * Specify a function that will be called after each execution of a property.
33 * It behaves as-if you manually called `afterEach` method on all the properties you execute with fast-check.
34 *
35 * The function will be used for both {@link fast-check#property} and {@link fast-check#asyncProperty}.
36 * This global override should never be used in conjunction with `asyncAfterEach`.
37 *
38 * @remarks Since 2.3.0
39 */
40 afterEach?: GlobalPropertyHookFunction;
41 /**
42 * Specify a function that will be called before each execution of an asynchronous property.
43 * It behaves as-if you manually called `beforeEach` method on all the asynchronous properties you execute with fast-check.
44 *
45 * The function will be used only for {@link fast-check#asyncProperty}. It makes synchronous properties created by {@link fast-check#property} unable to run.
46 * This global override should never be used in conjunction with `beforeEach`.
47 *
48 * @remarks Since 2.3.0
49 */
50 asyncBeforeEach?: GlobalAsyncPropertyHookFunction;
51 /**
52 * Specify a function that will be called after each execution of an asynchronous property.
53 * It behaves as-if you manually called `afterEach` method on all the asynchronous properties you execute with fast-check.
54 *
55 * The function will be used only for {@link fast-check#asyncProperty}. It makes synchronous properties created by {@link fast-check#property} unable to run.
56 * This global override should never be used in conjunction with `afterEach`.
57 *
58 * @remarks Since 2.3.0
59 */
60 asyncAfterEach?: GlobalAsyncPropertyHookFunction;
61 /**
62 * Define the base size to be used by arbitraries.
63 *
64 * By default arbitraries not specifying any size will default to it (except in some cases when used defaultSizeToMaxWhenMaxSpecified is true).
65 * For some arbitraries users will want to override the default and either define another size relative to this one,
66 * or a fixed one.
67 *
68 * @defaultValue `"small"`
69 * @remarks Since 2.22.0
70 */
71 baseSize?: Size;
72 /**
73 * When set to `true` and if the size has not been defined for this precise instance,
74 * it will automatically default to `"max"` if the user specified a upper bound for the range
75 * (applies to length and to depth).
76 *
77 * When `false`, the size will be defaulted to `baseSize` even if the user specified
78 * a upper bound for the range.
79 *
80 * @remarks Since 2.22.0
81 */
82 defaultSizeToMaxWhenMaxSpecified?: boolean;
83};
84/**
85 * Define global parameters that will be used by all the runners
86 *
87 * @example
88 * ```typescript
89 * fc.configureGlobal({ numRuns: 10 });
90 * //...
91 * fc.assert(
92 * fc.property(
93 * fc.nat(), fc.nat(),
94 * (a, b) => a + b === b + a
95 * ), { seed: 42 }
96 * ) // equivalent to { numRuns: 10, seed: 42 }
97 * ```
98 *
99 * @param parameters - Global parameters
100 *
101 * @remarks Since 1.18.0
102 * @public
103 */
104export declare function configureGlobal(parameters: GlobalParameters): void;
105/**
106 * Read global parameters that will be used by runners
107 * @remarks Since 1.18.0
108 * @public
109 */
110export declare function readConfigureGlobal(): GlobalParameters;
111/**
112 * Reset global parameters
113 * @remarks Since 1.18.0
114 * @public
115 */
116export declare function resetConfigureGlobal(): void;
117
\No newline at end of file