@systemfsoftware/xstate-test 0.0.0-bootstrap.0 → 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.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +1821 -2
- package/dist/adapter-Dd4Go0U3.d.ts +58 -0
- package/dist/effect-schema.d.ts +28 -0
- package/dist/effect-schema.mjs +40 -0
- package/dist/finalizerError-DOptAIDs.mjs +8 -0
- package/dist/index-CSbyUxJr.d.ts +2062 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.mjs +178 -0
- package/dist/playwright.d.ts +204 -0
- package/dist/playwright.mjs +287 -0
- package/dist/propertyTest-5bO0RsUu.mjs +4660 -0
- package/dist/propertyTest-BHnBV8ax.d.ts +147 -0
- package/dist/schema.d.ts +59 -0
- package/dist/schema.mjs +822 -0
- package/dist/vitest.d.ts +74 -0
- package/dist/vitest.mjs +139 -0
- package/package.json +86 -5
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { F as PropertyGeneratorKind, V as TestAdapter } from "./index-CSbyUxJr.js";
|
|
2
|
+
import * as fc from "fast-check";
|
|
3
|
+
/** @experimental */
|
|
4
|
+
interface FastCheckGeneratorKind extends PropertyGeneratorKind {
|
|
5
|
+
readonly generator: fc.Arbitrary<this['target']>;
|
|
6
|
+
}
|
|
7
|
+
/** @experimental */
|
|
8
|
+
interface FastCheckSchedulerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Wraps every task release, for integrations that need their own batching
|
|
11
|
+
* (React's `act`, for example).
|
|
12
|
+
*/
|
|
13
|
+
readonly act?: (task: () => Promise<void>) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A replayable summary of the ordering a scheduled run took.
|
|
17
|
+
*
|
|
18
|
+
* @experimental
|
|
19
|
+
*/
|
|
20
|
+
interface FastCheckSchedulerReport {
|
|
21
|
+
/** Task ids in the order the scheduler released them. */
|
|
22
|
+
readonly ordering: readonly number[];
|
|
23
|
+
readonly tasks: readonly {
|
|
24
|
+
readonly taskId: number;
|
|
25
|
+
readonly label: string;
|
|
26
|
+
readonly schedulingType: 'promise' | 'function' | 'sequence';
|
|
27
|
+
readonly status: 'resolved' | 'rejected' | 'pending';
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
/** @experimental */
|
|
31
|
+
interface FastCheckAdapterOptions extends Omit<fc.Parameters<unknown>, 'examples'> {
|
|
32
|
+
readonly maxCommands?: number;
|
|
33
|
+
readonly replayPath?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Explores promise resolution orders with `fc.scheduler()`. Wrap the system
|
|
36
|
+
* under test with `withScheduledSut` (and a reference oracle with
|
|
37
|
+
* `withScheduledReference`) so its async boundaries are scheduled too.
|
|
38
|
+
*/
|
|
39
|
+
readonly scheduler?: boolean | FastCheckSchedulerOptions;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extracts the `replayPath` that fast-check embeds in a `fc.commands`
|
|
43
|
+
* counterexample so a failing run can be replayed deterministically.
|
|
44
|
+
*
|
|
45
|
+
* fast-check exposes no typed accessor for this: `CommandsArbitrary` builds a
|
|
46
|
+
* `CommandsIterable` whose `metadataForReplay()` returns the
|
|
47
|
+
* `replayPath="<path>"` fragment, and whose `toString()` appends that fragment
|
|
48
|
+
* inside a trailing `/* ... *\/` comment. Neither member is declared in
|
|
49
|
+
* `fast-check`'s public typings (checked against fast-check 4.9.0), so this
|
|
50
|
+
* helper is the single place that depends on that shape. It prefers
|
|
51
|
+
* `metadataForReplay()` and falls back to parsing `toString()`.
|
|
52
|
+
*
|
|
53
|
+
* @experimental
|
|
54
|
+
*/
|
|
55
|
+
declare function extractReplayPath(counterexample: unknown): string | undefined;
|
|
56
|
+
/** @experimental */
|
|
57
|
+
declare function fastCheckAdapter(options?: FastCheckAdapterOptions): TestAdapter<FastCheckGeneratorKind>;
|
|
58
|
+
export { extractReplayPath as a, FastCheckSchedulerReport as i, FastCheckGeneratorKind as n, fastCheckAdapter as o, FastCheckSchedulerOptions as r, FastCheckAdapterOptions as t };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { n as FastCheckGeneratorKind } from "./adapter-Dd4Go0U3.js";
|
|
2
|
+
import { G as TestEventGenerators } from "./index-CSbyUxJr.js";
|
|
3
|
+
import { EventsFromSchemasOptions } from "./schema.js";
|
|
4
|
+
import { AnyStateMachine, EventFrom, SnapshotFrom } from "@systemfsoftware/xstate";
|
|
5
|
+
import * as fc from "fast-check";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
/**
|
|
8
|
+
* Converts an Effect Schema into a native FastCheck arbitrary.
|
|
9
|
+
*
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
export declare function fromEffectSchema<TSchema extends Schema.Top>(schema: TSchema): fc.Arbitrary<TSchema['Type']>;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a keyed payload-schema map for use by `propertyTest()`.
|
|
15
|
+
*
|
|
16
|
+
* @experimental
|
|
17
|
+
*/
|
|
18
|
+
export declare function fromEffectSchemas<TSchemas extends Readonly<Record<string, Schema.Top>>>(schemas: TSchemas): { [TKey in keyof TSchemas]: fc.Arbitrary<TSchemas[TKey]['Type']>; };
|
|
19
|
+
/**
|
|
20
|
+
* Same as `eventsFromSchemas` from `@xstate/test`, with Effect Schema
|
|
21
|
+
* support registered.
|
|
22
|
+
*
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
export declare const eventsFromSchemas: {
|
|
26
|
+
<TMachine extends AnyStateMachine>(options?: EventsFromSchemasOptions): (machine: TMachine) => TestEventGenerators<SnapshotFrom<TMachine>, EventFrom<TMachine>, FastCheckGeneratorKind>;
|
|
27
|
+
<TMachine extends AnyStateMachine>(machine: TMachine, options?: EventsFromSchemasOptions): TestEventGenerators<SnapshotFrom<TMachine>, EventFrom<TMachine>, FastCheckGeneratorKind>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { eventsFromSchemas as eventsFromSchemas$1 } from "./schema.mjs";
|
|
2
|
+
import { dual } from "effect/Function";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as fc from "fast-check";
|
|
5
|
+
import * as Arbitrary from "effect/Arbitrary";
|
|
6
|
+
// src/effect-schema.ts
|
|
7
|
+
const effectConverter = (schema) => schema !== null && (typeof schema === "object" || typeof schema === "function") && typeof schema.ast === "object" ? fromEffectSchema(schema) : void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Converts an Effect Schema into a native FastCheck arbitrary.
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
function fromEffectSchema(schema) {
|
|
14
|
+
const arbitrary = Arbitrary.schema(schema);
|
|
15
|
+
return fc.integer().map((seed) => Effect.runSync(Arbitrary.sampleEffect(arbitrary, {
|
|
16
|
+
count: 1,
|
|
17
|
+
seed
|
|
18
|
+
}))[0]);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Converts a keyed payload-schema map for use by `propertyTest()`.
|
|
22
|
+
*
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
function fromEffectSchemas(schemas) {
|
|
26
|
+
return Object.fromEntries(Object.entries(schemas).map(([key, schema]) => [key, fromEffectSchema(schema)]));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Same as `eventsFromSchemas` from `@xstate/test`, with Effect Schema
|
|
30
|
+
* support registered.
|
|
31
|
+
*
|
|
32
|
+
* @experimental
|
|
33
|
+
*/
|
|
34
|
+
const eventsFromSchemas = dual((args) => args.length >= 2 || typeof args[0] === "object" && args[0] !== null && "transition" in args[0], function eventsFromSchemas(machine, options = {}) {
|
|
35
|
+
return eventsFromSchemas$1(machine, {
|
|
36
|
+
...options,
|
|
37
|
+
converters: [effectConverter, ...options.converters ?? []]
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
export { eventsFromSchemas, fromEffectSchema, fromEffectSchemas };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { dual } from "effect/Function";
|
|
2
|
+
import { Effect, Ref } from "effect";
|
|
3
|
+
// src/engine/finalizerError.ts
|
|
4
|
+
const ensuringFinalizerWins = dual(2, (body, finalizer) => Effect.gen(function* () {
|
|
5
|
+
const finalizerCause = yield* Ref.make(void 0);
|
|
6
|
+
return yield* Effect.ensuring(body, finalizer.pipe(Effect.tapCause((cause) => Ref.set(finalizerCause, cause)))).pipe(Effect.catchCause((bodyCause) => Effect.flatMap(Ref.get(finalizerCause), (captured) => Effect.failCause(captured ?? bodyCause))));
|
|
7
|
+
}));
|
|
8
|
+
export { ensuringFinalizerWins as t };
|