@flemist/test-variants 3.0.3 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +287 -49
- package/build/browser/index.cjs +1 -0
- package/build/browser/index.d.ts +1 -0
- package/build/browser/index.mjs +4 -0
- package/build/common/-test/freezeProps.d.ts +2 -0
- package/build/common/garbage-collect/garbageCollect.d.ts +5 -0
- package/build/common/helpers/log.d.ts +5 -0
- package/build/common/index.cjs +1 -0
- package/build/common/index.d.ts +2 -0
- package/build/common/index.mjs +4 -0
- package/build/common/test-variants/-test/caches.d.ts +1 -0
- package/build/common/test-variants/-test/constants.d.ts +8 -0
- package/build/common/test-variants/-test/estimations/estimateCallCount.d.ts +4 -0
- package/build/common/test-variants/-test/estimations/estimateModeChanges.d.ts +4 -0
- package/build/common/test-variants/-test/generators/findBestError.d.ts +4 -0
- package/build/common/test-variants/-test/generators/primitives.d.ts +16 -0
- package/build/common/test-variants/-test/generators/run.d.ts +9 -0
- package/build/common/test-variants/-test/generators/template.d.ts +3 -0
- package/build/common/test-variants/-test/generators/testFunc.d.ts +3 -0
- package/build/common/test-variants/-test/helpers/CallController.d.ts +28 -0
- package/build/common/test-variants/-test/helpers/ErrorVariantController.d.ts +17 -0
- package/build/common/test-variants/-test/helpers/TestError.d.ts +2 -0
- package/build/common/test-variants/-test/helpers/deepEqualJsonLikeWithoutSeed.d.ts +1 -0
- package/build/common/test-variants/-test/helpers/deepFreezeJsonLike.d.ts +1 -0
- package/build/common/test-variants/-test/helpers/forEachVariant.d.ts +4 -0
- package/build/common/test-variants/-test/helpers/getMaxAttemptsPerVariant.d.ts +2 -0
- package/build/common/test-variants/-test/helpers/getParallelLimit.d.ts +7 -0
- package/build/common/test-variants/-test/helpers/getVariantArgs.d.ts +12 -0
- package/build/common/test-variants/-test/helpers/runWithTimeController.d.ts +7 -0
- package/build/common/test-variants/-test/invariants/CallCountInvariant.d.ts +18 -0
- package/build/common/test-variants/-test/invariants/CallOptionsInvariant.d.ts +32 -0
- package/build/common/test-variants/-test/invariants/ErrorBehaviorInvariant.d.ts +32 -0
- package/build/common/test-variants/-test/invariants/FindBestErrorInvariant.d.ts +37 -0
- package/build/common/test-variants/-test/invariants/IterationsInvariant.d.ts +21 -0
- package/build/common/test-variants/-test/invariants/LimitTimeInvariant.d.ts +26 -0
- package/build/common/test-variants/-test/invariants/LogInvariant.d.ts +126 -0
- package/build/common/test-variants/-test/invariants/OnErrorInvariant.d.ts +38 -0
- package/build/common/test-variants/-test/invariants/OnModeChangeInvariant.d.ts +32 -0
- package/build/common/test-variants/-test/invariants/ParallelInvariant.d.ts +25 -0
- package/build/common/test-variants/-test/log.d.ts +3 -0
- package/build/common/test-variants/-test/types.d.ts +34 -0
- package/build/common/test-variants/-test/variants.d.ts +3 -0
- package/build/common/test-variants/createTestRun.d.ts +3 -0
- package/build/common/test-variants/createTestVariants.d.ts +4 -0
- package/build/common/test-variants/iterator/createVariantsIterator.d.ts +4 -0
- package/build/common/test-variants/iterator/helpers/findValueIndex.d.ts +2 -0
- package/build/common/test-variants/iterator/helpers/mode.d.ts +3 -0
- package/build/common/test-variants/iterator/helpers/template.d.ts +7 -0
- package/build/common/test-variants/iterator/types.d.ts +106 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/caches.d.ts +1 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/check.d.ts +2 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/create.d.ts +3 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/format.d.ts +6 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/parse.d.ts +8 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/variants.d.ts +12 -0
- package/build/common/test-variants/iterator/variant-navigation/variantNavigation.d.ts +28 -0
- package/build/common/test-variants/log/format.d.ts +7 -0
- package/build/common/test-variants/log/getMemoryUsage.d.ts +2 -0
- package/build/common/test-variants/log/logOptions.d.ts +8 -0
- package/build/common/test-variants/run/AbortErrorSilent.d.ts +3 -0
- package/build/common/test-variants/run/RunContext.d.ts +21 -0
- package/build/common/test-variants/run/createRunResult.d.ts +6 -0
- package/build/common/test-variants/run/createRunState.d.ts +23 -0
- package/build/common/test-variants/run/errorHandlers.d.ts +20 -0
- package/build/common/test-variants/run/gcManager.d.ts +6 -0
- package/build/common/test-variants/run/resolveRunOptions.d.ts +23 -0
- package/build/common/test-variants/run/runIterationLoop.d.ts +9 -0
- package/build/common/test-variants/run/runLogger.d.ts +9 -0
- package/build/common/test-variants/run/types.d.ts +57 -0
- package/build/common/test-variants/testVariantsRun.d.ts +6 -0
- package/build/common/test-variants/types.d.ts +187 -0
- package/build/createTestVariants-BE_TQ9u5.mjs +1018 -0
- package/build/createTestVariants-Cmx68kHs.js +4 -0
- package/build/node/index.cjs +1 -0
- package/build/node/index.d.ts +8 -0
- package/build/node/index.mjs +107 -0
- package/build/node/test-variants/createSaveErrorVariantsStore.d.ts +5 -0
- package/{dist/lib → build/node}/test-variants/saveErrorVariants.d.ts +4 -3
- package/package.json +109 -68
- package/dist/bundle/browser.js +0 -669
- package/dist/lib/garbage-collect/garbageCollect.cjs +0 -30
- package/dist/lib/garbage-collect/garbageCollect.d.ts +0 -2
- package/dist/lib/garbage-collect/garbageCollect.mjs +0 -26
- package/dist/lib/index.cjs +0 -23
- package/dist/lib/index.d.ts +0 -7
- package/dist/lib/index.mjs +0 -13
- package/dist/lib/test-variants/argsToString.cjs +0 -17
- package/dist/lib/test-variants/argsToString.d.ts +0 -2
- package/dist/lib/test-variants/argsToString.mjs +0 -13
- package/dist/lib/test-variants/createTestVariants.cjs +0 -91
- package/dist/lib/test-variants/createTestVariants.d.ts +0 -8
- package/dist/lib/test-variants/createTestVariants.mjs +0 -87
- package/dist/lib/test-variants/createTestVariants.perf.cjs +0 -44
- package/dist/lib/test-variants/createTestVariants.perf.d.ts +0 -1
- package/dist/lib/test-variants/createTestVariants.perf.mjs +0 -42
- package/dist/lib/test-variants/prime.cjs +0 -65
- package/dist/lib/test-variants/prime.d.ts +0 -3
- package/dist/lib/test-variants/prime.mjs +0 -59
- package/dist/lib/test-variants/prime.perf.cjs +0 -30
- package/dist/lib/test-variants/prime.perf.d.ts +0 -1
- package/dist/lib/test-variants/prime.perf.mjs +0 -28
- package/dist/lib/test-variants/saveErrorVariants.cjs +0 -97
- package/dist/lib/test-variants/saveErrorVariants.mjs +0 -69
- package/dist/lib/test-variants/testVariantsCreateTestRun.cjs +0 -80
- package/dist/lib/test-variants/testVariantsCreateTestRun.d.ts +0 -22
- package/dist/lib/test-variants/testVariantsCreateTestRun.mjs +0 -76
- package/dist/lib/test-variants/testVariantsIterable.cjs +0 -70
- package/dist/lib/test-variants/testVariantsIterable.d.ts +0 -15
- package/dist/lib/test-variants/testVariantsIterable.mjs +0 -66
- package/dist/lib/test-variants/testVariantsIterator.cjs +0 -429
- package/dist/lib/test-variants/testVariantsIterator.d.ts +0 -67
- package/dist/lib/test-variants/testVariantsIterator.mjs +0 -425
- package/dist/lib/test-variants/testVariantsRun.cjs +0 -289
- package/dist/lib/test-variants/testVariantsRun.d.ts +0 -50
- package/dist/lib/test-variants/testVariantsRun.mjs +0 -265
- package/dist/lib/test-variants/types.cjs +0 -2
- package/dist/lib/test-variants/types.d.ts +0 -20
- package/dist/lib/test-variants/types.mjs +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IAbortSignalFast, IAbortControllerFast } from '@flemist/abort-controller-fast';
|
|
2
|
+
import { Obj } from '@flemist/simple-utils';
|
|
3
|
+
import { IPool } from '@flemist/time-limits';
|
|
4
|
+
import { VariantsIterator } from '../iterator/types';
|
|
5
|
+
import { TestOptions } from '../types';
|
|
6
|
+
import { RunState } from './createRunState';
|
|
7
|
+
import { RunOptionsResolved } from './resolveRunOptions';
|
|
8
|
+
import { TestVariantsTestRun } from './types';
|
|
9
|
+
/** Context for test variants iteration loop */
|
|
10
|
+
export type RunContext<Args extends Obj> = {
|
|
11
|
+
options: RunOptionsResolved<Args>;
|
|
12
|
+
testRun: TestVariantsTestRun<Args>;
|
|
13
|
+
variantsIterator: VariantsIterator<Args>;
|
|
14
|
+
testOptions: TestOptions;
|
|
15
|
+
testOptionsParallel: TestOptions;
|
|
16
|
+
abortControllerGlobal: IAbortControllerFast;
|
|
17
|
+
abortControllerParallel: IAbortControllerFast;
|
|
18
|
+
abortSignal: IAbortSignalFast;
|
|
19
|
+
pool: IPool | null;
|
|
20
|
+
state: RunState;
|
|
21
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Obj } from '@flemist/simple-utils';
|
|
2
|
+
import { VariantsIterator } from '../iterator/types';
|
|
3
|
+
import { TestVariantsResult } from '../types';
|
|
4
|
+
import { RunState } from './createRunState';
|
|
5
|
+
/** Create test variants run result */
|
|
6
|
+
export declare function createRunResult<Args extends Obj>(state: RunState, variantsIterator: VariantsIterator<Args>, dontThrowIfError: boolean | null | undefined): TestVariantsResult<Args>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ITimeController } from '@flemist/time-controller';
|
|
2
|
+
import { ModeChangeEvent } from '../types';
|
|
3
|
+
/** Runtime state for test variants run */
|
|
4
|
+
export type RunState = {
|
|
5
|
+
startTime: number;
|
|
6
|
+
startMemory: number | null;
|
|
7
|
+
/** Few repeats of error variant if JS debugger is attached */
|
|
8
|
+
debugMode: boolean;
|
|
9
|
+
/** Number of test function calls */
|
|
10
|
+
tests: number;
|
|
11
|
+
/** Sum of iterationsSync + iterationsAsync from test results */
|
|
12
|
+
iterations: number;
|
|
13
|
+
iterationsAsync: number;
|
|
14
|
+
prevLogTime: number;
|
|
15
|
+
prevLogMemory: number | null;
|
|
16
|
+
/** Mode change event waiting to be logged with next progress */
|
|
17
|
+
pendingModeChange: ModeChangeEvent | null;
|
|
18
|
+
prevGcTime: number;
|
|
19
|
+
prevGcIterations: number;
|
|
20
|
+
prevGcIterationsAsync: number;
|
|
21
|
+
};
|
|
22
|
+
/** Create initial run state */
|
|
23
|
+
export declare function createRunState(timeController: ITimeController, startMemory: number | null): RunState;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PromiseOrValue } from '@flemist/async-utils';
|
|
2
|
+
import { Obj } from '@flemist/simple-utils';
|
|
3
|
+
import { ArgsWithSeed } from '../types';
|
|
4
|
+
import { RunContext } from './RunContext';
|
|
5
|
+
/**
|
|
6
|
+
* Handle test error in parallel execution mode.
|
|
7
|
+
*
|
|
8
|
+
* In findBestError mode:
|
|
9
|
+
* - With sequentialOnError=true: adds limit, saves args, aborts parallel (fall back to sequential)
|
|
10
|
+
* - With sequentialOnError=false: adds limit, saves args, continues parallel with new limits
|
|
11
|
+
* Without findBestError: saves args and aborts with error.
|
|
12
|
+
*/
|
|
13
|
+
export declare function handleErrorParallel<Args extends Obj>(runContext: RunContext<Args>, args: ArgsWithSeed<Args>, error: unknown, tests: number): void;
|
|
14
|
+
/**
|
|
15
|
+
* Handle test error in sequential execution mode.
|
|
16
|
+
*
|
|
17
|
+
* In findBestError mode: adds limit to iterator, saves args.
|
|
18
|
+
* Without findBestError: saves args and throws error.
|
|
19
|
+
*/
|
|
20
|
+
export declare function handleErrorSequential<Args extends Obj>(runContext: RunContext<Args>, args: ArgsWithSeed<Args>, error: unknown, tests: number): PromiseOrValue<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RunContext } from './RunContext';
|
|
2
|
+
import { RunState } from './createRunState';
|
|
3
|
+
/** Check if GC should be triggered */
|
|
4
|
+
export declare function shouldTriggerGC(runContext: RunContext<any>, now: number): boolean;
|
|
5
|
+
/** Trigger GC and update state */
|
|
6
|
+
export declare function triggerGC(state: RunState, now: number): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IAbortSignalFast } from '@flemist/abort-controller-fast';
|
|
2
|
+
import { RequiredNonNullable, Obj } from '@flemist/simple-utils';
|
|
3
|
+
import { ITimeController } from '@flemist/time-controller';
|
|
4
|
+
import { TestVariantsLogOptions, FindBestErrorOptions } from '../types';
|
|
5
|
+
import { TestVariantsRunOptionsInternal, SaveErrorVariantsStore } from './types';
|
|
6
|
+
/** Resolved configuration for test variants run */
|
|
7
|
+
export type RunOptionsResolved<Args extends Obj> = {
|
|
8
|
+
store: SaveErrorVariantsStore<Args> | null;
|
|
9
|
+
GC_Iterations: number;
|
|
10
|
+
GC_IterationsAsync: number;
|
|
11
|
+
GC_Interval: number;
|
|
12
|
+
logOptions: RequiredNonNullable<TestVariantsLogOptions>;
|
|
13
|
+
abortSignalExternal: IAbortSignalFast | null | undefined;
|
|
14
|
+
findBestError: FindBestErrorOptions | null | undefined;
|
|
15
|
+
dontThrowIfError: boolean | null | undefined;
|
|
16
|
+
timeController: ITimeController;
|
|
17
|
+
/** Maximum number of parallel threads */
|
|
18
|
+
parallel: number;
|
|
19
|
+
/** Switch to sequential mode after first error in findBestError mode */
|
|
20
|
+
sequentialOnError: boolean;
|
|
21
|
+
};
|
|
22
|
+
/** Resolve run options into normalized structure */
|
|
23
|
+
export declare function resolveRunOptions<Args extends Obj, SavedArgs = Args>(options: TestVariantsRunOptionsInternal<Args, SavedArgs> | null | undefined): RunOptionsResolved<Args>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PromiseOrValue } from '@flemist/async-utils';
|
|
2
|
+
import { Obj } from '@flemist/simple-utils';
|
|
3
|
+
import { RunContext } from './RunContext';
|
|
4
|
+
/**
|
|
5
|
+
* Main iteration loop with sync mode optimization.
|
|
6
|
+
* Runs synchronously when all tests are sync and no async operations are triggered.
|
|
7
|
+
* Iterator handles all termination conditions internally via next() returning null.
|
|
8
|
+
*/
|
|
9
|
+
export declare function runIterationLoop<Args extends Obj>(runContext: RunContext<Args>): PromiseOrValue<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RequiredNonNullable } from '@flemist/simple-utils';
|
|
2
|
+
import { TestVariantsLogOptions } from '../types';
|
|
3
|
+
import { RunContext } from './RunContext';
|
|
4
|
+
export declare function logStart(logOptions: RequiredNonNullable<TestVariantsLogOptions>, startMemory: number | null): void;
|
|
5
|
+
export declare function logCompleted(runContext: RunContext<any>): void;
|
|
6
|
+
/** Log pending mode change and clear it */
|
|
7
|
+
export declare function logModeChange(runContext: RunContext<any>): void;
|
|
8
|
+
/** Returns true if logging was performed */
|
|
9
|
+
export declare function logProgress(runContext: RunContext<any>): boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PromiseOrValue } from '@flemist/async-utils';
|
|
2
|
+
import { Obj, RequiredNonNullable } from '@flemist/simple-utils';
|
|
3
|
+
import { TestVariantsTemplatesExt, VariantsIterator } from '../iterator/types';
|
|
4
|
+
import { ArgsWithSeed, OnErrorCallback, SaveErrorVariantsOptions, TestOptions, TestVariantsLogOptions, TestVariantsResult, TestVariantsRunOptions } from '../types';
|
|
5
|
+
/** Result of test run (internal format with separate sync/async counts) */
|
|
6
|
+
export type TestFuncResult = void | {
|
|
7
|
+
iterationsAsync: number;
|
|
8
|
+
iterationsSync: number;
|
|
9
|
+
};
|
|
10
|
+
/** Test run function (internal - wraps user's test with error handling) */
|
|
11
|
+
export type TestVariantsTestRun<Args extends Obj> = (args: ArgsWithSeed<Args>, tests: number, options: TestOptions) => PromiseOrValue<TestFuncResult>;
|
|
12
|
+
/** Result of user's test function (number treated as iterationsSync) */
|
|
13
|
+
export type TestVariantsTestResult = number | void | TestFuncResult;
|
|
14
|
+
/** User's test function */
|
|
15
|
+
export type TestVariantsTest<Args extends Obj> = (args: ArgsWithSeed<Args>, options: TestOptions) => PromiseOrValue<TestVariantsTestResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Store for saving and loading error-causing parameter combinations.
|
|
18
|
+
* Node.js implementation uses file system. Browser returns null (not supported).
|
|
19
|
+
*/
|
|
20
|
+
export interface SaveErrorVariantsStore<Args extends Obj> {
|
|
21
|
+
/**
|
|
22
|
+
* Save error-causing args to storage.
|
|
23
|
+
* Handles concurrency protection and deduplication internally.
|
|
24
|
+
*/
|
|
25
|
+
save(args: ArgsWithSeed<Args>): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Replay saved error variants before normal iteration.
|
|
28
|
+
* If error occurs during replay:
|
|
29
|
+
* - In findBestError mode (useToFindBestError + findBestErrorEnabled): adds limit and continues
|
|
30
|
+
* - Otherwise: throws the error
|
|
31
|
+
*/
|
|
32
|
+
replay(options: SaveErrorVariantsStoreReplayOptions<Args>): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
/** Options for SaveErrorVariantsStore.replay method */
|
|
35
|
+
export type SaveErrorVariantsStoreReplayOptions<Args extends Obj> = {
|
|
36
|
+
/** Test run function */
|
|
37
|
+
testRun: TestVariantsTestRun<Args>;
|
|
38
|
+
/** Iterator to add limits to */
|
|
39
|
+
variantsIterator: VariantsIterator<Args>;
|
|
40
|
+
/** Options passed to test function */
|
|
41
|
+
testOptions: TestOptions;
|
|
42
|
+
/** Whether findBestError is enabled */
|
|
43
|
+
findBestErrorEnabled?: null | boolean;
|
|
44
|
+
};
|
|
45
|
+
/** Factory function for creating SaveErrorVariantsStore */
|
|
46
|
+
export type CreateSaveErrorVariantsStore<Args extends Obj, SavedArgs = Args> = (options: SaveErrorVariantsOptions<Args, SavedArgs>) => SaveErrorVariantsStore<Args> | null;
|
|
47
|
+
/** Internal run options with injected dependencies */
|
|
48
|
+
export type TestVariantsRunOptionsInternal<Args extends Obj = Obj, SavedArgs = Args> = TestVariantsRunOptions<Args, SavedArgs> & {
|
|
49
|
+
createSaveErrorVariantsStore?: null | CreateSaveErrorVariantsStore<Args, SavedArgs>;
|
|
50
|
+
};
|
|
51
|
+
export type TestVariantsCreateTestRunOptions<Args extends Obj> = {
|
|
52
|
+
onError?: null | OnErrorCallback<Args>;
|
|
53
|
+
/** Resolved logging options */
|
|
54
|
+
log: RequiredNonNullable<TestVariantsLogOptions>;
|
|
55
|
+
};
|
|
56
|
+
export type TestVariantsCall<Args extends Obj> = <SavedArgs = Args>(options?: null | TestVariantsRunOptionsInternal<Args, SavedArgs>) => PromiseOrValue<TestVariantsResult<Args>>;
|
|
57
|
+
export type TestVariantsSetArgs<Args extends Obj> = <ArgsExtra extends Obj>(args: TestVariantsTemplatesExt<Omit<Args, 'seed'>, Omit<ArgsExtra, 'seed'>>) => TestVariantsCall<Args>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Obj } from '@flemist/simple-utils';
|
|
2
|
+
import { VariantsIterator } from './iterator/types';
|
|
3
|
+
import { RunState } from './run/createRunState';
|
|
4
|
+
import { TestVariantsTestRun, TestVariantsRunOptionsInternal } from './run/types';
|
|
5
|
+
import { TestVariantsResult } from './types';
|
|
6
|
+
export declare function testVariantsRun<Args extends Obj, SavedArgs = Args>(testRun: TestVariantsTestRun<Args>, variantsIterator: VariantsIterator<Args>, state: RunState, options?: null | TestVariantsRunOptionsInternal<Args, SavedArgs>): Promise<TestVariantsResult<Args>>;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { IAbortSignalFast } from '@flemist/abort-controller-fast';
|
|
2
|
+
import { PromiseOrValue } from '@flemist/async-utils';
|
|
3
|
+
import { Obj } from '@flemist/simple-utils';
|
|
4
|
+
import { ITimeController } from '@flemist/time-controller';
|
|
5
|
+
export type { TestVariantsTemplatesExt } from './iterator/types';
|
|
6
|
+
export type { TestVariantsCall, TestVariantsSetArgs, TestVariantsTestResult, } from './run/types';
|
|
7
|
+
export type Equals = (a: any, b: any) => boolean;
|
|
8
|
+
/** Args with seed from getSeed */
|
|
9
|
+
export type ArgsWithSeed<Args extends Obj> = Args & {
|
|
10
|
+
seed: any;
|
|
11
|
+
};
|
|
12
|
+
/** Base mode configuration shared by all modes */
|
|
13
|
+
export type BaseModeConfig = {
|
|
14
|
+
/** Maximum time in ms for this phase */
|
|
15
|
+
limitTime?: null | number;
|
|
16
|
+
/** Maximum total picks in this phase */
|
|
17
|
+
limitTests?: null | number;
|
|
18
|
+
};
|
|
19
|
+
/** Sequential mode configuration shared by forward and backward modes */
|
|
20
|
+
export type SequentialModeConfig = BaseModeConfig & {
|
|
21
|
+
/** Number of full passes through all variants */
|
|
22
|
+
cycles?: null | number;
|
|
23
|
+
/** Number of repeat tests per variant */
|
|
24
|
+
attemptsPerVariant?: null | number;
|
|
25
|
+
};
|
|
26
|
+
/** Forward mode configuration */
|
|
27
|
+
export type ForwardModeConfig = SequentialModeConfig & {
|
|
28
|
+
mode: 'forward';
|
|
29
|
+
};
|
|
30
|
+
/** Backward mode configuration - iterates from last to first combination within limits */
|
|
31
|
+
export type BackwardModeConfig = SequentialModeConfig & {
|
|
32
|
+
mode: 'backward';
|
|
33
|
+
};
|
|
34
|
+
/** Random mode configuration */
|
|
35
|
+
export type RandomModeConfig = BaseModeConfig & {
|
|
36
|
+
mode: 'random';
|
|
37
|
+
};
|
|
38
|
+
/** Mode configuration for iteration phase */
|
|
39
|
+
export type ModeConfig = ForwardModeConfig | BackwardModeConfig | RandomModeConfig;
|
|
40
|
+
export type ModeType = ModeConfig['mode'];
|
|
41
|
+
/** Parameters passed to getSeed function for generating test seeds */
|
|
42
|
+
export type GetSeedParams = {
|
|
43
|
+
/** Total number of tests run */
|
|
44
|
+
tests: number;
|
|
45
|
+
};
|
|
46
|
+
/** Options for limiting per-arg indexes on error */
|
|
47
|
+
export type LimitArgOnErrorOptions = {
|
|
48
|
+
/** Arg name */
|
|
49
|
+
name: string;
|
|
50
|
+
/** Current template values array for this arg */
|
|
51
|
+
values: readonly any[];
|
|
52
|
+
/** Current max value index limit for this arg; null if no limit */
|
|
53
|
+
maxValueIndex: number | null;
|
|
54
|
+
};
|
|
55
|
+
/** Callback to decide whether to apply limit for specific arg */
|
|
56
|
+
export type LimitArgOnError = (options: LimitArgOnErrorOptions) => boolean;
|
|
57
|
+
/** Log entry type for custom log function */
|
|
58
|
+
export type TestVariantsLogType = Exclude<keyof TestVariantsLogOptions, 'func'>;
|
|
59
|
+
/** Custom log function signature */
|
|
60
|
+
export type TestVariantsLogFunc = (type: TestVariantsLogType, message: string) => void;
|
|
61
|
+
/** Logging options for test-variants */
|
|
62
|
+
export type TestVariantsLogOptions = {
|
|
63
|
+
/** Log at test start with memory info; default true */
|
|
64
|
+
start?: null | boolean;
|
|
65
|
+
/** Progress log interval in ms; false/0 to disable; default 5000 */
|
|
66
|
+
progress?: null | false | number;
|
|
67
|
+
/** Log on completion; default true */
|
|
68
|
+
completed?: null | boolean;
|
|
69
|
+
/** Log error details (variant index, args, error); default true */
|
|
70
|
+
error?: null | boolean;
|
|
71
|
+
/** Log mode changes with all parameters; default true */
|
|
72
|
+
modeChange?: null | boolean;
|
|
73
|
+
/** Debug logging for internal behavior; default false */
|
|
74
|
+
debug?: null | boolean;
|
|
75
|
+
/** Custom log function; receives log type and formatted message */
|
|
76
|
+
func?: null | TestVariantsLogFunc;
|
|
77
|
+
};
|
|
78
|
+
/** Options for generating error variant file path */
|
|
79
|
+
export type GenerateErrorVariantFilePathOptions = {
|
|
80
|
+
sessionDate: Date;
|
|
81
|
+
};
|
|
82
|
+
/** Options for saving and replaying error-causing parameter combinations */
|
|
83
|
+
export type SaveErrorVariantsOptions<Args extends Obj, SavedArgs = Args> = {
|
|
84
|
+
/** Directory path for error variant JSON files */
|
|
85
|
+
dir: string;
|
|
86
|
+
/** Retry attempts per variant during replay phase (default: 1) */
|
|
87
|
+
attemptsPerVariant?: null | number;
|
|
88
|
+
/** Custom file path generator; returns path relative to dir, or absolute path; null - use default path */
|
|
89
|
+
getFilePath?: null | ((options: GenerateErrorVariantFilePathOptions) => string | null);
|
|
90
|
+
/** Transform args before JSON serialization */
|
|
91
|
+
argsToJson?: null | ((args: ArgsWithSeed<Args>) => string | SavedArgs);
|
|
92
|
+
/** Transform parsed JSON back to args */
|
|
93
|
+
jsonToArgs?: null | ((json: SavedArgs) => ArgsWithSeed<Args>);
|
|
94
|
+
/** Use saved errors to set findBestError limits instead of throwing on replay */
|
|
95
|
+
useToFindBestError?: null | boolean;
|
|
96
|
+
/** Limit per-arg indexes; boolean enables/disables, function for custom per-arg logic */
|
|
97
|
+
limitArg?: null | boolean | LimitArgOnError;
|
|
98
|
+
/** Extend template with extra args from limit if they are missing */
|
|
99
|
+
extendTemplates?: null | boolean;
|
|
100
|
+
};
|
|
101
|
+
/** Options passed to test function */
|
|
102
|
+
export type TestOptions = {
|
|
103
|
+
abortSignal: IAbortSignalFast;
|
|
104
|
+
timeController: ITimeController;
|
|
105
|
+
};
|
|
106
|
+
/** Options for finding the earliest failing variant across multiple test runs */
|
|
107
|
+
export type FindBestErrorOptions = {
|
|
108
|
+
/** Custom equality for comparing arg values when finding indexes */
|
|
109
|
+
equals?: null | Equals;
|
|
110
|
+
/** Limit per-arg indexes on error; boolean enables/disables, function for custom per-arg logic */
|
|
111
|
+
limitArgOnError?: null | boolean | LimitArgOnError;
|
|
112
|
+
/** When true, error variant is included in iteration (for debugging); default false excludes it */
|
|
113
|
+
includeErrorVariant?: null | boolean;
|
|
114
|
+
/** Return found error instead of throwing after all cycles complete */
|
|
115
|
+
dontThrowIfError?: null | boolean;
|
|
116
|
+
};
|
|
117
|
+
/** Best error found during test run */
|
|
118
|
+
export type TestVariantsBestError<Args extends Obj> = {
|
|
119
|
+
error: any;
|
|
120
|
+
args: Args;
|
|
121
|
+
/** Number of tests run before the error (including attemptsPerVariant) */
|
|
122
|
+
tests: number;
|
|
123
|
+
};
|
|
124
|
+
/** Result of test variants run */
|
|
125
|
+
export type TestVariantsResult<Args extends Obj> = {
|
|
126
|
+
iterations: number;
|
|
127
|
+
bestError: null | TestVariantsBestError<Args>;
|
|
128
|
+
};
|
|
129
|
+
/** Error event passed to onError callback */
|
|
130
|
+
export type ErrorEvent<Args extends Obj> = {
|
|
131
|
+
error: any;
|
|
132
|
+
args: Args;
|
|
133
|
+
/** Number of tests run before this error (including attemptsPerVariant) */
|
|
134
|
+
tests: number;
|
|
135
|
+
};
|
|
136
|
+
/** Callback invoked when a test variant throws an error */
|
|
137
|
+
export type OnErrorCallback<Args extends Obj> = (event: ErrorEvent<Args>) => PromiseOrValue<void>;
|
|
138
|
+
/** Mode change event passed to onModeChange callback */
|
|
139
|
+
export type ModeChangeEvent = {
|
|
140
|
+
/** Current mode configuration */
|
|
141
|
+
mode: ModeConfig;
|
|
142
|
+
/** Current mode index in iterationModes array */
|
|
143
|
+
modeIndex: number;
|
|
144
|
+
/** Number of tests run before this mode change */
|
|
145
|
+
tests: number;
|
|
146
|
+
};
|
|
147
|
+
/** Callback invoked when iteration mode changes */
|
|
148
|
+
export type OnModeChangeCallback = (event: ModeChangeEvent) => void;
|
|
149
|
+
/** Options for parallel test execution */
|
|
150
|
+
export type ParallelOptions = {
|
|
151
|
+
/** Number of parallel threads; true = unlimited, false/1 = sequential */
|
|
152
|
+
count?: null | number | boolean;
|
|
153
|
+
/** Switch to sequential mode after first error in findBestError mode */
|
|
154
|
+
sequentialOnError?: null | boolean;
|
|
155
|
+
};
|
|
156
|
+
export type TestVariantsRunOptions<Args extends Obj = Obj, SavedArgs = Args> = {
|
|
157
|
+
/** Callback invoked when a test variant throws an error */
|
|
158
|
+
onError?: null | OnErrorCallback<Args>;
|
|
159
|
+
/** Callback invoked when iteration mode changes */
|
|
160
|
+
onModeChange?: null | OnModeChangeCallback;
|
|
161
|
+
/** Wait for garbage collection after iterations */
|
|
162
|
+
GC_Iterations?: null | number;
|
|
163
|
+
/** Same as GC_Iterations but only for async test variants, required for 10000 and more of Promise rejections */
|
|
164
|
+
GC_IterationsAsync?: null | number;
|
|
165
|
+
/** Wait for garbage collection after time interval, required to prevent the karma browserDisconnectTimeout */
|
|
166
|
+
GC_Interval?: null | number;
|
|
167
|
+
/** Logging options; null/true uses defaults; false disables all; object for fine-grained control */
|
|
168
|
+
log?: null | boolean | TestVariantsLogOptions;
|
|
169
|
+
abortSignal?: null | IAbortSignalFast;
|
|
170
|
+
/** Parallel execution; true = unlimited, number = max parallel, false/1 = sequential, object = ParallelOptions */
|
|
171
|
+
parallel?: null | number | boolean | ParallelOptions;
|
|
172
|
+
/** Number of full passes through all variants; default 1 */
|
|
173
|
+
cycles?: null | number;
|
|
174
|
+
/** Generates seed for reproducible randomized testing; seed is added to args */
|
|
175
|
+
getSeed?: null | ((params: GetSeedParams) => any);
|
|
176
|
+
/** Iteration modes (variant traversal methods); each mode runs until its limits are reached */
|
|
177
|
+
iterationModes?: null | readonly ModeConfig[];
|
|
178
|
+
findBestError?: null | FindBestErrorOptions;
|
|
179
|
+
/** Save error-causing args to files and replay them before normal iteration */
|
|
180
|
+
saveErrorVariants?: null | SaveErrorVariantsOptions<Args, SavedArgs>;
|
|
181
|
+
/** Tests only first N variants, ignores the rest. If null or not specified, tests all variants */
|
|
182
|
+
limitTests?: null | number;
|
|
183
|
+
/** Maximum test run duration in milliseconds; when exceeded, iteration stops and current results are returned */
|
|
184
|
+
limitTime?: null | number;
|
|
185
|
+
/** Time controller for testable time-dependent operations; null uses timeControllerDefault */
|
|
186
|
+
timeController?: null | ITimeController;
|
|
187
|
+
};
|