@systemfsoftware/vitest 0.1.0 → 0.3.0

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,204 @@
1
+
2
+ import { a as Values, i as PropertySubject, l as Breach, n as Gens, o as engine_d_exports, r as PropertySpec } from "./engine-ZbxyPNiN.js";
3
+ import { i as Checks, t as Asserted } from "./checks-DiuzHhQM.js";
4
+ import * as Cause from "effect/Cause";
5
+ import * as Effect$1 from "effect/Effect";
6
+ import * as Tracer from "effect/Tracer";
7
+ import { Option, Schema } from "effect";
8
+ //#region src/internal/call-site.d.ts
9
+ /** @internal */
10
+ export declare const callFrameOutside: (library: RegExp) => string | undefined;
11
+ /** @internal */
12
+ export declare const callSite: () => string | undefined;
13
+ /** @internal */
14
+ export declare const withRaisingFrame: {
15
+ <A extends Error>(error: A, frame: string | undefined): A;
16
+ (frame: string | undefined): <A extends Error>(error: A) => A;
17
+ };
18
+ //#endregion
19
+ //#region src/internal/failure-record.d.ts
20
+ /** A value the renderer narrows rather than assumes. */
21
+ type Opaque<A = unknown> = A;
22
+ /**
23
+ * A value a recorded span attribute or a replay path carries. Structured values stay structured on the span
24
+ * (KTD2); the renderer decides the text.
25
+ *
26
+ * @internal
27
+ */
28
+ type AttributeValue = string | number | boolean | null | ReadonlyArray<AttributeValue> | {
29
+ readonly [key: string]: AttributeValue;
30
+ };
31
+ /**
32
+ * The test a failure happened in, as Vitest knows it. `file` is the path the rerun command names, so a caller
33
+ * that holds an absolute path derives the repo-relative one before handing it over.
34
+ *
35
+ * @internal
36
+ */
37
+ interface TestIdentity {
38
+ /**
39
+ * The npm package the test file belongs to, e.g. `@systemfsoftware/effect-readiness`. Empty when the run
40
+ * provided no name: the rerun command then drops its `pnpm --filter` prefix and runs from the package
41
+ * directory, which is not a breach (R6).
42
+ */
43
+ readonly package: string;
44
+ /** The test file, as the rerun command writes it. */
45
+ readonly file: string;
46
+ /** The scenario name the rerun command filters on with `-t`. */
47
+ readonly name: string;
48
+ }
49
+ /**
50
+ * The value a generator chose a run by: the kernel's seed and decision path, or a property counterexample's
51
+ * seed and path. A path without a seed is a replay value offered for a baseline run, which R6 refuses (KTD5).
52
+ *
53
+ * @internal
54
+ */
55
+ interface ReplayValue {
56
+ /** The generator's seed, or `undefined` when only a path was recorded. */
57
+ readonly seed: number | undefined;
58
+ /** The decisions the generator chose, in order; a decision is the index the scheduler picked (KTD5). */
59
+ readonly path: ReadonlyArray<number>;
60
+ }
61
+ /**
62
+ * A contract rule a rendered record breaks; the runner refuses such a record (R10, KTD7).
63
+ *
64
+ * @internal
65
+ */
66
+ /**
67
+ * What a rendered failure gives Vitest: the tag the error carries, the record text, and the rules it breaks.
68
+ *
69
+ * @internal
70
+ */
71
+ interface FailureRecord {
72
+ /** The headline's failure tag, e.g. `StepError`; the runner sets it as the thrown error's `name`. */
73
+ readonly name: string;
74
+ /** The text Vitest prints as the failure's message. */
75
+ readonly record: string;
76
+ /** The contract rules the record breaks: `R1` empty headline, `R2` no location, `R6` replay or rerun. */
77
+ readonly breaches: ReadonlyArray<Breach>;
78
+ }
79
+ /**
80
+ * Everything one failure is rendered from: the failure, its run's spans, the test and the replay value.
81
+ *
82
+ * @internal
83
+ */
84
+ interface FailureRecordInput<E = never> {
85
+ /** The failure itself: a `Cause`, or the value a program threw or failed with. */
86
+ readonly failure: Cause.Cause<E> | E;
87
+ /** Every span the failing run recorded, in creation order. */
88
+ readonly spans: ReadonlyArray<Tracer.NativeSpan>;
89
+ /** The test the run belonged to. */
90
+ readonly identity: TestIdentity;
91
+ /** The generator that chose this run, or `undefined` on a run no generator chose. */
92
+ readonly replay: ReplayValue | undefined;
93
+ /**
94
+ * The seed the kernel's scheduler chose. The kernel knows its own scheduler, so it hands the note over rather
95
+ * than the renderer guessing it; a run no scheduler chose renders no note (KTD5).
96
+ */
97
+ readonly schedule?: {
98
+ readonly seed: number;
99
+ } | undefined;
100
+ /**
101
+ * The workspace root the rendered paths are relativized against, provided by the shared config the same way the
102
+ * package name is. Omitted, paths print absolute.
103
+ */
104
+ readonly root?: string | undefined;
105
+ }
106
+ /** @internal */
107
+ export declare const summaryOf: (value: Opaque) => string;
108
+ /**
109
+ * Renders the record Vitest prints for one spec failure, and the contract rules it breaks.
110
+ *
111
+ * Never throws: a `Cause` renders layer by layer, a thrown `Error` renders as one layer, and any other value
112
+ * renders as itself. The first location the record names is the raising frame — the first stack frame outside
113
+ * `node_modules` and outside the spec libraries' own `src/` and `dist/` — and when no layer has one, the
114
+ * innermost failed span's site stands in, or the innermost unfinished cell's decide site for a deadlock (KTD6).
115
+ *
116
+ * @internal
117
+ */
118
+ export declare const renderFailureRecord: <E>(input: FailureRecordInput<E>) => FailureRecord;
119
+ /** @internal */
120
+ export declare const throwFailureRecord: <E>(input: FailureRecordInput<E>) => never;
121
+ interface TaskLike {
122
+ readonly name?: string | undefined;
123
+ readonly fullName?: string | undefined;
124
+ readonly fullTestName?: string | undefined;
125
+ }
126
+ /** @internal */
127
+ export declare const testIdentityOf: (task?: TaskLike | null) => TestIdentity;
128
+ //#endregion
129
+ //#region src/internal/provided.schema.d.ts
130
+ /**
131
+ * The workspace root every rendered path is relativized against.
132
+ *
133
+ * @internal
134
+ */
135
+ declare const WorkspaceRoot: Schema.brand<Schema.NonEmptyString, "WorkspaceRoot">;
136
+ /** @internal */
137
+ type WorkspaceRoot = typeof WorkspaceRoot.Type;
138
+ //#endregion
139
+ //#region src/internal/provided.d.ts
140
+ /** @internal */
141
+ declare const providedRoot: () => WorkspaceRoot | undefined;
142
+ //#endregion
143
+ //#region src/internal/recorded-run.d.ts
144
+ /** @internal */
145
+ interface RecordedRun<A, E> {
146
+ (checks: Checks): Effect$1.Effect<A, E, Asserted>;
147
+ }
148
+ /** @internal */
149
+ interface RecordedProperty<G extends Gens, S extends PropertySubject, N extends number> {
150
+ readonly name: string;
151
+ readonly spec: PropertySpec<G, S, N>;
152
+ readonly holds: (subject: S, values: Values<G>) => boolean;
153
+ }
154
+ /**
155
+ * Runs one program as the runner runs a lane, with a fresh ledger and its own recorder, and resolves with the
156
+ * record its failure rendered — or `undefined` when it passed.
157
+ *
158
+ * @internal
159
+ */
160
+ export declare const recordOfRun: <A, E>(program: RecordedRun<A, E>) => Promise<FailureRecord | undefined>;
161
+ /**
162
+ * Runs one property the way the runner runs `it.prop`, with a fresh ledger and its own recorder, and resolves with
163
+ * the record its falsification rendered — or `undefined` when it held.
164
+ *
165
+ * @internal
166
+ */
167
+ export declare const recordOfProperty: <const G extends Gens, S extends PropertySubject, N extends number>(input: RecordedProperty<G, S, N>) => Promise<FailureRecord | undefined>;
168
+ //#endregion
169
+ //#region src/internal/span-recorder.d.ts
170
+ /** @internal */
171
+ interface SpanRecorder {
172
+ readonly tracer: Tracer.Tracer;
173
+ readonly spans: ReadonlyArray<Tracer.NativeSpan>;
174
+ }
175
+ /** @internal */
176
+ export declare const createSpanRecorder: () => SpanRecorder;
177
+ //#endregion
178
+ //#region src/replay.schema.d.ts
179
+ /** The replay a generator chose: its seed and the decisions it took, in order (R6). */
180
+ export declare const Replay: Schema.Struct<{
181
+ readonly seed: Schema.brand<Schema.Int, "ReplaySeed">;
182
+ readonly path: Schema.$Array<Schema.brand<Schema.Int, "ReplayStep">>;
183
+ }>;
184
+ /** @since 4.0.0 */
185
+ export type Replay = typeof Replay.Type;
186
+ /**
187
+ * The `CONFORMANCE_REPLAY` text as the replay it names. A text a seed and a path cannot be read out of is refused
188
+ * with the same prose the spec runtime has always thrown, so the grammar and its refusal share one home.
189
+ *
190
+ * @since 4.0.0
191
+ */
192
+ export declare const replayOfText: (text: string) => Replay;
193
+ /**
194
+ * The replay codec: `Schema.String` in, a replay out. A text that names no seed and path fails the decode, and
195
+ * every replay encodes back to the text it was read from.
196
+ *
197
+ * @since 4.0.0
198
+ */
199
+ export declare const ReplayFromText: Schema.decodeTo<Schema.Struct<{
200
+ readonly seed: Schema.brand<Schema.Int, "ReplaySeed">;
201
+ readonly path: Schema.$Array<Schema.brand<Schema.Int, "ReplayStep">>;
202
+ }>, Schema.String, never, never>;
203
+ //#endregion
204
+ export { type AttributeValue, type Breach, type FailureRecord, type FailureRecordInput, type RecordedProperty, type RecordedRun, type ReplayValue, type SpanRecorder, type TestIdentity, providedRoot as providedWorkspaceRoot };
@@ -0,0 +1,4 @@
1
+
2
+ import { _ as ReplayFromText, c as summaryOf, d as providedRoot, g as Replay, l as testIdentityOf, n as recordOfRun, r as createSpanRecorder, s as renderFailureRecord, t as recordOfProperty, u as throwFailureRecord, v as replayOfText } from "./failure-DC_SJoxW.mjs";
3
+ import { c as callFrameOutside, l as callSite, p as withRaisingFrame } from "./test-context-D_-acRSc.mjs";
4
+ export { Replay, ReplayFromText, callFrameOutside, callSite, createSpanRecorder, providedRoot as providedWorkspaceRoot, recordOfProperty, recordOfRun, renderFailureRecord, replayOfText, summaryOf, testIdentityOf, throwFailureRecord, withRaisingFrame };
package/dist/index.d.ts CHANGED
@@ -1,176 +1,23 @@
1
1
  /// <reference types="./compat.d.ts" />
