@systemfsoftware/vitest 0.1.0 → 0.2.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.
- package/CHANGELOG.md +18 -0
- package/dist/{checks-DiuzHhQM.d.ts → checks-Cq9of-Lx.d.ts} +105 -1
- package/dist/engine-YsoQ_9we.d.ts +158 -0
- package/dist/failure-BquJJPFZ.mjs +1217 -0
- package/dist/failure.d.ts +80 -0
- package/dist/failure.mjs +4 -0
- package/dist/{guard-BocOhXt2.mjs → guard-p_8ARgPm.mjs} +15 -11
- package/dist/guard.mjs +1 -1
- package/dist/index.d.ts +4 -155
- package/dist/index.mjs +46 -516
- package/dist/integration.d.ts +1 -1
- package/dist/integration.mjs +1 -1
- package/dist/{test-context-hvSoKLtw.mjs → test-context-ChvjVyCo.mjs} +128 -6
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @systemfsoftware/vitest
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Tests take `expect` from the test callback and yield each check: `it(name, function* ({ expect }) { yield* expect(actual).toEqual(expected) })`. The package stops exporting `expect`, `assert` and the `utils` helpers. With its `guard` entry listed in `setupFiles`, an `expect` imported from Vitest, or a test registered through Vitest's own `it`, is refused. Also refused, each with its rewrite as the message: a second check on one observed state, an unyielded check, a body with no check, a non-generator body, `it.effect`/`it.scoped`/`it.scopedLive`, `beforeEach`/`afterEach`, and weak matchers such as `toHaveLength`, `toBeDefined`, snapshots, `expect.anything`, `expect.soft`/`expect.poll` and argument-less `toThrow`. Libraries that judge inside a test import `step`, `captureRunBinding` and the `Check`/`Expect`/`Asserted` types from the `integration` entry.
|
|
8
|
+
|
|
9
|
+
- `@systemfsoftware/differential-spec` depends on and imports `@systemfsoftware/vitest` by its own name instead of through an `@effect/vitest` alias. `@systemfsoftware/oxlint-config-recommended` enables the test-discipline rule under its new id `vitest-from-systemfsoftware-vitest`. `@systemfsoftware/vitest` documentation examples import from `@systemfsoftware/vitest`.
|
|
10
|
+
|
|
11
|
+
The lawful runner is published under its own name, `@systemfsoftware/vitest`, starting at `0.1.0`, so peers declared as `^0.1.0` accept its patch releases.
|
|
12
|
+
|
|
13
|
+
- A failing test now reports one failure record instead of a raw cause: the error with its message, the first source line outside the spec libraries, the steps that ran and the cell decisions each caused, and a rerun command for that one scenario. Every cause in the chain keeps all lines of its message. A replay value is printed only for a run a seed or a property chose. Each failure prints once; other errors in the same cause are logged. A failed `expect` points at the line that called it and a property failure at the line that declared it. A new `@systemfsoftware/vitest/failure` entry exports the renderer, the recorder, the cause summary (`summaryOf`) and the author call-site capture (`callSite`, `callFrameOutside`, `withRaisingFrame`) for libraries that raise their own failures.
|
|
14
|
+
|
|
15
|
+
- Kernel runs are serialized. A run started while another is live now waits behind it, in arrival order, instead of failing: two runs never interleave, so a scenario never sees another run's decisions, and a suite whose cases drive the kernel can run its tests concurrently.
|
|
16
|
+
|
|
17
|
+
`@systemfsoftware/vitest` adds `captureRunBinding`, the running test's run binding. `bind(effect)` re-provides it to an effect a library runs on a runtime of its own — its own scheduler, a worker, a simulation kernel — so the checks inside it count as that test's assertions, report softly, and see the same `owned` regions.
|
|
18
|
+
|
|
19
|
+
`@systemfsoftware/effect-spec-runtime` runs a case that declares no live reason through that runner, and a case's annotations now reach the test's report.
|
|
20
|
+
|
|
3
21
|
## 0.1.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -1,7 +1,111 @@
|
|
|
1
1
|
|
|
2
2
|
import * as V from "vitest";
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Tracer from "effect/Tracer";
|
|
4
6
|
import * as Context from "effect/Context";
|
|
7
|
+
//#region src/internal/failure-record.d.ts
|
|
8
|
+
/** A value the renderer narrows rather than assumes. */
|
|
9
|
+
type Opaque$1<A = unknown> = A;
|
|
10
|
+
/**
|
|
11
|
+
* A value a recorded span attribute or a replay path carries. Structured values stay structured on the span
|
|
12
|
+
* (KTD2); the renderer decides the text.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
type AttributeValue = string | number | boolean | null | ReadonlyArray<AttributeValue> | {
|
|
17
|
+
readonly [key: string]: AttributeValue;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The test a failure happened in, as Vitest knows it. `file` is the path the rerun command names, so a caller
|
|
21
|
+
* that holds an absolute path derives the repo-relative one before handing it over.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
interface TestIdentity {
|
|
26
|
+
/**
|
|
27
|
+
* The npm package the test file belongs to, e.g. `@systemfsoftware/effect-readiness`. Empty when the run
|
|
28
|
+
* provided no name: the rerun command then drops its `pnpm --filter` prefix and runs from the package
|
|
29
|
+
* directory, which is not a breach (R6).
|
|
30
|
+
*/
|
|
31
|
+
readonly package: string;
|
|
32
|
+
/** The test file, as the rerun command writes it. */
|
|
33
|
+
readonly file: string;
|
|
34
|
+
/** The scenario name the rerun command filters on with `-t`. */
|
|
35
|
+
readonly name: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The value a generator chose a run by: the kernel's seed and decision path, or a property counterexample's
|
|
39
|
+
* seed and path. A path without a seed is a replay value offered for a baseline run, which R6 refuses (KTD5).
|
|
40
|
+
*
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
interface ReplayValue {
|
|
44
|
+
/** The generator's seed, or `undefined` when only a path was recorded. */
|
|
45
|
+
readonly seed: number | undefined;
|
|
46
|
+
/** The decisions or inputs the generator chose, in order. */
|
|
47
|
+
readonly path: ReadonlyArray<AttributeValue>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A contract rule a rendered record breaks; the runner refuses such a record (R10, KTD7).
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
type Breach = 'R1' | 'R2' | 'R6';
|
|
55
|
+
/**
|
|
56
|
+
* What a rendered failure gives Vitest: the tag the error carries, the record text, and the rules it breaks.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
interface FailureRecord {
|
|
61
|
+
/** The headline's failure tag, e.g. `StepError`; the runner sets it as the thrown error's `name`. */
|
|
62
|
+
readonly name: string;
|
|
63
|
+
/** The text Vitest prints as the failure's message. */
|
|
64
|
+
readonly record: string;
|
|
65
|
+
/** The contract rules the record breaks: `R1` empty headline, `R2` no location, `R6` replay or rerun. */
|
|
66
|
+
readonly breaches: ReadonlyArray<Breach>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Everything one failure is rendered from: the failure, its run's spans, the test and the replay value.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
interface FailureRecordInput<E = never> {
|
|
74
|
+
/** The failure itself: a `Cause`, or the value a program threw or failed with. */
|
|
75
|
+
readonly failure: Cause.Cause<E> | E;
|
|
76
|
+
/** Every span the failing run recorded, in creation order. */
|
|
77
|
+
readonly spans: ReadonlyArray<Tracer.NativeSpan>;
|
|
78
|
+
/** The test the run belonged to. */
|
|
79
|
+
readonly identity: TestIdentity;
|
|
80
|
+
/** The generator that chose this run, or `undefined` on a run no generator chose. */
|
|
81
|
+
readonly replay: ReplayValue | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The seed the kernel's scheduler chose. The kernel knows its own scheduler, so it hands the note over rather
|
|
84
|
+
* than the renderer guessing it; a run no scheduler chose renders no note (KTD5).
|
|
85
|
+
*/
|
|
86
|
+
readonly schedule?: {
|
|
87
|
+
readonly seed: number;
|
|
88
|
+
} | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The workspace root the rendered paths are relativized against, provided by the shared config the same way the
|
|
91
|
+
* package name is. Omitted, paths print absolute.
|
|
92
|
+
*/
|
|
93
|
+
readonly root?: string | undefined;
|
|
94
|
+
}
|
|
95
|
+
/** @internal */
|
|
96
|
+
declare const summaryOf: (value: Opaque$1) => string;
|
|
97
|
+
/**
|
|
98
|
+
* Renders the record Vitest prints for one spec failure, and the contract rules it breaks.
|
|
99
|
+
*
|
|
100
|
+
* Never throws: a `Cause` renders layer by layer, a thrown `Error` renders as one layer, and any other value
|
|
101
|
+
* renders as itself. The first location the record names is the raising frame — the first stack frame outside
|
|
102
|
+
* `node_modules` and outside the spec libraries' own `src/` and `dist/` — and when no layer has one, the
|
|
103
|
+
* innermost failed span's site stands in, or the innermost unfinished cell's decide site for a deadlock (KTD6).
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
declare const renderFailureRecord: <E>(input: FailureRecordInput<E>) => FailureRecord;
|
|
108
|
+
//#endregion
|
|
5
109
|
//#region src/internal/refusals.d.ts
|
|
6
110
|
/** @internal */
|
|
7
111
|
declare const refusedText: {
|
|
@@ -229,4 +333,4 @@ interface Checks {
|
|
|
229
333
|
readonly expect: Expect;
|
|
230
334
|
}
|
|
231
335
|
//#endregion
|
|
232
|
-
export { Expect as a, NoCheckRefusal as c, RefuseSyncBody as d, ScopedLaneRefusal as f, Checks as i, RefuseAsyncBody as l, UnprovidedRefusal as m, AssertedShape as n, EffectLaneRefusal as o, ScopedLiveLaneRefusal as p, Check as r, HookRefusal as s, Asserted as t, RefuseEffectBody as u };
|
|
336
|
+
export { summaryOf as S, FailureRecord as _, Expect as a, TestIdentity as b, NoCheckRefusal as c, RefuseSyncBody as d, ScopedLaneRefusal as f, Breach as g, AttributeValue as h, Checks as i, RefuseAsyncBody as l, UnprovidedRefusal as m, AssertedShape as n, EffectLaneRefusal as o, ScopedLiveLaneRefusal as p, Check as r, HookRefusal as s, Asserted as t, RefuseEffectBody as u, FailureRecordInput as v, renderFailureRecord as x, ReplayValue as y };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
|
|
2
|
+
import * as Cause from "effect/Cause";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema$1 from "effect/Schema";
|
|
5
|
+
import { Schema } from "effect";
|
|
6
|
+
import * as Arbitrary from "effect/unstable/arbitrary/Arbitrary";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/internal/errors.schema.d.ts
|
|
9
|
+
declare const NonBooleanVerdict_base: Schema.Class<NonBooleanVerdict, Schema.TaggedStruct<"NonBooleanVerdict", {
|
|
10
|
+
readonly detail: Schema.String;
|
|
11
|
+
}>, import("effect/Cause").YieldableError>;
|
|
12
|
+
/** @internal */
|
|
13
|
+
declare class NonBooleanVerdict extends NonBooleanVerdict_base {
|
|
14
|
+
get message(): string;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/internal/property/impostor.d.ts
|
|
18
|
+
/**
|
|
19
|
+
* @internal The constant impostor of R12: a fake of the subject under test that
|
|
20
|
+
* returns the first output it ever produced, for every later call, whatever the
|
|
21
|
+
* input it was given.
|
|
22
|
+
*
|
|
23
|
+
* A property that still holds for the impostor does not constrain the subject.
|
|
24
|
+
* Whether that is fatal is a per-file question — a subject's impostor must be
|
|
25
|
+
* refuted by some property in its file — so this module builds the fake and
|
|
26
|
+
* collects the verdicts; the engine decides them once, when the file finishes
|
|
27
|
+
* (KTD10).
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* A value the fork hands over without inspecting: an argument to the subject, or one of its outputs.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
type Opaque<A = unknown> = A;
|
|
35
|
+
/**
|
|
36
|
+
* A function under test: any argument, any output.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
type SubjectFunction = (...values: ReadonlyArray<never>) => Opaque;
|
|
41
|
+
/**
|
|
42
|
+
* A record of functions under test; every member is replaced by a constant.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
type MemberRecord = {
|
|
47
|
+
readonly [key: string]: SubjectFunction;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The function under test, or a record of them.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
type Subject = SubjectFunction | MemberRecord;
|
|
55
|
+
declare namespace kinds_d_exports {
|
|
56
|
+
export { LawApi, LawKind, LawSubject, MetamorphicRelation, deterministicHolds, idempotentHolds, invariantHolds, metamorphicHolds, modelHolds, roundTripHolds, spreadValues };
|
|
57
|
+
}
|
|
58
|
+
/** @internal */
|
|
59
|
+
type LawKind = 'model' | 'metamorphic' | 'roundTrip' | 'invariant' | 'idempotent' | 'deterministic';
|
|
60
|
+
/**
|
|
61
|
+
* A subject of a law kind: a function of the generated values.
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
type LawSubject<G extends Gens, A> = (...values: ReadonlyArray<ElementValues<G>>) => A;
|
|
66
|
+
/**
|
|
67
|
+
* A metamorphic relation: the input transform, and how the two outputs relate (structural equality by default).
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
interface MetamorphicRelation<G extends Gens, A> {
|
|
72
|
+
readonly transform: (...values: ReadonlyArray<ElementValues<G>>) => Values<G>;
|
|
73
|
+
readonly relate?: (original: A, transformed: A) => boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The R13 law surface: four gated kinds and two declared exemptions.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
interface LawApi {
|
|
81
|
+
readonly model: <const G extends Gens, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec<G, S, N>, oracle: LawSubject<G, A>) => void;
|
|
82
|
+
readonly metamorphic: <const G extends Gens, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec<G, S, N>, relation: MetamorphicRelation<G, A>) => void;
|
|
83
|
+
readonly roundTrip: <const G extends Gens, E, N extends number, S extends LawSubject<G, E>>(name: string, spec: PropertySpec<G, S, N>, decode: (encoded: E) => Values<G>) => void;
|
|
84
|
+
readonly invariant: <const G extends Gens, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec<G, S, N>, holds: (output: A, ...values: ReadonlyArray<ElementValues<G>>) => boolean) => void;
|
|
85
|
+
readonly idempotent: <const G extends Gens, N extends number, S extends (value: ElementValues<G>) => ElementValues<G>>(name: string, spec: PropertySpec<G, S, N>) => void;
|
|
86
|
+
readonly deterministic: <const G extends Gens, A, N extends number, S extends LawSubject<G, A>>(name: string, spec: PropertySpec<G, S, N>) => void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The generated values as the argument list a law subject is called with.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
declare const spreadValues: <G extends Gens>(values: Values<G>) => ReadonlyArray<ElementValues<G>>;
|
|
94
|
+
/** @internal */
|
|
95
|
+
declare const modelHolds: <G extends Gens, A>(oracle: LawSubject<G, A>) => (subject: LawSubject<G, A>, values: Values<G>) => boolean;
|
|
96
|
+
/** @internal */
|
|
97
|
+
declare const metamorphicHolds: <G extends Gens, A>(relation: MetamorphicRelation<G, A>) => (subject: LawSubject<G, A>, values: Values<G>) => boolean;
|
|
98
|
+
/** @internal */
|
|
99
|
+
declare const roundTripHolds: <G extends Gens, E>(decode: (encoded: E) => Values<G>) => (subject: LawSubject<G, E>, values: Values<G>) => boolean;
|
|
100
|
+
/** @internal */
|
|
101
|
+
declare const invariantHolds: <G extends Gens, A>(holds: (output: A, ...values: ReadonlyArray<ElementValues<G>>) => boolean) => (subject: LawSubject<G, A>, values: Values<G>) => boolean;
|
|
102
|
+
/** @internal */
|
|
103
|
+
declare const idempotentHolds: <G extends Gens>() => (subject: (value: ElementValues<G>) => ElementValues<G>, values: Values<G>) => boolean;
|
|
104
|
+
/** @internal */
|
|
105
|
+
declare const deterministicHolds: <G extends Gens, A>() => (subject: LawSubject<G, A>, values: Values<G>) => boolean;
|
|
106
|
+
declare namespace engine_d_exports {
|
|
107
|
+
export { ArbitraryInput, CoveragePredicate, ElementValues, Gens, PropApi, PropertyRuntime, PropertySpec, PropertySubject, Values, makeProperty };
|
|
108
|
+
}
|
|
109
|
+
/** @internal */
|
|
110
|
+
type ArbitraryInput = Schema$1.Top | Arbitrary.Arbitrary<Schema$1.Top['Type']>;
|
|
111
|
+
/** @internal */
|
|
112
|
+
type Gens = ReadonlyArray<ArbitraryInput> | {
|
|
113
|
+
readonly [key: string]: ArbitraryInput;
|
|
114
|
+
};
|
|
115
|
+
type Generated<I> = I extends Schema$1.Schema<infer T> ? T : I extends Arbitrary.Arbitrary<infer A> ? A : never;
|
|
116
|
+
/** @internal */
|
|
117
|
+
type Values<G extends Gens> = { readonly [K in keyof G]: Generated<G[K]>; };
|
|
118
|
+
/** @internal */
|
|
119
|
+
type ElementValues<G extends Gens> = G extends ReadonlyArray<ArbitraryInput> ? Generated<G[number]> : never;
|
|
120
|
+
/** @internal */
|
|
121
|
+
type PropertySubject = Subject;
|
|
122
|
+
/** @internal */
|
|
123
|
+
type CoveragePredicate<G extends Gens> = (...values: ReadonlyArray<ElementValues<G>>) => boolean;
|
|
124
|
+
type PropertyRuns<N extends number> = number extends N ? number : `${N}` extends `-${bigint}` ? never : `${N}` extends `${bigint}` ? (N extends 0 ? never : N) : never;
|
|
125
|
+
/** @internal */
|
|
126
|
+
interface PropertySpec<G extends Gens, S extends PropertySubject, N extends number> {
|
|
127
|
+
readonly of: G;
|
|
128
|
+
readonly subject: S;
|
|
129
|
+
/**
|
|
130
|
+
* The property's own run count. Omitted, the configured default applies; when the run provides none,
|
|
131
|
+
* the built-in default of 100 does.
|
|
132
|
+
*/
|
|
133
|
+
readonly runs?: N & PropertyRuns<N>;
|
|
134
|
+
/** Labelled input predicates, each with the minimum share of runs it must see (R14). */
|
|
135
|
+
readonly cover?: Readonly<Record<string, readonly [CoveragePredicate<G>, number]>>;
|
|
136
|
+
/** The property's own check options, merged field by field over the provided and built-in defaults. */
|
|
137
|
+
readonly arbitrary?: Arbitrary.CheckOptions;
|
|
138
|
+
}
|
|
139
|
+
/** @internal */
|
|
140
|
+
interface PropertyRuntime<R> {
|
|
141
|
+
/** Registers the property's program; the runtime runs it inside the test it registers, under that test's binding. */
|
|
142
|
+
readonly register: (name: string, program: () => Effect.Effect<void, Cause.Cause<NonBooleanVerdict>, never>) => void;
|
|
143
|
+
readonly provide: <A, E>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, never>;
|
|
144
|
+
}
|
|
145
|
+
/** @internal */
|
|
146
|
+
interface PropApi<R> {
|
|
147
|
+
readonly prop: <const G extends Gens, S extends PropertySubject, N extends number>(name: string, spec: PropertySpec<G, S, N>, holds: (subject: S, values: Values<G>) => boolean) => void;
|
|
148
|
+
readonly effectProp: <const G extends Gens, S extends PropertySubject, N extends number, E>(name: string, spec: PropertySpec<G, S, N>, holds: (subject: S, values: Values<G>) => Effect.Effect<boolean, E, R>) => void;
|
|
149
|
+
readonly law: LawApi;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The property surface over one runtime: `prop`, `effectProp`, and the R13 law kinds routed through the gate.
|
|
153
|
+
*
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
declare const makeProperty: <R>(runtime: PropertyRuntime<R>) => PropApi<R>;
|
|
157
|
+
//#endregion
|
|
158
|
+
export { Values as a, kinds_d_exports as c, PropertySubject as i, __exportAll as l, Gens as n, engine_d_exports as o, PropertySpec as r, LawApi as s, ArbitraryInput as t };
|