@systemfsoftware/xstate-test 0.0.0-stage → 2.0.0-beta.2

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.
@@ -0,0 +1,147 @@
1
+ import { n as FastCheckGeneratorKind, t as FastCheckAdapterOptions } from "./adapter-Dd4Go0U3.js";
2
+ import { G as TestEventGenerators, J as TestFailureStore, R as PropertyTestOptions, V as TestAdapter, _t as TestCoverage, a as GenerateTestSuiteOptions, gt as SnapshotFromSource, ht as InputFromSource, mt as EventFromSource, n as TestPathsOptions, r as TestPathsResult, s as TestSuite } from "./index-CSbyUxJr.js";
3
+ import { ActorLogic, EventObject, Snapshot } from "@systemfsoftware/xstate";
4
+ /**
5
+ * Options for the file-system failure database. See `failures`.
6
+ *
7
+ * @experimental
8
+ */
9
+ interface FailureDatabaseOptions {
10
+ /** The directory failures are saved in. Defaults to `'.xstate-test'`. */
11
+ readonly dir?: string;
12
+ /**
13
+ * `'first'` (the default) replays saved failures before the campaign and
14
+ * fails on the first one that still reproduces. `'only'` replays them and
15
+ * skips the campaign. `false` saves failures without replaying them.
16
+ */
17
+ readonly replay?: 'first' | 'only' | false;
18
+ /**
19
+ * The subdirectory of `dir` the failures of this test are saved in.
20
+ * Defaults to the machine id plus a hash of the configured event cases and
21
+ * oracles. Set it when two tests run the same machine with different
22
+ * oracles, so each replays only its own failures.
23
+ */
24
+ readonly key?: string;
25
+ }
26
+ /**
27
+ * The accepted values of the `failures` option.
28
+ *
29
+ * @experimental
30
+ */
31
+ type FailuresOption = boolean | FailureDatabaseOptions | TestFailureStore;
32
+ /**
33
+ * A {@link TestFailureStore} that saves each failing fixture as
34
+ * `<dir>/<key>/<hash>.json`. Node's `fs` is loaded only when a campaign reads
35
+ * or writes a failure, so importing `@xstate/test` stays free of Node APIs.
36
+ *
37
+ * @experimental
38
+ */
39
+ declare function createFailureDatabase(options?: FailureDatabaseOptions): TestFailureStore;
40
+ /** The options the wrappers add to, or reshape from, `xstate/graph`. */
41
+ interface DeriveEventsOptions {
42
+ /**
43
+ * Saves the fixture of a failing campaign to disk, and replays saved
44
+ * fixtures before the next campaign. `true` uses the defaults: the
45
+ * `.xstate-test` directory and `replay: 'first'`. A `TestFailureStore`
46
+ * object is used as-is.
47
+ */
48
+ readonly failures?: FailuresOption;
49
+ /**
50
+ * Derives a generator, via `eventsFromSchemas()`, for every event type the
51
+ * machine declares in `schemas.events` and that `events` does not already
52
+ * configure. Defaults to `true`; machines that declare no `schemas.events`
53
+ * are unaffected either way.
54
+ *
55
+ * Only declared runtime schemas are derived from. An event type the machine
56
+ * handles but declares no schema for is left out rather than generated as
57
+ * `{}`, and a type-only `types<...>()` declaration is skipped because it
58
+ * carries no runtime structure. A runtime schema the converters do not
59
+ * recognize throws, unless `events` already covers that event type.
60
+ */
61
+ readonly deriveEvents?: boolean;
62
+ }
63
+ /**
64
+ * `PropertyTestOptions` with the generator kind fixed to fast-check:
65
+ * `events`, `commands` and `outcomes` take `fc.Arbitrary` values, and every
66
+ * fast-check option is accepted at the top level.
67
+ *
68
+ * @experimental
69
+ */
70
+ type FastCheckPropertyTestOptions<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput> = Omit<PropertyTestOptions<TSnapshot, TEvent, TInput, FastCheckGeneratorKind>, 'adapter' | 'events' | 'failures'> & FastCheckAdapterOptions & DeriveEventsOptions & {
71
+ /**
72
+ * Overrides the implicit fast-check adapter. Any generator kind is
73
+ * accepted here, so a non-fast-check adapter can be dropped in; `events`
74
+ * and `commands` are still typed against fast-check, so such an adapter
75
+ * usually wants `propertyTest()` from `xstate/graph` instead.
76
+ */
77
+ readonly adapter?: TestAdapter<any>;
78
+ /**
79
+ * Optional when the machine declares `schemas.events`; the generators are
80
+ * derived from those schemas, and entries here override the derived ones.
81
+ */
82
+ readonly events?: TestEventGenerators<TSnapshot, TEvent, FastCheckGeneratorKind>;
83
+ };
84
+ /** @experimental */
85
+ type FastCheckGenerateTestSuiteOptions<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput> = FastCheckPropertyTestOptions<TSnapshot, TEvent, TInput> & Omit<GenerateTestSuiteOptions<TSnapshot, TEvent, TInput, FastCheckGeneratorKind>, keyof PropertyTestOptions<TSnapshot, TEvent, TInput, FastCheckGeneratorKind>>;
86
+ /**
87
+ * Runs a property-testing campaign with fast-check as the generator.
88
+ *
89
+ * Identical to `propertyTest()` from `xstate/graph`, except that fast-check
90
+ * options (`seed`, `numRuns`, `maxCommands`, `scheduler`, …) are top-level
91
+ * options rather than `fastCheckAdapter()` arguments, and `events` is derived
92
+ * from the machine's `schemas.events` when it declares them.
93
+ *
94
+ * @experimental
95
+ */
96
+ declare const propertyTest: {
97
+ <TSource extends ActorLogic<any, any, any>>(options: FastCheckPropertyTestOptions<SnapshotFromSource<TSource>, EventFromSource<TSource>, InputFromSource<TSource>>): (source: TSource) => Promise<{
98
+ coverage: TestCoverage;
99
+ }>;
100
+ <TSource extends ActorLogic<any, any, any>>(source: TSource, options: FastCheckPropertyTestOptions<SnapshotFromSource<TSource>, EventFromSource<TSource>, InputFromSource<TSource>>): Promise<{
101
+ coverage: TestCoverage;
102
+ }>;
103
+ };
104
+ /**
105
+ * Records an offline property suite from a passing campaign, with fast-check
106
+ * as the generator. See `generateTestSuite()` in `xstate/graph`.
107
+ *
108
+ * @experimental
109
+ */
110
+ declare const generateTestSuite: {
111
+ <TSource extends ActorLogic<any, any, any>>(options: FastCheckGenerateTestSuiteOptions<SnapshotFromSource<TSource>, EventFromSource<TSource>, InputFromSource<TSource>>): (source: TSource) => Promise<TestSuite>;
112
+ <TSource extends ActorLogic<any, any, any>>(source: TSource, options: FastCheckGenerateTestSuiteOptions<SnapshotFromSource<TSource>, EventFromSource<TSource>, InputFromSource<TSource>>): Promise<TestSuite>;
113
+ };
114
+ /**
115
+ * `TestPathsOptions` with the generator kind fixed to fast-check:
116
+ * `events` takes `fc.Arbitrary` values, which are sampled into concrete
117
+ * payloads before traversal.
118
+ *
119
+ * @experimental
120
+ */
121
+ type FastCheckTestPathsOptions<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput> = Omit<TestPathsOptions<TSnapshot, TEvent, TInput>, 'events' | 'outcomes' | 'failures'> & DeriveEventsOptions & {
122
+ readonly events?: TestEventGenerators<TSnapshot, TEvent, FastCheckGeneratorKind>;
123
+ /**
124
+ * Invoke sources whose outcomes are sampled from fast-check arbitraries
125
+ * and routed through the `xstate.done.actor` / `xstate.error.actor` steps
126
+ * traversal took. In pure mode the sampled `output` or `error` is the
127
+ * payload of that step's event; in executed mode the source is stubbed
128
+ * and the stub resolves with it.
129
+ */
130
+ readonly outcomes?: TestPathsOptions<TSnapshot, TEvent, TInput, FastCheckGeneratorKind>['outcomes'];
131
+ };
132
+ /**
133
+ * Executes model paths against a system under test.
134
+ *
135
+ * The same options as `propertyTest()`, minus the generation controls
136
+ * (`numRuns`, `maxCommands`, `swarm`, `frontiers`, …) and plus the traversal
137
+ * controls (`pathGenerator`, `limit`, `toState`, `samples`, `seed`). fast-check
138
+ * arbitraries are accepted in `events` and sampled into `samples` concrete
139
+ * payloads before traversal.
140
+ *
141
+ * @experimental
142
+ */
143
+ declare const testPaths: {
144
+ <TSource extends ActorLogic<any, any, any>>(options?: FastCheckTestPathsOptions<SnapshotFromSource<TSource>, EventFromSource<TSource>, InputFromSource<TSource>>): (source: TSource) => Promise<TestPathsResult<SnapshotFromSource<TSource>, EventFromSource<TSource>>>;
145
+ <TSource extends ActorLogic<any, any, any>>(source: TSource, options?: FastCheckTestPathsOptions<SnapshotFromSource<TSource>, EventFromSource<TSource>, InputFromSource<TSource>>): Promise<TestPathsResult<SnapshotFromSource<TSource>, EventFromSource<TSource>>>;
146
+ };
147
+ export { propertyTest as a, FailuresOption as c, generateTestSuite as i, createFailureDatabase as l, FastCheckPropertyTestOptions as n, testPaths as o, FastCheckTestPathsOptions as r, FailureDatabaseOptions as s, FastCheckGenerateTestSuiteOptions as t };
@@ -0,0 +1,59 @@
1
+ import { n as FastCheckGeneratorKind } from "./adapter-Dd4Go0U3.js";
2
+ import { G as TestEventGenerators } from "./index-CSbyUxJr.js";
3
+ import { AnyStateMachine, EventFrom, SnapshotFrom } from "@systemfsoftware/xstate";
4
+ import * as fc from "fast-check";
5
+ /**
6
+ * Converts a single payload schema into a FastCheck arbitrary. Returns
7
+ * `undefined` when the converter does not recognize the schema.
8
+ *
9
+ * @experimental
10
+ */
11
+ export type SchemaConverter = (schema: unknown, path: string) => fc.Arbitrary<unknown> | undefined;
12
+ /** @experimental */
13
+ export interface EventsFromSchemasOptions {
14
+ /**
15
+ * What to do with event types that the machine handles but that have no
16
+ * declared schema, under either their own key or a matching wildcard key
17
+ * (`'user.*'`).
18
+ *
19
+ * - `'empty'` (default) generates `{}` for them.
20
+ * - `'skip'` leaves them out of the returned map.
21
+ */
22
+ readonly eventsWithoutSchema?: 'empty' | 'skip';
23
+ /**
24
+ * Converts schemas that are not recognized by the built-in converters.
25
+ * Return `undefined` to fall through to the built-in error.
26
+ */
27
+ readonly fallback?: SchemaConverter;
28
+ }
29
+ /**
30
+ * Converts a declared payload schema into a FastCheck arbitrary. Only schema
31
+ * libraries whose structure can be inspected are supported; a Standard Schema
32
+ * alone only validates, so nothing can be generated from it.
33
+ *
34
+ * @experimental
35
+ */
36
+ export declare function arbitraryFromSchema(schema: unknown, options?: EventsFromSchemasOptions, path?: string): fc.Arbitrary<unknown>;
37
+ /**
38
+ * Derives event generators from the event schemas declared on a machine
39
+ * (`setup({ schemas: { events } })` or `createMachine({ schemas: { events } })`).
40
+ *
41
+ * Type-only event declarations (`types.events`) are erased at runtime and
42
+ * cannot be used here.
43
+ *
44
+ * @experimental
45
+ */
46
+ export declare const eventsFromSchemas: {
47
+ <TMachine extends AnyStateMachine>(options?: EventsFromSchemasOptions): (machine: TMachine) => TestEventGenerators<SnapshotFrom<TMachine>, EventFrom<TMachine>, FastCheckGeneratorKind>;
48
+ <TMachine extends AnyStateMachine>(machine: TMachine, options?: EventsFromSchemasOptions): TestEventGenerators<SnapshotFrom<TMachine>, EventFrom<TMachine>, FastCheckGeneratorKind>;
49
+ };
50
+ /**
51
+ * Merges derived generators with explicit ones. Explicit entries win for event
52
+ * types declared in both.
53
+ *
54
+ * @experimental
55
+ */
56
+ export declare const mergeEventGenerators: {
57
+ <TDerived, TExplicit>(explicit: TExplicit): (derived: TDerived) => TDerived & TExplicit;
58
+ <TDerived, TExplicit>(derived: TDerived, explicit: TExplicit): TDerived & TExplicit;
59
+ };