2
+ import { a as Values$1, c as kinds_d_exports, i as PropertySubject$1, n as Gens$1, o as engine_d_exports, r as PropertySpec$1, s as LawApi, t as ArbitraryInput, u as __exportAll } from "./engine-ZbxyPNiN.js";
2
3
  import { a as Expect, c as NoCheckRefusal, d as RefuseSyncBody, f as ScopedLaneRefusal, i as Checks, l as RefuseAsyncBody, m as UnprovidedRefusal, o as EffectLaneRefusal, p as ScopedLiveLaneRefusal, r as Check, s as HookRefusal, t as Asserted, u as RefuseEffectBody } from "./checks-DiuzHhQM.js";
3
4
  import * as V from "vitest";
4
5
  import { afterAll, assertType, beforeAll, expectTypeOf, inject, onTestFailed, onTestFinished, recordArtifact, vi, vitest } from "vitest";
5
- import * as Cause from "effect/Cause";
6
6
  import * as Duration from "effect/Duration";
7
7
  import * as Effect from "effect/Effect";
8
8
  import * as Layer from "effect/Layer";
9
- import * as Schema$1 from "effect/Schema";
10
9
  import * as Scope from "effect/Scope";
11
10
  import * as TestConsole from "effect/testing/TestConsole";
12
11
  import * as Context from "effect/Context";
