@systemfsoftware/vitest 0.0.0 → 0.1.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 +6 -0
- package/README.md +113 -61
- package/dist/TestClock.d.ts +1 -1
- package/dist/checks-DiuzHhQM.d.ts +232 -0
- package/dist/guard-BocOhXt2.mjs +246 -0
- package/dist/guard.d.ts +2 -0
- package/dist/guard.mjs +19 -0
- package/dist/index.d.ts +201 -287
- package/dist/index.mjs +353 -562
- package/dist/integration.d.ts +37 -0
- package/dist/integration.mjs +38 -0
- package/dist/test-context-hvSoKLtw.mjs +206 -0
- package/package.json +9 -9
- package/dist/refusals-BQtDszyU.mjs +0 -32
- package/dist/refusals-_6e3GzVK.d.ts +0 -37
- package/dist/refusals.d.ts +0 -3
- package/dist/refusals.mjs +0 -3
- package/dist/utils.d.ts +0 -197
- package/dist/utils.mjs +0 -227
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 };
|