@effect/vitest 4.0.0-beta.7 → 4.0.0-beta.70
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 +45 -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 +45 -10
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Assertion utilities for `@effect/vitest` test suites.
|
|
3
|
+
*
|
|
4
|
+
* This module collects small assertion helpers for common Effect testing
|
|
5
|
+
* scenarios: Node-style equality checks, `Equal.equals` comparisons, string
|
|
6
|
+
* matching, thrown error validation, and focused assertions for `Option`,
|
|
7
|
+
* `Result`, and `Exit` values. They are intended to be imported as `assert`
|
|
8
|
+
* helpers from `@effect/vitest` and used in both regular Vitest tests and
|
|
9
|
+
* `it.effect` tests after the value under test has already been produced.
|
|
10
|
+
*
|
|
11
|
+
* These helpers throw assertion errors synchronously; they do not run Effects,
|
|
12
|
+
* provide services, or advance test environments such as `TestClock`. In
|
|
13
|
+
* Effect-based tests, yield the effect first and then assert on the resulting
|
|
14
|
+
* value so failures are reported through the surrounding Vitest test.
|
|
15
|
+
*
|
|
2
16
|
* @since 4.0.0
|
|
3
17
|
*/
|
|
4
18
|
import type * as Cause from "effect/Cause"
|
|
@@ -17,6 +31,7 @@ import { assert as vassert } from "vitest"
|
|
|
17
31
|
/**
|
|
18
32
|
* Throws an `AssertionError` with the provided error message.
|
|
19
33
|
*
|
|
34
|
+
* @category testing
|
|
20
35
|
* @since 4.0.0
|
|
21
36
|
*/
|
|
22
37
|
export function fail(message: string) {
|
|
@@ -24,8 +39,9 @@ export function fail(message: string) {
|
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
/**
|
|
27
|
-
* Asserts that `actual` is equal to `expected` using
|
|
42
|
+
* Asserts that `actual` is deeply strictly equal to `expected` using Node's `assert.deepStrictEqual`.
|
|
28
43
|
*
|
|
44
|
+
* @category testing
|
|
29
45
|
* @since 4.0.0
|
|
30
46
|
*/
|
|
31
47
|
export function deepStrictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -33,8 +49,9 @@ export function deepStrictEqual<A>(actual: A, expected: A, message?: string, ...
|
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
/**
|
|
36
|
-
* Asserts that `actual` is not equal to `expected` using
|
|
52
|
+
* Asserts that `actual` is not deeply strictly equal to `expected` using Node's `assert.notDeepStrictEqual`.
|
|
37
53
|
*
|
|
54
|
+
* @category testing
|
|
38
55
|
* @since 4.0.0
|
|
39
56
|
*/
|
|
40
57
|
export function notDeepStrictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -42,8 +59,9 @@ export function notDeepStrictEqual<A>(actual: A, expected: A, message?: string,
|
|
|
42
59
|
}
|
|
43
60
|
|
|
44
61
|
/**
|
|
45
|
-
* Asserts that `actual` is equal to `expected` using
|
|
62
|
+
* Asserts that `actual` is strictly equal to `expected` using Node's `assert.strictEqual`.
|
|
46
63
|
*
|
|
64
|
+
* @category testing
|
|
47
65
|
* @since 4.0.0
|
|
48
66
|
*/
|
|
49
67
|
export function strictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -53,6 +71,7 @@ export function strictEqual<A>(actual: A, expected: A, message?: string, ..._: A
|
|
|
53
71
|
/**
|
|
54
72
|
* Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
|
|
55
73
|
*
|
|
74
|
+
* @category testing
|
|
56
75
|
* @since 4.0.0
|
|
57
76
|
*/
|
|
58
77
|
export function assertEquals<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
|
|
@@ -65,6 +84,7 @@ export function assertEquals<A>(actual: A, expected: A, message?: string, ..._:
|
|
|
65
84
|
/**
|
|
66
85
|
* Asserts that `thunk` does not throw an error.
|
|
67
86
|
*
|
|
87
|
+
* @category testing
|
|
68
88
|
* @since 4.0.0
|
|
69
89
|
*/
|
|
70
90
|
export function doesNotThrow(thunk: () => void, message?: string, ..._: Array<never>) {
|
|
@@ -78,6 +98,7 @@ export function doesNotThrow(thunk: () => void, message?: string, ..._: Array<ne
|
|
|
78
98
|
/**
|
|
79
99
|
* Asserts that `value` is an instance of `constructor`.
|
|
80
100
|
*
|
|
101
|
+
* @category testing
|
|
81
102
|
* @since 4.0.0
|
|
82
103
|
*/
|
|
83
104
|
export function assertInstanceOf<C extends abstract new(...args: any) => any>(
|
|
@@ -92,6 +113,7 @@ export function assertInstanceOf<C extends abstract new(...args: any) => any>(
|
|
|
92
113
|
/**
|
|
93
114
|
* Asserts that `self` is `true`.
|
|
94
115
|
*
|
|
116
|
+
* @category testing
|
|
95
117
|
* @since 4.0.0
|
|
96
118
|
*/
|
|
97
119
|
export function assertTrue(self: unknown, message?: string, ..._: Array<never>): asserts self {
|
|
@@ -101,6 +123,7 @@ export function assertTrue(self: unknown, message?: string, ..._: Array<never>):
|
|
|
101
123
|
/**
|
|
102
124
|
* Asserts that `self` is `false`.
|
|
103
125
|
*
|
|
126
|
+
* @category testing
|
|
104
127
|
* @since 4.0.0
|
|
105
128
|
*/
|
|
106
129
|
export function assertFalse(self: boolean, message?: string, ..._: Array<never>) {
|
|
@@ -110,6 +133,7 @@ export function assertFalse(self: boolean, message?: string, ..._: Array<never>)
|
|
|
110
133
|
/**
|
|
111
134
|
* Asserts that `actual` includes `expected`.
|
|
112
135
|
*
|
|
136
|
+
* @category testing
|
|
113
137
|
* @since 4.0.0
|
|
114
138
|
*/
|
|
115
139
|
export function assertInclude(actual: string | undefined, expected: string, ..._: Array<never>) {
|
|
@@ -123,6 +147,7 @@ export function assertInclude(actual: string | undefined, expected: string, ..._
|
|
|
123
147
|
/**
|
|
124
148
|
* Asserts that `actual` matches `regExp`.
|
|
125
149
|
*
|
|
150
|
+
* @category testing
|
|
126
151
|
* @since 4.0.0
|
|
127
152
|
*/
|
|
128
153
|
export function assertMatch(actual: string, regExp: RegExp, ..._: Array<never>) {
|
|
@@ -132,8 +157,9 @@ export function assertMatch(actual: string, regExp: RegExp, ..._: Array<never>)
|
|
|
132
157
|
}
|
|
133
158
|
|
|
134
159
|
/**
|
|
135
|
-
* Asserts that `thunk` throws an
|
|
160
|
+
* Asserts that `thunk` throws, optionally checking the thrown value against an expected `Error` or validation function.
|
|
136
161
|
*
|
|
162
|
+
* @category testing
|
|
137
163
|
* @since 4.0.0
|
|
138
164
|
*/
|
|
139
165
|
export function throws(thunk: () => void, error?: Error | ((u: unknown) => undefined), ..._: Array<never>) {
|
|
@@ -154,8 +180,9 @@ export function throws(thunk: () => void, error?: Error | ((u: unknown) => undef
|
|
|
154
180
|
}
|
|
155
181
|
|
|
156
182
|
/**
|
|
157
|
-
* Asserts that `thunk` throws an
|
|
183
|
+
* Asserts that `thunk` throws or returns a rejected promise, optionally checking the failure value against an expected `Error` or validation function.
|
|
158
184
|
*
|
|
185
|
+
* @category testing
|
|
159
186
|
* @since 4.0.0
|
|
160
187
|
*/
|
|
161
188
|
export async function throwsAsync(
|
|
@@ -184,6 +211,7 @@ export async function throwsAsync(
|
|
|
184
211
|
/**
|
|
185
212
|
* Asserts that `option` is `None`.
|
|
186
213
|
*
|
|
214
|
+
* @category testing
|
|
187
215
|
* @since 4.0.0
|
|
188
216
|
*/
|
|
189
217
|
export function assertNone<A>(option: Option.Option<A>, ..._: Array<never>): asserts option is Option.None<never> {
|
|
@@ -193,6 +221,7 @@ export function assertNone<A>(option: Option.Option<A>, ..._: Array<never>): ass
|
|
|
193
221
|
/**
|
|
194
222
|
* Asserts that `a` is not `undefined`.
|
|
195
223
|
*
|
|
224
|
+
* @category testing
|
|
196
225
|
* @since 4.0.0
|
|
197
226
|
*/
|
|
198
227
|
export function assertDefined<A>(
|
|
@@ -207,6 +236,7 @@ export function assertDefined<A>(
|
|
|
207
236
|
/**
|
|
208
237
|
* Asserts that `a` is `undefined`.
|
|
209
238
|
*
|
|
239
|
+
* @category testing
|
|
210
240
|
* @since 4.0.0
|
|
211
241
|
*/
|
|
212
242
|
export function assertUndefined<A>(
|
|
@@ -219,8 +249,9 @@ export function assertUndefined<A>(
|
|
|
219
249
|
}
|
|
220
250
|
|
|
221
251
|
/**
|
|
222
|
-
* Asserts that `option` is `Some`.
|
|
252
|
+
* Asserts that `option` is `Some` and contains a value equal to `expected`.
|
|
223
253
|
*
|
|
254
|
+
* @category testing
|
|
224
255
|
* @since 4.0.0
|
|
225
256
|
*/
|
|
226
257
|
export function assertSome<A>(
|
|
@@ -236,8 +267,9 @@ export function assertSome<A>(
|
|
|
236
267
|
// ----------------------------
|
|
237
268
|
|
|
238
269
|
/**
|
|
239
|
-
* Asserts that `result` is `Success`.
|
|
270
|
+
* Asserts that `result` is `Success` and contains a value equal to `expected`.
|
|
240
271
|
*
|
|
272
|
+
* @category testing
|
|
241
273
|
* @since 4.0.0
|
|
242
274
|
*/
|
|
243
275
|
export function assertSuccess<A, E>(
|
|
@@ -249,8 +281,9 @@ export function assertSuccess<A, E>(
|
|
|
249
281
|
}
|
|
250
282
|
|
|
251
283
|
/**
|
|
252
|
-
* Asserts that `result` is `Failure`.
|
|
284
|
+
* Asserts that `result` is `Failure` and contains an error equal to `expected`.
|
|
253
285
|
*
|
|
286
|
+
* @category testing
|
|
254
287
|
* @since 4.0.0
|
|
255
288
|
*/
|
|
256
289
|
export function assertFailure<A, E>(
|
|
@@ -266,8 +299,9 @@ export function assertFailure<A, E>(
|
|
|
266
299
|
// ----------------------------
|
|
267
300
|
|
|
268
301
|
/**
|
|
269
|
-
* Asserts that `exit` is a failure
|
|
302
|
+
* Asserts that `exit` is a failure with a cause equal to `expected`.
|
|
270
303
|
*
|
|
304
|
+
* @category testing
|
|
271
305
|
* @since 4.0.0
|
|
272
306
|
*/
|
|
273
307
|
export function assertExitFailure<A, E>(
|
|
@@ -279,8 +313,9 @@ export function assertExitFailure<A, E>(
|
|
|
279
313
|
}
|
|
280
314
|
|
|
281
315
|
/**
|
|
282
|
-
* Asserts that `exit` is a success
|
|
316
|
+
* Asserts that `exit` is a success with a value equal to `expected`.
|
|
283
317
|
*
|
|
318
|
+
* @category testing
|
|
284
319
|
* @since 4.0.0
|
|
285
320
|
*/
|
|
286
321
|
export function assertExitSuccess<A, E>(
|