@effect/vitest 4.0.0-beta.7 → 4.0.0-beta.71
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/index.d.ts +35 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -23
- package/dist/index.js.map +1 -1
- package/dist/internal/internal.d.ts +1 -1
- package/dist/internal/internal.js +63 -9
- package/dist/internal/internal.js.map +1 -1
- package/dist/utils.d.ts +60 -10
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -10
- package/dist/utils.js.map +1 -1
- package/package.json +7 -6
- package/src/index.ts +37 -29
- package/src/internal/internal.ts +89 -14
- package/src/utils.ts +60 -10
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Assertion helpers used by `@effect/vitest` tests.
|
|
3
|
+
*
|
|
4
|
+
* This module extends Node and Vitest assertions with Effect-aware checks for
|
|
5
|
+
* values commonly returned by the library: `Option`, `Result`, and `Exit`. The
|
|
6
|
+
* helpers are synchronous assertions except `throwsAsync`, and are intended to
|
|
7
|
+
* be used after a test has already produced the value to inspect.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* `@effect/vitest` supplies the test runner integration, while this module
|
|
12
|
+
* supplies small value-level assertions. Use `it.effect` to run Effects and
|
|
13
|
+
* then call these helpers on yielded results; use ordinary Vitest tests for pure
|
|
14
|
+
* synchronous code.
|
|
15
|
+
*
|
|
16
|
+
* **Common tasks**
|
|
17
|
+
*
|
|
18
|
+
* Use `assertEquals` when equality should follow Effect's `Equal` trait, Node
|
|
19
|
+
* `strictEqual` or `deepStrictEqual` for JavaScript equality, `assertSome` and
|
|
20
|
+
* `assertNone` for `Option`, `assertSuccess` and `assertFailure` for `Result`,
|
|
21
|
+
* and `assertExitSuccess` or `assertExitFailure` when an Effect has been run to
|
|
22
|
+
* an `Exit`.
|
|
23
|
+
*
|
|
24
|
+
* **Gotchas**
|
|
25
|
+
*
|
|
26
|
+
* These helpers throw assertion errors; they do not run Effects, provide test
|
|
27
|
+
* services, or advance `TestClock`. Failed `assertEquals` checks first delegate
|
|
28
|
+
* to `deepStrictEqual` so Vitest can show a structural diff before reporting the
|
|
29
|
+
* `Equal.equals` mismatch.
|
|
30
|
+
*
|
|
2
31
|
* @since 4.0.0
|
|
3
32
|
*/
|
|
4
33
|
import type * as Cause from "effect/Cause"
|
|
@@ -17,6 +46,7 @@ import { assert as vassert } from "vitest"
|
|
|
17
46
|
/**
|
|
18
47
|
* Throws an `AssertionError` with the provided error message.
|
|
19
48
|
*
|
|
49
|
+
* @category testing
|
|
20
50
|
* @since 4.0.0
|
|
21
51
|
*/
|
|
22
52
|
export function fail(message: string) {
|
|
@@ -24,8 +54,9 @@ export function fail(message: string) {
|
|
|
24
54
|
}
|
|
25
55
|
|
|
26
56
|
/**
|
|
27
|
-
* Asserts that `actual` is equal to `expected` using
|
|
57
|
+
* Asserts that `actual` is deeply strictly equal to `expected` using Node's `assert.deepStrictEqual`.
|
|
28
58
|
*
|
|
59
|
+
* @category testing
|
|
29
60
|
* @since 4.0.0
|
|
30
61
|
*/
|
|
31
62
|
export function deepStrictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -33,8 +64,9 @@ export function deepStrictEqual<A>(actual: A, expected: A, message?: string, ...
|
|
|
33
64
|
}
|
|
34
65
|
|
|
35
66
|
/**
|
|
36
|
-
* Asserts that `actual` is not equal to `expected` using
|
|
67
|
+
* Asserts that `actual` is not deeply strictly equal to `expected` using Node's `assert.notDeepStrictEqual`.
|
|
37
68
|
*
|
|
69
|
+
* @category testing
|
|
38
70
|
* @since 4.0.0
|
|
39
71
|
*/
|
|
40
72
|
export function notDeepStrictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -42,8 +74,9 @@ export function notDeepStrictEqual<A>(actual: A, expected: A, message?: string,
|
|
|
42
74
|
}
|
|
43
75
|
|
|
44
76
|
/**
|
|
45
|
-
* Asserts that `actual` is equal to `expected` using
|
|
77
|
+
* Asserts that `actual` is strictly equal to `expected` using Node's `assert.strictEqual`.
|
|
46
78
|
*
|
|
79
|
+
* @category testing
|
|
47
80
|
* @since 4.0.0
|
|
48
81
|
*/
|
|
49
82
|
export function strictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -53,6 +86,7 @@ export function strictEqual<A>(actual: A, expected: A, message?: string, ..._: A
|
|
|
53
86
|
/**
|
|
54
87
|
* Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
|
|
55
88
|
*
|
|
89
|
+
* @category testing
|
|
56
90
|
* @since 4.0.0
|
|
57
91
|
*/
|
|
58
92
|
export function assertEquals<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -65,6 +99,7 @@ export function assertEquals<A>(actual: A, expected: A, message?: string, ..._:
|
|
|
65
99
|
/**
|
|
66
100
|
* Asserts that `thunk` does not throw an error.
|
|
67
101
|
*
|
|
102
|
+
* @category testing
|
|
68
103
|
* @since 4.0.0
|
|
69
104
|
*/
|
|
70
105
|
export function doesNotThrow(thunk: () => void, message?: string, ..._: Array<never>) {
|
|
@@ -78,6 +113,7 @@ export function doesNotThrow(thunk: () => void, message?: string, ..._: Array<ne
|
|
|
78
113
|
/**
|
|
79
114
|
* Asserts that `value` is an instance of `constructor`.
|
|
80
115
|
*
|
|
116
|
+
* @category testing
|
|
81
117
|
* @since 4.0.0
|
|
82
118
|
*/
|
|
83
119
|
export function assertInstanceOf<C extends abstract new(...args: any) => any>(
|
|
@@ -92,6 +128,7 @@ export function assertInstanceOf<C extends abstract new(...args: any) => any>(
|
|
|
92
128
|
/**
|
|
93
129
|
* Asserts that `self` is `true`.
|
|
94
130
|
*
|
|
131
|
+
* @category testing
|
|
95
132
|
* @since 4.0.0
|
|
96
133
|
*/
|
|
97
134
|
export function assertTrue(self: unknown, message?: string, ..._: Array<never>): asserts self {
|
|
@@ -101,6 +138,7 @@ export function assertTrue(self: unknown, message?: string, ..._: Array<never>):
|
|
|
101
138
|
/**
|
|
102
139
|
* Asserts that `self` is `false`.
|
|
103
140
|
*
|
|
141
|
+
* @category testing
|
|
104
142
|
* @since 4.0.0
|
|
105
143
|
*/
|
|
106
144
|
export function assertFalse(self: boolean, message?: string, ..._: Array<never>) {
|
|
@@ -110,6 +148,7 @@ export function assertFalse(self: boolean, message?: string, ..._: Array<never>)
|
|
|
110
148
|
/**
|
|
111
149
|
* Asserts that `actual` includes `expected`.
|
|
112
150
|
*
|
|
151
|
+
* @category testing
|
|
113
152
|
* @since 4.0.0
|
|
114
153
|
*/
|
|
115
154
|
export function assertInclude(actual: string | undefined, expected: string, ..._: Array<never>) {
|
|
@@ -123,6 +162,7 @@ export function assertInclude(actual: string | undefined, expected: string, ..._
|
|
|
123
162
|
/**
|
|
124
163
|
* Asserts that `actual` matches `regExp`.
|
|
125
164
|
*
|
|
165
|
+
* @category testing
|
|
126
166
|
* @since 4.0.0
|
|
127
167
|
*/
|
|
128
168
|
export function assertMatch(actual: string, regExp: RegExp, ..._: Array<never>) {
|
|
@@ -132,8 +172,9 @@ export function assertMatch(actual: string, regExp: RegExp, ..._: Array<never>)
|
|
|
132
172
|
}
|
|
133
173
|
|
|
134
174
|
/**
|
|
135
|
-
* Asserts that `thunk` throws an
|
|
175
|
+
* Asserts that `thunk` throws, optionally checking the thrown value against an expected `Error` or validation function.
|
|
136
176
|
*
|
|
177
|
+
* @category testing
|
|
137
178
|
* @since 4.0.0
|
|
138
179
|
*/
|
|
139
180
|
export function throws(thunk: () => void, error?: Error | ((u: unknown) => undefined), ..._: Array<never>) {
|
|
@@ -154,8 +195,9 @@ export function throws(thunk: () => void, error?: Error | ((u: unknown) => undef
|
|
|
154
195
|
}
|
|
155
196
|
|
|
156
197
|
/**
|
|
157
|
-
* Asserts that `thunk` throws an
|
|
198
|
+
* Asserts that `thunk` throws or returns a rejected promise, optionally checking the failure value against an expected `Error` or validation function.
|
|
158
199
|
*
|
|
200
|
+
* @category testing
|
|
159
201
|
* @since 4.0.0
|
|
160
202
|
*/
|
|
161
203
|
export async function throwsAsync(
|
|
@@ -184,6 +226,7 @@ export async function throwsAsync(
|
|
|
184
226
|
/**
|
|
185
227
|
* Asserts that `option` is `None`.
|
|
186
228
|
*
|
|
229
|
+
* @category testing
|
|
187
230
|
* @since 4.0.0
|
|
188
231
|
*/
|
|
189
232
|
export function assertNone<A>(option: Option.Option<A>, ..._: Array<never>): asserts option is Option.None<never> {
|
|
@@ -193,6 +236,7 @@ export function assertNone<A>(option: Option.Option<A>, ..._: Array<never>): ass
|
|
|
193
236
|
/**
|
|
194
237
|
* Asserts that `a` is not `undefined`.
|
|
195
238
|
*
|
|
239
|
+
* @category testing
|
|
196
240
|
* @since 4.0.0
|
|
197
241
|
*/
|
|
198
242
|
export function assertDefined<A>(
|
|
@@ -207,6 +251,7 @@ export function assertDefined<A>(
|
|
|
207
251
|
/**
|
|
208
252
|
* Asserts that `a` is `undefined`.
|
|
209
253
|
*
|
|
254
|
+
* @category testing
|
|
210
255
|
* @since 4.0.0
|
|
211
256
|
*/
|
|
212
257
|
export function assertUndefined<A>(
|
|
@@ -219,8 +264,9 @@ export function assertUndefined<A>(
|
|
|
219
264
|
}
|
|
220
265
|
|
|
221
266
|
/**
|
|
222
|
-
* Asserts that `option` is `Some`.
|
|
267
|
+
* Asserts that `option` is `Some` and contains a value equal to `expected`.
|
|
223
268
|
*
|
|
269
|
+
* @category testing
|
|
224
270
|
* @since 4.0.0
|
|
225
271
|
*/
|
|
226
272
|
export function assertSome<A>(
|
|
@@ -236,8 +282,9 @@ export function assertSome<A>(
|
|
|
236
282
|
// ----------------------------
|
|
237
283
|
|
|
238
284
|
/**
|
|
239
|
-
* Asserts that `result` is `Success`.
|
|
285
|
+
* Asserts that `result` is `Success` and contains a value equal to `expected`.
|
|
240
286
|
*
|
|
287
|
+
* @category testing
|
|
241
288
|
* @since 4.0.0
|
|
242
289
|
*/
|
|
243
290
|
export function assertSuccess<A, E>(
|
|
@@ -249,8 +296,9 @@ export function assertSuccess<A, E>(
|
|
|
249
296
|
}
|
|
250
297
|
|
|
251
298
|
/**
|
|
252
|
-
* Asserts that `result` is `Failure`.
|
|
299
|
+
* Asserts that `result` is `Failure` and contains an error equal to `expected`.
|
|
253
300
|
*
|
|
301
|
+
* @category testing
|
|
254
302
|
* @since 4.0.0
|
|
255
303
|
*/
|
|
256
304
|
export function assertFailure<A, E>(
|
|
@@ -266,8 +314,9 @@ export function assertFailure<A, E>(
|
|
|
266
314
|
// ----------------------------
|
|
267
315
|
|
|
268
316
|
/**
|
|
269
|
-
* Asserts that `exit` is a failure
|
|
317
|
+
* Asserts that `exit` is a failure with a cause equal to `expected`.
|
|
270
318
|
*
|
|
319
|
+
* @category testing
|
|
271
320
|
* @since 4.0.0
|
|
272
321
|
*/
|
|
273
322
|
export function assertExitFailure<A, E>(
|
|
@@ -279,8 +328,9 @@ export function assertExitFailure<A, E>(
|
|
|
279
328
|
}
|
|
280
329
|
|
|
281
330
|
/**
|
|
282
|
-
* Asserts that `exit` is a success
|
|
331
|
+
* Asserts that `exit` is a success with a value equal to `expected`.
|
|
283
332
|
*
|
|
333
|
+
* @category testing
|
|
284
334
|
* @since 4.0.0
|
|
285
335
|
*/
|
|
286
336
|
export function assertExitSuccess<A, E>(
|