@systemfsoftware/vitest 0.0.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/dist/utils.d.ts DELETED
@@ -1,197 +0,0 @@
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 DELETED
@@ -1,227 +0,0 @@
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 };