13
- import { Schema } from "effect";
14
12
  import * as Arbitrary from "effect/unstable/arbitrary/Arbitrary";
15
13
  import * as Clock from "effect/Clock";
16
14
  import * as Scheduler from "effect/Scheduler";
17
- //#endregion
18
15
  //#region src/internal/property/defaults.d.ts
19
16
  /** @internal The `test.provide` key the shared config fills with this run's tier's check options. */
20
17
  declare const checkDefaultsKey = "@systemfsoftware/vitest:property-check";
21
18
  /** @internal The check options a run supplies as its property default, minus `replay`. */
22
19
  type ProvidedCheckDefaults = Omit<Arbitrary.CheckOptions, 'replay'>;
23
20
  //#endregion
24
- //#region src/internal/errors.schema.d.ts
25
- declare const NonBooleanVerdict_base: Schema.Class<NonBooleanVerdict, Schema.TaggedStruct<"NonBooleanVerdict", {
26
- readonly detail: Schema.String;
27
- }>, import("effect/Cause").YieldableError>;
28
- /** @internal */
29
- declare class NonBooleanVerdict extends NonBooleanVerdict_base {
30
- get message(): string;
31
- }
32
- //#endregion
33
- //#region src/internal/property/impostor.d.ts
34
- /**
35
- * @internal The constant impostor of R12: a fake of the subject under test that
36
- * returns the first output it ever produced, for every later call, whatever the
37
- * input it was given.
38
- *
39
- * A property that still holds for the impostor does not constrain the subject.
40
- * Whether that is fatal is a per-file question — a subject's impostor must be
41
- * refuted by some property in its file — so this module builds the fake and
42
- * collects the verdicts; the engine decides them once, when the file finishes
43
- * (KTD10).
44
- */
45
- /**
46
- * A value the fork hands over without inspecting: an argument to the subject, or one of its outputs.
47
- *
48
- * @internal
49
- */
50
- type Opaque<A = unknown> = A;
51
- /**
52
- * A function under test: any argument, any output.
53
- *
54
- * @internal
55
- */
56
- type SubjectFunction = (...values: ReadonlyArray<never>) => Opaque;
57
- /**
58
- * A record of functions under test; every member is replaced by a constant.
59
- *
60
- * @internal
61
- */
62
- type MemberRecord = {
63
- readonly [key: string]: SubjectFunction;
64
- };
65
- /**
66
- * The function under test, or a record of them.
67
- *
68
- * @internal
69
- */
70
- type Subject = SubjectFunction | MemberRecord;
71
- declare namespace kinds_d_exports {
72
- export { LawApi, LawKind, LawSubject, MetamorphicRelation, deterministicHolds, idempotentHolds, invariantHolds, metamorphicHolds, modelHolds, roundTripHolds, spreadValues };
73
- }
74
- /** @internal */
75
- type LawKind = 'model' | 'metamorphic' | 'roundTrip' | 'invariant' | 'idempotent' | 'deterministic';
76
- /**
77
- * A subject of a law kind: a function of the generated values.
78
- *
79
- * @internal
80
- */
81
- type LawSubject<G extends Gens$1, A> = (...values: ReadonlyArray<ElementValues<G>>) => A;
82
- /**
83
- * A metamorphic relation: the input transform, and how the two outputs relate (structural equality by default).
84
- *
85
- * @internal
86
- */
87
- interface MetamorphicRelation<G extends Gens$1, A> {
88
- readonly transform: (...values: ReadonlyArray<ElementValues<G>>) => Values$1<G>;
89
- readonly relate?: (original: A, transformed: A) => boolean;
90
- }
91
- /**
92
- * The R13 law surface: four gated kinds and two declared exemptions.
93
- *
94
- * @internal
95
- */
96
- interface LawApi {
97
- readonly model: <const G extends Gens$1, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec$1<G, S, N>, oracle: LawSubject<G, A>) => void;
98
- readonly metamorphic: <const G extends Gens$1, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec$1<G, S, N>, relation: MetamorphicRelation<G, A>) => void;
99
- readonly roundTrip: <const G extends Gens$1, E, N extends number, S extends LawSubject<G, E>>(name: string, spec: PropertySpec$1<G, S, N>, decode: (encoded: E) => Values$1<G>) => void;
100
- readonly invariant: <const G extends Gens$1, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec$1<G, S, N>, holds: (output: A, ...values: ReadonlyArray<ElementValues<G>>) => boolean) => void;
101
- readonly idempotent: <const G extends Gens$1, N extends number, S extends (value: ElementValues<G>) => ElementValues<G>>(name: string, spec: PropertySpec$1<G, S, N>) => void;
102
- readonly deterministic: <const G extends Gens$1, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec$1<G, S, N>) => void;
103
- }
104
- /**
105
- * The generated values as the argument list a law subject is called with.
106
- *
107
- * @internal
108
- */
109
- declare const spreadValues: <G extends Gens$1>(values: Values$1<G>) => ReadonlyArray<ElementValues<G>>;
110
- /** @internal */
111
- declare const modelHolds: <G extends Gens$1, A>(oracle: LawSubject<G, A>) => (subject: LawSubject<G, A>, values: Values$1<G>) => boolean;
112
- /** @internal */
113
- declare const metamorphicHolds: <G extends Gens$1, A>(relation: MetamorphicRelation<G, A>) => (subject: LawSubject<G, A>, values: Values$1<G>) => boolean;
114
- /** @internal */
115
- declare const roundTripHolds: <G extends Gens$1, E>(decode: (encoded: E) => Values$1<G>) => (subject: LawSubject<G, E>, values: Values$1<G>) => boolean;
116
- /** @internal */
117
- declare const invariantHolds: <G extends Gens$1, A>(holds: (output: A, ...values: ReadonlyArray<ElementValues<G>>) => boolean) => (subject: LawSubject<G, A>, values: Values$1<G>) => boolean;
118
- /** @internal */
119
- declare const idempotentHolds: <G extends Gens$1>() => (subject: (value: ElementValues<G>) => ElementValues<G>, values: Values$1<G>) => boolean;
120
- /** @internal */
121
- declare const deterministicHolds: <G extends Gens$1, A>() => (subject: LawSubject<G, A>, values: Values$1<G>) => boolean;
122
- declare namespace engine_d_exports {
123
- export { ArbitraryInput, CoveragePredicate, ElementValues, Gens$1 as Gens, PropApi, PropertyRuntime, PropertySpec$1 as PropertySpec, PropertySubject$1 as PropertySubject, Values$1 as Values, makeProperty };
124
- }
125
- /** @internal */
126
- type ArbitraryInput = Schema$1.Top | Arbitrary.Arbitrary<Schema$1.Top['Type']>;
127
- /** @internal */
128
- type Gens$1 = ReadonlyArray<ArbitraryInput> | {
129
- readonly [key: string]: ArbitraryInput;
130
- };
131
- type Generated<I> = I extends Schema$1.Schema<infer T> ? T : I extends Arbitrary.Arbitrary<infer A> ? A : never;
132
- /** @internal */
133
- type Values$1<G extends Gens$1> = { readonly [K in keyof G]: Generated<G[K]>; };
134
- /** @internal */
135
- type ElementValues<G extends Gens$1> = G extends ReadonlyArray<ArbitraryInput> ? Generated<G[number]> : never;
136
- /** @internal */
137
- type PropertySubject$1 = Subject;
138
- /** @internal */
139
- type CoveragePredicate<G extends Gens$1> = (...values: ReadonlyArray<ElementValues<G>>) => boolean;
140
- type PropertyRuns<N extends number> = number extends N ? number : `${N}` extends `-${bigint}` ? never : `${N}` extends `${bigint}` ? (N extends 0 ? never : N) : never;
141
- /** @internal */
142
- interface PropertySpec$1<G extends Gens$1, S extends PropertySubject$1, N extends number> {
143
- readonly of: G;
144
- readonly subject: S;
145
- /**
146
- * The property's own run count. Omitted, the configured default applies; when the run provides none,
147
- * the built-in default of 100 does.
148
- */
149
- readonly runs?: N & PropertyRuns<N>;
150
- /** Labelled input predicates, each with the minimum share of runs it must see (R14). */
151
- readonly cover?: Readonly<Record<string, readonly [CoveragePredicate<G>, number]>>;
152
- /** The property's own check options, merged field by field over the provided and built-in defaults. */
153
- readonly arbitrary?: Arbitrary.CheckOptions;
154
- }
155
- /** @internal */
156
- interface PropertyRuntime<R> {
157
- /** Registers the property's program; the runtime runs it inside the test it registers, under that test's binding. */
158
- readonly register: (name: string, program: () => Effect.Effect<void, Cause.Cause<NonBooleanVerdict>, never>) => void;
159
- readonly provide: <A, E>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, never>;
160
- }
161
- /** @internal */
162
- interface PropApi<R> {
163
- readonly prop: <const G extends Gens$1, S extends PropertySubject$1, N extends number>(name: string, spec: PropertySpec$1<G, S, N>, holds: (subject: S, values: Values$1<G>) => boolean) => void;
164
- readonly effectProp: <const G extends Gens$1, S extends PropertySubject$1, N extends number, E>(name: string, spec: PropertySpec$1<G, S, N>, holds: (subject: S, values: Values$1<G>) => Effect.Effect<boolean, E, R>) => void;
165
- readonly law: LawApi;
166
- }
167
- /**
168
- * The property surface over one runtime: `prop`, `effectProp`, and the R13 law kinds routed through the gate.
169
- *
170
- * @internal
171
- */
172
- declare const makeProperty: <R>(runtime: PropertyRuntime<R>) => PropApi<R>;
173
- //#endregion
174
21
  //#region src/internal/virtual-time.d.ts
175
22
  /** @internal */
176
23
  interface VirtualRuntime {
@@ -290,6 +137,8 @@ declare namespace mod_d_exports {
290
137
  declare module 'vitest' {
291
138
  interface ProvidedContext {
292
139
  [checkDefaultsKey]?: ProvidedCheckDefaults;
140
+ '@systemfsoftware/vitest:package'?: string;
141
+ '@systemfsoftware/vitest:workspace-root'?: string;
293
142
  }
294
143
  }
295
144
  /**