@systemfsoftware/vitest 0.0.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 +17 -0
- package/LICENSE +203 -0
- package/README.md +236 -0
- package/dist/TestClock.d.ts +6 -0
- package/dist/TestClock.mjs +6 -0
- package/dist/compat.d.ts +11 -0
- package/dist/index.d.ts +735 -0
- package/dist/index.mjs +1523 -0
- package/dist/refusals-BQtDszyU.mjs +32 -0
- package/dist/refusals-_6e3GzVK.d.ts +37 -0
- package/dist/refusals.d.ts +3 -0
- package/dist/refusals.mjs +3 -0
- package/dist/utils.d.ts +197 -0
- package/dist/utils.mjs +227 -0
- package/package.json +75 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/internal/refusals.ts
|
|
3
|
+
/** @internal */
|
|
4
|
+
const refuseHook = "✗ hooks share state between tests. Build what a test needs inside it; services come fresh per test from layer(Service.layer)((it) => { ... }).";
|
|
5
|
+
/** @internal */
|
|
6
|
+
const refuseNoAssertion = "✗ this test ran no assertion, so it cannot fail. Assert on what the code returned: expect(actual).toEqual(expected).";
|
|
7
|
+
/** @internal */
|
|
8
|
+
const refuseAsync = "✗ an async test runs Effects outside the test runtime: no virtual time, no fresh services, no leak check. Return the Effect instead: it.effect(name, () => Effect.gen(function* () { ... })).";
|
|
9
|
+
/** @internal */
|
|
10
|
+
const refuseBareEffect = "✗ a bare test body that returns an Effect never runs it, so nothing in the test was checked. Register it on the Effect lane: it.effect(name, () => Effect.gen(function* () { ... })).";
|
|
11
|
+
/** @internal */
|
|
12
|
+
const refuseUnprovided = "✗ the test needs a service that nothing provides. Pipe the body through Effect.provide(Service.layer), or write the tests inside layer(Service.layer)((it) => { ... }); every test gets its own fresh build.";
|
|
13
|
+
/** @internal */
|
|
14
|
+
const refuseBoolean = "✗ expect(<boolean>) can only report 'expected false to be true'. Pass the two values instead: expect(Equal.equals(a, b)).toBe(true) becomes expect(a).toEqual(b). A predicate: expect(value).toSatisfy(predicate).";
|
|
15
|
+
/** @internal */
|
|
16
|
+
const refusePositionalProp = "✗ it.prop(name, [arbitraries], predicate) is removed. Name the function under test and pass a budget: it.prop(name, { of, subject, runs }, holds).";
|
|
17
|
+
/** @internal */
|
|
18
|
+
const presenceMessage = (name) => `✗ ${name} passes for almost any value the code returns. Assert the value: toEqual(expected); for a key that must exist: toHaveProperty(key).`;
|
|
19
|
+
/** @internal */
|
|
20
|
+
const narrowVacuous = [
|
|
21
|
+
"toBeDefined",
|
|
22
|
+
"toBeTruthy",
|
|
23
|
+
"toBeFalsy"
|
|
24
|
+
];
|
|
25
|
+
/** @internal */
|
|
26
|
+
const narrowNegated = [
|
|
27
|
+
...narrowVacuous,
|
|
28
|
+
"toBeNull",
|
|
29
|
+
"toBeUndefined"
|
|
30
|
+
];
|
|
31
|
+
//#endregion
|
|
32
|
+
export { refuseBareEffect as a, refuseNoAssertion as c, refuseAsync as i, refusePositionalProp as l, narrowVacuous as n, refuseBoolean as o, presenceMessage as r, refuseHook as s, narrowNegated as t, refuseUnprovided as u };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/internal/refusals.d.ts
|
|
3
|
+
/** @internal */
|
|
4
|
+
declare const refuseHook = "✗ hooks share state between tests. Build what a test needs inside it; services come fresh per test from layer(Service.layer)((it) => { ... }).";
|
|
5
|
+
/** @internal */
|
|
6
|
+
declare const refuseNoAssertion = "✗ this test ran no assertion, so it cannot fail. Assert on what the code returned: expect(actual).toEqual(expected).";
|
|
7
|
+
/** @internal */
|
|
8
|
+
declare const refuseAsync = "✗ an async test runs Effects outside the test runtime: no virtual time, no fresh services, no leak check. Return the Effect instead: it.effect(name, () => Effect.gen(function* () { ... })).";
|
|
9
|
+
/** @internal */
|
|
10
|
+
declare const refuseBareEffect = "✗ a bare test body that returns an Effect never runs it, so nothing in the test was checked. Register it on the Effect lane: it.effect(name, () => Effect.gen(function* () { ... })).";
|
|
11
|
+
/** @internal */
|
|
12
|
+
declare const refuseUnprovided = "✗ the test needs a service that nothing provides. Pipe the body through Effect.provide(Service.layer), or write the tests inside layer(Service.layer)((it) => { ... }); every test gets its own fresh build.";
|
|
13
|
+
/** @internal */
|
|
14
|
+
declare const refuseBoolean = "✗ expect(<boolean>) can only report 'expected false to be true'. Pass the two values instead: expect(Equal.equals(a, b)).toBe(true) becomes expect(a).toEqual(b). A predicate: expect(value).toSatisfy(predicate).";
|
|
15
|
+
/** @internal */
|
|
16
|
+
declare const refusePositionalProp = "✗ it.prop(name, [arbitraries], predicate) is removed. Name the function under test and pass a budget: it.prop(name, { of, subject, runs }, holds).";
|
|
17
|
+
/** @internal */
|
|
18
|
+
type PresenceMessage<N extends string = string> = `✗ ${N} passes for almost any value the code returns. Assert the value: toEqual(expected); for a key that must exist: toHaveProperty(key).`;
|
|
19
|
+
/**
|
|
20
|
+
* The narrowed matcher as the type sees it: a call whose `this` is not the assertion cannot compile, and the
|
|
21
|
+
* refused text is the compiler error (KTD9). The run time throws the same text.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
type PresenceRefusal<N extends string = string> = (this: PresenceMessage<N>, ...args: Array<never>) => void;
|
|
26
|
+
/** @internal */
|
|
27
|
+
declare const presenceMessage: <N extends string>(name: N) => PresenceMessage<N>;
|
|
28
|
+
/** @internal */
|
|
29
|
+
declare const narrowVacuous: readonly ['toBeDefined', 'toBeTruthy', 'toBeFalsy'];
|
|
30
|
+
/** @internal */
|
|
31
|
+
type NarrowVacuousName = (typeof narrowVacuous)[number];
|
|
32
|
+
/** @internal */
|
|
33
|
+
declare const narrowNegated: readonly ["toBeDefined", "toBeTruthy", "toBeFalsy", "toBeNull", "toBeUndefined"];
|
|
34
|
+
/** @internal */
|
|
35
|
+
type NarrowNegatedName = (typeof narrowNegated)[number];
|
|
36
|
+
//#endregion
|
|
37
|
+
export { narrowVacuous as a, refuseBareEffect as c, refuseNoAssertion as d, refusePositionalProp as f, narrowNegated as i, refuseBoolean as l, NarrowVacuousName as n, presenceMessage as o, refuseUnprovided as p, PresenceRefusal as r, refuseAsync as s, NarrowNegatedName as t, refuseHook as u };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
|
|
2
|
+
import { a as narrowVacuous, c as refuseBareEffect, d as refuseNoAssertion, f as refusePositionalProp, i as narrowNegated, l as refuseBoolean, o as presenceMessage, p as refuseUnprovided, s as refuseAsync, u as refuseHook } from "./refusals-_6e3GzVK.js";
|
|
3
|
+
export { narrowNegated, narrowVacuous, presenceMessage, refuseAsync, refuseBareEffect, refuseBoolean, refuseHook, refuseNoAssertion, refusePositionalProp, refuseUnprovided };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
|
|
2
|
+
import { a as refuseBareEffect, c as refuseNoAssertion, i as refuseAsync, l as refusePositionalProp, n as narrowVacuous, o as refuseBoolean, r as presenceMessage, s as refuseHook, t as narrowNegated, u as refuseUnprovided } from "./refusals-BQtDszyU.mjs";
|
|
3
|
+
export { narrowNegated, narrowVacuous, presenceMessage, refuseAsync, refuseBareEffect, refuseBoolean, refuseHook, refuseNoAssertion, refusePositionalProp, refuseUnprovided };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
|
|
2
|
+
import * as Cause from "effect/Cause";
|
|
3
|
+
import * as Exit from "effect/Exit";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Result from "effect/Result";
|
|
6
|
+
//#region src/utils.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Inspects the value a thunk threw. `A` defaults to `unknown` so a caller passes any inspection function.
|
|
9
|
+
*/
|
|
10
|
+
type ThrownValidator = <A = unknown>(thrown: A) => undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Any class, abstract ones included: what `assertInstanceOf` accepts and what `instanceof` takes.
|
|
13
|
+
*/
|
|
14
|
+
type AnyConstructor = abstract new (...args: never[]) => object;
|
|
15
|
+
/**
|
|
16
|
+
* Fails the current test with the provided error message.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.0.0
|
|
19
|
+
*/
|
|
20
|
+
export declare function fail(message: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Asserts that `actual` is deeply strictly equal to `expected`.
|
|
23
|
+
*
|
|
24
|
+
* @since 4.0.0
|
|
25
|
+
*/
|
|
26
|
+
export declare const deepStrictEqual: {
|
|
27
|
+
<A>(actual: A, expected: A, message?: undefined): void;
|
|
28
|
+
<A>(expected: A, message?: undefined): (actual: A) => void;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Asserts that `actual` is not deeply strictly equal to `expected`.
|
|
32
|
+
*
|
|
33
|
+
* Chai names the negation of its deep comparison `notDeepEqual`; there, `deepStrictEqual` and `deepEqual` are
|
|
34
|
+
* one function.
|
|
35
|
+
*
|
|
36
|
+
* @since 4.0.0
|
|
37
|
+
*/
|
|
38
|
+
export declare const notDeepStrictEqual: {
|
|
39
|
+
<A>(actual: A, expected: A, message?: undefined): void;
|
|
40
|
+
<A>(expected: A, message?: undefined): (actual: A) => void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Asserts that `actual` is strictly equal to `expected`.
|
|
44
|
+
*
|
|
45
|
+
* @since 4.0.0
|
|
46
|
+
*/
|
|
47
|
+
export declare const strictEqual: {
|
|
48
|
+
<A>(actual: A, expected: A, message?: undefined): void;
|
|
49
|
+
<A>(expected: A, message?: undefined): (actual: A) => void;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
|
|
53
|
+
*
|
|
54
|
+
* @since 4.0.0
|
|
55
|
+
*/
|
|
56
|
+
export declare const assertEquals: {
|
|
57
|
+
<A>(actual: A, expected: A, message?: undefined): void;
|
|
58
|
+
<A>(expected: A, message?: undefined): (actual: A) => void;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Asserts that `thunk` does not throw an error.
|
|
62
|
+
*
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
export declare const doesNotThrow: {
|
|
66
|
+
(thunk: () => void, message?: string): void;
|
|
67
|
+
(message?: string): (thunk: () => void) => void;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Asserts that `value` is an instance of `constructor`.
|
|
71
|
+
*
|
|
72
|
+
* @since 4.0.0
|
|
73
|
+
*/
|
|
74
|
+
export declare const assertInstanceOf: {
|
|
75
|
+
<C extends AnyConstructor>(value: unknown, ctor: C, message?: string): asserts value is InstanceType<C>;
|
|
76
|
+
<C extends AnyConstructor>(ctor: C, message?: string): (value: unknown) => asserts value is InstanceType<C>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Asserts that `self` is `true`.
|
|
80
|
+
*
|
|
81
|
+
* @since 4.0.0
|
|
82
|
+
*/
|
|
83
|
+
export declare const assertTrue: {
|
|
84
|
+
(self: boolean, message?: string): asserts self;
|
|
85
|
+
(message?: string): (self: boolean) => asserts self;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Asserts that `self` is `false`.
|
|
89
|
+
*
|
|
90
|
+
* @since 4.0.0
|
|
91
|
+
*/
|
|
92
|
+
export declare const assertFalse: {
|
|
93
|
+
(self: boolean, message?: string): void;
|
|
94
|
+
(message?: string): (self: boolean) => void;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Asserts that `actual` includes `expected`.
|
|
98
|
+
*
|
|
99
|
+
* @since 4.0.0
|
|
100
|
+
*/
|
|
101
|
+
export declare const assertInclude: {
|
|
102
|
+
(actual: string | undefined, expected: string): void;
|
|
103
|
+
(expected: string): (actual: string | undefined) => void;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Asserts that `actual` matches `regExp`.
|
|
107
|
+
*
|
|
108
|
+
* @since 4.0.0
|
|
109
|
+
*/
|
|
110
|
+
export declare const assertMatch: {
|
|
111
|
+
(actual: string, regExp: RegExp): void;
|
|
112
|
+
(regExp: RegExp): (actual: string) => void;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Asserts that `thunk` throws, optionally checking the thrown value against an expected `Error` or validation
|
|
116
|
+
* function.
|
|
117
|
+
*
|
|
118
|
+
* @since 4.0.0
|
|
119
|
+
*/
|
|
120
|
+
export declare const throws: {
|
|
121
|
+
(thunk: () => void, error?: Error | ThrownValidator): void;
|
|
122
|
+
(error?: Error | ThrownValidator): (thunk: () => void) => void;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Asserts that `thunk` throws or returns a rejected promise, optionally checking the failure value against an
|
|
126
|
+
* expected `Error` or validation function.
|
|
127
|
+
*
|
|
128
|
+
* @since 4.0.0
|
|
129
|
+
*/
|
|
130
|
+
export declare const throwsAsync: {
|
|
131
|
+
(thunk: () => Promise<void>, error?: Error | ThrownValidator): Promise<void>;
|
|
132
|
+
(error?: Error | ThrownValidator): (thunk: () => Promise<void>) => Promise<void>;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Asserts that `option` is `None`.
|
|
136
|
+
*
|
|
137
|
+
* @since 4.0.0
|
|
138
|
+
*/
|
|
139
|
+
export declare function assertNone<A>(option: Option.Option<A>): asserts option is Option.None<never>;
|
|
140
|
+
/**
|
|
141
|
+
* Asserts that `a` is not `undefined`.
|
|
142
|
+
*
|
|
143
|
+
* @since 4.0.0
|
|
144
|
+
*/
|
|
145
|
+
export declare function assertDefined<A>(a: A | undefined): asserts a is Exclude<A, undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* Asserts that `a` is `undefined`.
|
|
148
|
+
*
|
|
149
|
+
* @since 4.0.0
|
|
150
|
+
*/
|
|
151
|
+
export declare function assertUndefined<A>(a: A | undefined): asserts a is undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Asserts that `option` is `Some` and contains a value equal to `expected`.
|
|
154
|
+
*
|
|
155
|
+
* @since 4.0.0
|
|
156
|
+
*/
|
|
157
|
+
export declare const assertSome: {
|
|
158
|
+
<A>(option: Option.Option<A>, expected: A): asserts option is Option.Some<A>;
|
|
159
|
+
<A>(expected: A): (option: Option.Option<A>) => asserts option is Option.Some<A>;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Asserts that `result` is `Success` and contains a value equal to `expected`.
|
|
163
|
+
*
|
|
164
|
+
* @since 4.0.0
|
|
165
|
+
*/
|
|
166
|
+
export declare const assertSuccess: {
|
|
167
|
+
<A, E>(result: Result.Result<A, E>, expected: A): asserts result is Result.Success<A, never>;
|
|
168
|
+
<A, E>(expected: A): (result: Result.Result<A, E>) => asserts result is Result.Success<A, never>;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Asserts that `result` is `Failure` and contains an error equal to `expected`.
|
|
172
|
+
*
|
|
173
|
+
* @since 4.0.0
|
|
174
|
+
*/
|
|
175
|
+
export declare const assertFailure: {
|
|
176
|
+
<A, E>(result: Result.Result<A, E>, expected: E): asserts result is Result.Failure<never, E>;
|
|
177
|
+
<A, E>(expected: E): (result: Result.Result<A, E>) => asserts result is Result.Failure<never, E>;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Asserts that `exit` is a failure with a cause equal to `expected`.
|
|
181
|
+
*
|
|
182
|
+
* @since 4.0.0
|
|
183
|
+
*/
|
|
184
|
+
export declare const assertExitFailure: {
|
|
185
|
+
<A, E>(exit: Exit.Exit<A, E>, expected: Cause.Cause<E>): asserts exit is Exit.Failure<never, E>;
|
|
186
|
+
<A, E>(expected: Cause.Cause<E>): (exit: Exit.Exit<A, E>) => asserts exit is Exit.Failure<never, E>;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Asserts that `exit` is a success with a value equal to `expected`.
|
|
190
|
+
*
|
|
191
|
+
* @since 4.0.0
|
|
192
|
+
*/
|
|
193
|
+
export declare const assertExitSuccess: {
|
|
194
|
+
<A, E>(exit: Exit.Exit<A, E>, expected: A): asserts exit is Exit.Success<A, never>;
|
|
195
|
+
<A, E>(expected: A): (exit: Exit.Exit<A, E>) => asserts exit is Exit.Success<A, never>;
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
|
|
2
|
+
import { assert } from "vitest";
|
|
3
|
+
import { dual } from "effect/Function";
|
|
4
|
+
import * as Equal from "effect/Equal";
|
|
5
|
+
import * as Exit from "effect/Exit";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import * as Predicate from "effect/Predicate";
|
|
8
|
+
import * as Result from "effect/Result";
|
|
9
|
+
//#region src/utils.ts
|
|
10
|
+
/**
|
|
11
|
+
* Whether `actual` — possibly absent — contains `expected`.
|
|
12
|
+
*/
|
|
13
|
+
const includes = (actual, expected) => actual !== void 0 && actual.includes(expected);
|
|
14
|
+
/**
|
|
15
|
+
* `assertEquals`'s message when the caller gave none: the two values are deep-equal, so only the `Equal` trait
|
|
16
|
+
* explains the failure.
|
|
17
|
+
*/
|
|
18
|
+
const equalMismatch = (message) => message ?? "Expected values to be Equal.equals";
|
|
19
|
+
/**
|
|
20
|
+
* `assertInstanceOf`'s message when the caller gave none: the value may be anything, so only the constructor
|
|
21
|
+
* names the expectation.
|
|
22
|
+
*/
|
|
23
|
+
const instanceMismatch = (constructor, message) => message ?? `Expected value to be an instance of ${constructor.name}`;
|
|
24
|
+
/**
|
|
25
|
+
* Runs `thunk`, then applies `error`'s expectation to anything it threw: a validator inspects the value, an
|
|
26
|
+
* `Error` must be deep-strict-equal to it, and no expectation accepts any throw.
|
|
27
|
+
*/
|
|
28
|
+
const applyThrown = (thunk, error) => {
|
|
29
|
+
try {
|
|
30
|
+
thunk();
|
|
31
|
+
} catch (e) {
|
|
32
|
+
Option.match(Option.fromNullishOr(error), {
|
|
33
|
+
onNone: () => void 0,
|
|
34
|
+
onSome: (expectation) => Predicate.isFunction(expectation) ? expectation(e) : deepStrictEqual(e, expectation)
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
fail("Expected to throw an error");
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Whether a dual assertion call is the data-first one: a piped call names the expected value alone, and a
|
|
42
|
+
* pair of values is the only other shape these helpers take.
|
|
43
|
+
*
|
|
44
|
+
* No overload of them carries a message, because a pipeable signature has to repeat its data-first twin
|
|
45
|
+
* parameter for parameter (`effecttsgo/missing-pipeable-signature`). A pair of values therefore cannot be
|
|
46
|
+
* mistaken for a value and a message, in the types or here, and the message a caller might have written is
|
|
47
|
+
* refused rather than dropped.
|
|
48
|
+
*/
|
|
49
|
+
const byTwoValues = (args) => args.length >= 2;
|
|
50
|
+
/**
|
|
51
|
+
* Fails the current test with the provided error message.
|
|
52
|
+
*
|
|
53
|
+
* @since 4.0.0
|
|
54
|
+
*/
|
|
55
|
+
function fail(message) {
|
|
56
|
+
assert.fail(message);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Asserts that `actual` is deeply strictly equal to `expected`.
|
|
60
|
+
*
|
|
61
|
+
* @since 4.0.0
|
|
62
|
+
*/
|
|
63
|
+
const deepStrictEqual = dual(byTwoValues, (actual, expected, message) => {
|
|
64
|
+
assert.deepStrictEqual(actual, expected, message);
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Asserts that `actual` is not deeply strictly equal to `expected`.
|
|
68
|
+
*
|
|
69
|
+
* Chai names the negation of its deep comparison `notDeepEqual`; there, `deepStrictEqual` and `deepEqual` are
|
|
70
|
+
* one function.
|
|
71
|
+
*
|
|
72
|
+
* @since 4.0.0
|
|
73
|
+
*/
|
|
74
|
+
const notDeepStrictEqual = dual(byTwoValues, (actual, expected, message) => {
|
|
75
|
+
assert.notDeepEqual(actual, expected, message);
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Asserts that `actual` is strictly equal to `expected`.
|
|
79
|
+
*
|
|
80
|
+
* @since 4.0.0
|
|
81
|
+
*/
|
|
82
|
+
const strictEqual = dual(byTwoValues, (actual, expected, message) => {
|
|
83
|
+
assert.strictEqual(actual, expected, message);
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
|
|
87
|
+
*
|
|
88
|
+
* @since 4.0.0
|
|
89
|
+
*/
|
|
90
|
+
const assertEquals = dual(byTwoValues, (actual, expected, message) => {
|
|
91
|
+
if (Equal.equals(actual, expected)) return;
|
|
92
|
+
assert.deepStrictEqual(actual, expected, message);
|
|
93
|
+
fail(equalMismatch(message));
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Asserts that `thunk` does not throw an error.
|
|
97
|
+
*
|
|
98
|
+
* @since 4.0.0
|
|
99
|
+
*/
|
|
100
|
+
const doesNotThrow = dual((args) => args.length >= 2 || typeof args[0] === "function", (thunk, message) => {
|
|
101
|
+
assert.doesNotThrow(thunk, void 0, void 0, message);
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Asserts that `value` is an instance of `constructor`.
|
|
105
|
+
*
|
|
106
|
+
* @since 4.0.0
|
|
107
|
+
*/
|
|
108
|
+
const assertInstanceOf = dual((args) => args.length >= 2 && typeof args[1] !== "string", (value, ctor, message) => {
|
|
109
|
+
if (value instanceof ctor) return;
|
|
110
|
+
fail(instanceMismatch(ctor, message));
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Asserts that `self` is `true`.
|
|
114
|
+
*
|
|
115
|
+
* @since 4.0.0
|
|
116
|
+
*/
|
|
117
|
+
const assertTrue = dual((args) => args.length >= 2 || typeof args[0] === "boolean", (self, message) => {
|
|
118
|
+
assert.strictEqual(self, true, message);
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Asserts that `self` is `false`.
|
|
122
|
+
*
|
|
123
|
+
* @since 4.0.0
|
|
124
|
+
*/
|
|
125
|
+
const assertFalse = dual((args) => args.length >= 2 || typeof args[0] === "boolean", (self, message) => {
|
|
126
|
+
assert.strictEqual(self, false, message);
|
|
127
|
+
});
|
|
128
|
+
/**
|
|
129
|
+
* Asserts that `actual` includes `expected`.
|
|
130
|
+
*
|
|
131
|
+
* @since 4.0.0
|
|
132
|
+
*/
|
|
133
|
+
const assertInclude = dual((args) => args.length >= 2, (actual, expected) => {
|
|
134
|
+
if (!includes(actual, expected)) fail(`Expected\n\n${actual}\n\nto include\n\n${expected}`);
|
|
135
|
+
});
|
|
136
|
+
/**
|
|
137
|
+
* Asserts that `actual` matches `regExp`.
|
|
138
|
+
*
|
|
139
|
+
* @since 4.0.0
|
|
140
|
+
*/
|
|
141
|
+
const assertMatch = dual((args) => args.length >= 2, (actual, regExp) => {
|
|
142
|
+
if (!regExp.test(actual)) fail(`Expected\n\n${actual}\n\nto match\n\n${regExp}`);
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Asserts that `thunk` throws, optionally checking the thrown value against an expected `Error` or validation
|
|
146
|
+
* function.
|
|
147
|
+
*
|
|
148
|
+
* @since 4.0.0
|
|
149
|
+
*/
|
|
150
|
+
const throws = dual((args) => args.length >= 2 || typeof args[0] === "function", (thunk, error) => {
|
|
151
|
+
applyThrown(thunk, error);
|
|
152
|
+
});
|
|
153
|
+
/**
|
|
154
|
+
* Asserts that `thunk` throws or returns a rejected promise, optionally checking the failure value against an
|
|
155
|
+
* expected `Error` or validation function.
|
|
156
|
+
*
|
|
157
|
+
* @since 4.0.0
|
|
158
|
+
*/
|
|
159
|
+
const throwsAsync = dual((args) => args.length >= 2 || typeof args[0] === "function", (thunk, error) => Promise.resolve().then(thunk).then(() => fail("Expected to throw an error"), (thrown) => applyThrown(() => {
|
|
160
|
+
throw thrown;
|
|
161
|
+
}, error)));
|
|
162
|
+
/**
|
|
163
|
+
* Asserts that `option` is `None`.
|
|
164
|
+
*
|
|
165
|
+
* @since 4.0.0
|
|
166
|
+
*/
|
|
167
|
+
function assertNone(option) {
|
|
168
|
+
deepStrictEqual(option, Option.none());
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Asserts that `a` is not `undefined`.
|
|
172
|
+
*
|
|
173
|
+
* @since 4.0.0
|
|
174
|
+
*/
|
|
175
|
+
function assertDefined(a) {
|
|
176
|
+
if (a === void 0) fail("Expected value to be defined");
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Asserts that `a` is `undefined`.
|
|
180
|
+
*
|
|
181
|
+
* @since 4.0.0
|
|
182
|
+
*/
|
|
183
|
+
function assertUndefined(a) {
|
|
184
|
+
if (a !== void 0) fail("Expected value to be undefined");
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Asserts that `option` is `Some` and contains a value equal to `expected`.
|
|
188
|
+
*
|
|
189
|
+
* @since 4.0.0
|
|
190
|
+
*/
|
|
191
|
+
const assertSome = dual((args) => args.length >= 2, (option, expected) => {
|
|
192
|
+
deepStrictEqual(option, Option.some(expected));
|
|
193
|
+
});
|
|
194
|
+
/**
|
|
195
|
+
* Asserts that `result` is `Success` and contains a value equal to `expected`.
|
|
196
|
+
*
|
|
197
|
+
* @since 4.0.0
|
|
198
|
+
*/
|
|
199
|
+
const assertSuccess = dual((args) => args.length >= 2, (result, expected) => {
|
|
200
|
+
deepStrictEqual(result, Result.succeed(expected));
|
|
201
|
+
});
|
|
202
|
+
/**
|
|
203
|
+
* Asserts that `result` is `Failure` and contains an error equal to `expected`.
|
|
204
|
+
*
|
|
205
|
+
* @since 4.0.0
|
|
206
|
+
*/
|
|
207
|
+
const assertFailure = dual((args) => args.length >= 2, (result, expected) => {
|
|
208
|
+
deepStrictEqual(result, Result.fail(expected));
|
|
209
|
+
});
|
|
210
|
+
/**
|
|
211
|
+
* Asserts that `exit` is a failure with a cause equal to `expected`.
|
|
212
|
+
*
|
|
213
|
+
* @since 4.0.0
|
|
214
|
+
*/
|
|
215
|
+
const assertExitFailure = dual((args) => args.length >= 2, (exit, expected) => {
|
|
216
|
+
deepStrictEqual(exit, Exit.failCause(expected));
|
|
217
|
+
});
|
|
218
|
+
/**
|
|
219
|
+
* Asserts that `exit` is a success with a value equal to `expected`.
|
|
220
|
+
*
|
|
221
|
+
* @since 4.0.0
|
|
222
|
+
*/
|
|
223
|
+
const assertExitSuccess = dual((args) => args.length >= 2, (exit, expected) => {
|
|
224
|
+
deepStrictEqual(exit, Exit.succeed(expected));
|
|
225
|
+
});
|
|
226
|
+
//#endregion
|
|
227
|
+
export { assertDefined, assertEquals, assertExitFailure, assertExitSuccess, assertFailure, assertFalse, assertInclude, assertInstanceOf, assertMatch, assertNone, assertSome, assertSuccess, assertTrue, assertUndefined, deepStrictEqual, doesNotThrow, fail, notDeepStrictEqual, strictEqual, throws, throwsAsync };
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@systemfsoftware/vitest",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/systemfsoftware/systemfsoftware.git",
|
|
9
|
+
"directory": "packages/vitest"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/vitest#readme",
|
|
12
|
+
"bugs": "https://github.com/systemfsoftware/systemfsoftware/issues",
|
|
13
|
+
"description": "A fork of @effect/vitest whose defaults make the lazy test a good test: fresh layers, a second run that catches leaked state, virtual time, soft checks that stop at the next step, and properties refuted against a constant impostor.",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"effect",
|
|
16
|
+
"effect-ts",
|
|
17
|
+
"vitest",
|
|
18
|
+
"testing",
|
|
19
|
+
"property-testing",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./refusals": {
|
|
29
|
+
"types": "./dist/refusals.d.ts",
|
|
30
|
+
"default": "./dist/refusals.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./TestClock": {
|
|
33
|
+
"types": "./dist/TestClock.d.ts",
|
|
34
|
+
"default": "./dist/TestClock.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./utils": {
|
|
37
|
+
"types": "./dist/utils.d.ts",
|
|
38
|
+
"default": "./dist/utils.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
|
|
47
|
+
"@systemfsoftware/oxlint-config-recommended": "^3.1.0",
|
|
48
|
+
"@systemfsoftware/tsconfig": "^2.0.1",
|
|
49
|
+
"@systemfsoftware/tsdown-config": "^0.1.0",
|
|
50
|
+
"@systemfsoftware/vitest-config": "^0.1.0",
|
|
51
|
+
"@types/node": "^26",
|
|
52
|
+
"effect": "4.0.0-rc.117",
|
|
53
|
+
"oxlint": "~1.82.0",
|
|
54
|
+
"rimraf": "^6.1.3",
|
|
55
|
+
"tsdown": "^0.23.0",
|
|
56
|
+
"tstyche": "^7.2.5",
|
|
57
|
+
"vitest": "^5"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"effect": "4.0.0-rc.117",
|
|
61
|
+
"vitest": "^5"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"provenance": true
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"clean": "rimraf dist",
|
|
68
|
+
"build": "tsdown -l warn",
|
|
69
|
+
"typecheck": "tsc -b",
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"test:types": "TSTYCHE_TYPESCRIPT_MODULE=tstyche-typescript tstyche",
|
|
72
|
+
"lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
|
|
73
|
+
"attw": "attw --pack ."
|
|
74
|
+
}
|
|
75
|
+
}
|