@effect/vitest 4.0.0-beta.66 → 4.0.0-beta.68

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.js CHANGED
@@ -11,30 +11,34 @@ import { assert as vassert } from "vitest";
11
11
  /**
12
12
  * Throws an `AssertionError` with the provided error message.
13
13
  *
14
+ * @category testing
14
15
  * @since 4.0.0
15
16
  */
16
17
  export function fail(message) {
17
18
  assert.fail(message);
18
19
  }
19
20
  /**
20
- * Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
21
+ * Asserts that `actual` is deeply strictly equal to `expected` using Node's `assert.deepStrictEqual`.
21
22
  *
23
+ * @category testing
22
24
  * @since 4.0.0
23
25
  */
24
26
  export function deepStrictEqual(actual, expected, message, ..._) {
25
27
  assert.deepStrictEqual(actual, expected, message);
26
28
  }
27
29
  /**
28
- * Asserts that `actual` is not equal to `expected` using the `Equal.equals` trait.
30
+ * Asserts that `actual` is not deeply strictly equal to `expected` using Node's `assert.notDeepStrictEqual`.
29
31
  *
32
+ * @category testing
30
33
  * @since 4.0.0
31
34
  */
32
35
  export function notDeepStrictEqual(actual, expected, message, ..._) {
33
36
  assert.notDeepStrictEqual(actual, expected, message);
34
37
  }
35
38
  /**
36
- * Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
39
+ * Asserts that `actual` is strictly equal to `expected` using Node's `assert.strictEqual`.
37
40
  *
41
+ * @category testing
38
42
  * @since 4.0.0
39
43
  */
40
44
  export function strictEqual(actual, expected, message, ..._) {
@@ -43,6 +47,7 @@ export function strictEqual(actual, expected, message, ..._) {
43
47
  /**
44
48
  * Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
45
49
  *
50
+ * @category testing
46
51
  * @since 4.0.0
47
52
  */
48
53
  export function assertEquals(actual, expected, message, ..._) {
@@ -54,6 +59,7 @@ export function assertEquals(actual, expected, message, ..._) {
54
59
  /**
55
60
  * Asserts that `thunk` does not throw an error.
56
61
  *
62
+ * @category testing
57
63
  * @since 4.0.0
58
64
  */
59
65
  export function doesNotThrow(thunk, message, ..._) {
@@ -65,6 +71,7 @@ export function doesNotThrow(thunk, message, ..._) {
65
71
  /**
66
72
  * Asserts that `value` is an instance of `constructor`.
67
73
  *
74
+ * @category testing
68
75
  * @since 4.0.0
69
76
  */
70
77
  export function assertInstanceOf(value, constructor, message, ..._) {
@@ -73,6 +80,7 @@ export function assertInstanceOf(value, constructor, message, ..._) {
73
80
  /**
74
81
  * Asserts that `self` is `true`.
75
82
  *
83
+ * @category testing
76
84
  * @since 4.0.0
77
85
  */
78
86
  export function assertTrue(self, message, ..._) {
@@ -81,6 +89,7 @@ export function assertTrue(self, message, ..._) {
81
89
  /**
82
90
  * Asserts that `self` is `false`.
83
91
  *
92
+ * @category testing
84
93
  * @since 4.0.0
85
94
  */
86
95
  export function assertFalse(self, message, ..._) {
@@ -89,6 +98,7 @@ export function assertFalse(self, message, ..._) {
89
98
  /**
90
99
  * Asserts that `actual` includes `expected`.
91
100
  *
101
+ * @category testing
92
102
  * @since 4.0.0
93
103
  */
94
104
  export function assertInclude(actual, expected, ..._) {
@@ -101,6 +111,7 @@ export function assertInclude(actual, expected, ..._) {
101
111
  /**
102
112
  * Asserts that `actual` matches `regExp`.
103
113
  *
114
+ * @category testing
104
115
  * @since 4.0.0
105
116
  */
106
117
  export function assertMatch(actual, regExp, ..._) {
@@ -109,8 +120,9 @@ export function assertMatch(actual, regExp, ..._) {
109
120
  }
110
121
  }
111
122
  /**
112
- * Asserts that `thunk` throws an error.
123
+ * Asserts that `thunk` throws, optionally checking the thrown value against an expected `Error` or validation function.
113
124
  *
125
+ * @category testing
114
126
  * @since 4.0.0
115
127
  */
116
128
  export function throws(thunk, error, ..._) {
@@ -130,8 +142,9 @@ export function throws(thunk, error, ..._) {
130
142
  }
131
143
  }
132
144
  /**
133
- * Asserts that `thunk` throws an error.
145
+ * Asserts that `thunk` throws or returns a rejected promise, optionally checking the failure value against an expected `Error` or validation function.
134
146
  *
147
+ * @category testing
135
148
  * @since 4.0.0
136
149
  */
137
150
  export async function throwsAsync(thunk, error, ..._) {
@@ -154,6 +167,7 @@ export async function throwsAsync(thunk, error, ..._) {
154
167
  /**
155
168
  * Asserts that `option` is `None`.
156
169
  *
170
+ * @category testing
157
171
  * @since 4.0.0
158
172
  */
159
173
  export function assertNone(option, ..._) {
@@ -162,6 +176,7 @@ export function assertNone(option, ..._) {
162
176
  /**
163
177
  * Asserts that `a` is not `undefined`.
164
178
  *
179
+ * @category testing
165
180
  * @since 4.0.0
166
181
  */
167
182
  export function assertDefined(a, ..._) {
@@ -172,6 +187,7 @@ export function assertDefined(a, ..._) {
172
187
  /**
173
188
  * Asserts that `a` is `undefined`.
174
189
  *
190
+ * @category testing
175
191
  * @since 4.0.0
176
192
  */
177
193
  export function assertUndefined(a, ..._) {
@@ -180,8 +196,9 @@ export function assertUndefined(a, ..._) {
180
196
  }
181
197
  }
182
198
  /**
183
- * Asserts that `option` is `Some`.
199
+ * Asserts that `option` is `Some` and contains a value equal to `expected`.
184
200
  *
201
+ * @category testing
185
202
  * @since 4.0.0
186
203
  */
187
204
  export function assertSome(option, expected, ..._) {
@@ -191,16 +208,18 @@ export function assertSome(option, expected, ..._) {
191
208
  // Result
192
209
  // ----------------------------
193
210
  /**
194
- * Asserts that `result` is `Success`.
211
+ * Asserts that `result` is `Success` and contains a value equal to `expected`.
195
212
  *
213
+ * @category testing
196
214
  * @since 4.0.0
197
215
  */
198
216
  export function assertSuccess(result, expected, ..._) {
199
217
  deepStrictEqual(result, Result.succeed(expected));
200
218
  }
201
219
  /**
202
- * Asserts that `result` is `Failure`.
220
+ * Asserts that `result` is `Failure` and contains an error equal to `expected`.
203
221
  *
222
+ * @category testing
204
223
  * @since 4.0.0
205
224
  */
206
225
  export function assertFailure(result, expected, ..._) {
@@ -210,16 +229,18 @@ export function assertFailure(result, expected, ..._) {
210
229
  // Exit
211
230
  // ----------------------------
212
231
  /**
213
- * Asserts that `exit` is a failure.
232
+ * Asserts that `exit` is a failure with a cause equal to `expected`.
214
233
  *
234
+ * @category testing
215
235
  * @since 4.0.0
216
236
  */
217
237
  export function assertExitFailure(exit, expected, ..._) {
218
238
  deepStrictEqual(exit, Exit.failCause(expected));
219
239
  }
220
240
  /**
221
- * Asserts that `exit` is a success.
241
+ * Asserts that `exit` is a success with a value equal to `expected`.
222
242
  *
243
+ * @category testing
223
244
  * @since 4.0.0
224
245
  */
225
246
  export function assertExitSuccess(exit, expected, ..._) {
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["Equal","Exit","Option","Predicate","Result","assert","vassert","fail","message","deepStrictEqual","actual","expected","_","notDeepStrictEqual","strictEqual","assertEquals","equals","doesNotThrow","thunk","assertInstanceOf","value","constructor","instanceOf","assertTrue","self","assertFalse","assertInclude","includes","assertMatch","regExp","test","throws","error","e","undefined","isFunction","throwsAsync","assertNone","option","none","assertDefined","a","assertUndefined","assertSome","some","assertSuccess","result","succeed","assertFailure","assertExitFailure","exit","failCause","assertExitSuccess"],"sources":["../src/utils.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,aAAa;AACrC,SAASA,MAAM,IAAIC,OAAO,QAAQ,QAAQ;AAE1C;AACA;AACA;AAEA;;;;;AAKA,OAAM,SAAUC,IAAIA,CAACC,OAAe;EAClCH,MAAM,CAACE,IAAI,CAACC,OAAO,CAAC;AACtB;AAEA;;;;;AAKA,OAAM,SAAUC,eAAeA,CAAIC,MAAS,EAAEC,QAAW,EAAEH,OAAgB,EAAE,GAAGI,CAAe;EAC7FP,MAAM,CAACI,eAAe,CAACC,MAAM,EAAEC,QAAQ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;AAChD;AAEA;AACA;AACA;AAEA;;;;;AAKA,OAAM,SAAUsC,iBAAiBA,CAC/BC,IAAqB,EACrBvC,QAAwB,EACxB,GAAGC,CAAe;EAElBH,eAAe,CAACyC,IAAI,EAAEjD,IAAI,CAACkD,SAAS,CAACxC,QAAQ,CAAC,CAAC;AACjD;AAEA;;;;;AAKA,OAAM,SAAUyC,iBAAiBA,CAC/BF,IAAqB,EACrBvC,QAAW,EACX,GAAGC,CAAe;EAElBH,eAAe,CAACyC,IAAI,EAAEjD,IAAI,CAAC8C,OAAO,CAACpC,QAAQ,CAAC,CAAC;AAC/C","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","names":["Equal","Exit","Option","Predicate","Result","assert","vassert","fail","message","deepStrictEqual","actual","expected","_","notDeepStrictEqual","strictEqual","assertEquals","equals","doesNotThrow","thunk","assertInstanceOf","value","constructor","instanceOf","assertTrue","self","assertFalse","assertInclude","includes","assertMatch","regExp","test","throws","error","e","undefined","isFunction","throwsAsync","assertNone","option","none","assertDefined","a","assertUndefined","assertSome","some","assertSuccess","result","succeed","assertFailure","assertExitFailure","exit","failCause","assertExitSuccess"],"sources":["../src/utils.ts"],"sourcesContent":[null],"mappings":"AAkBA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,aAAa;AACrC,SAASA,MAAM,IAAIC,OAAO,QAAQ,QAAQ;AAE1C;AACA;AACA;AAEA;;;;;;AAMA,OAAM,SAAUC,IAAIA,CAACC,OAAe;EAClCH,MAAM,CAACE,IAAI,CAACC,OAAO,CAAC;AACtB;AAEA;;;;;;AAMA,OAAM,SAAUC,eAAeA,CAAIC,MAAS,EAAEC,QAAW,EAAEH,OAAgB,EAAE,GAAGI,CAA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BH,eAAe,CAACqC,MAAM,EAAE1C,MAAM,CAACG,IAAI,CAACI,QAAQ,CAAC,CAAC;AAChD;AAEA;AACA;AACA;AAEA;;;;;;AAMA,OAAM,SAAUsC,iBAAiBA,CAC/BC,IAAqB,EACrBvC,QAAwB,EACxB,GAAGC,CAAe;EAElBH,eAAe,CAACyC,IAAI,EAAEjD,IAAI,CAACkD,SAAS,CAACxC,QAAQ,CAAC,CAAC;AACjD;AAEA;;;;;;AAMA,OAAM,SAAUyC,iBAAiBA,CAC/BF,IAAqB,EACrBvC,QAAW,EACX,GAAGC,CAAe;EAElBH,eAAe,CAACyC,IAAI,EAAEjD,IAAI,CAAC8C,OAAO,CAACpC,QAAQ,CAAC,CAAC;AAC/C","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/vitest",
3
- "version": "4.0.0-beta.66",
3
+ "version": "4.0.0-beta.68",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A set of helpers for testing Effects with vitest",
@@ -34,12 +34,13 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "vitest": "^3.0.0 || ^4.0.0",
37
- "effect": "^4.0.0-beta.66"
37
+ "effect": "^4.0.0-beta.68"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/node": "^25.6.0",
40
+ "@types/node": "^25.7.0",
41
+ "@vitest/runner": "4.1.4",
41
42
  "vitest": "4.1.4",
42
- "effect": "^4.0.0-beta.66"
43
+ "effect": "^4.0.0-beta.68"
43
44
  },
44
45
  "scripts": {
45
46
  "build": "tsc -b tsconfig.json && pnpm babel",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  import type * as Duration from "effect/Duration"
5
5
  import type * as Effect from "effect/Effect"
@@ -11,28 +11,28 @@ import * as V from "vitest"
11
11
  import * as internal from "./internal/internal.ts"
12
12
 
13
13
  /**
14
- * @since 1.0.0
14
+ * @since 4.0.0
15
15
  */
16
16
  export * from "vitest"
17
17
 
18
18
  /**
19
- * @since 1.0.0
19
+ * @since 4.0.0
20
20
  */
21
21
  export type API = V.TestAPI<{}>
22
22
 
23
23
  /**
24
- * @since 1.0.0
24
+ * @since 4.0.0
25
25
  */
26
26
  export namespace Vitest {
27
27
  /**
28
- * @since 1.0.0
28
+ * @since 4.0.0
29
29
  */
30
30
  export interface TestFunction<A, E, R, TestArgs extends Array<any>> {
31
31
  (...args: TestArgs): Effect.Effect<A, E, R>
32
32
  }
33
33
 
34
34
  /**
35
- * @since 1.0.0
35
+ * @since 4.0.0
36
36
  */
37
37
  export interface Test<R> {
38
38
  <A, E>(
@@ -43,14 +43,14 @@ export namespace Vitest {
43
43
  }
44
44
 
45
45
  /**
46
- * @since 1.0.0
46
+ * @since 4.0.0
47
47
  */
48
48
  export type Arbitraries =
49
49
  | Array<Schema.Schema<any> | FC.Arbitrary<any>>
50
50
  | { [K in string]: Schema.Schema<any> | FC.Arbitrary<any> }
51
51
 
52
52
  /**
53
- * @since 1.0.0
53
+ * @since 4.0.0
54
54
  */
55
55
  export interface Tester<R> extends Vitest.Test<R> {
56
56
  skip: Vitest.Test<R>
@@ -63,7 +63,7 @@ export namespace Vitest {
63
63
  fails: Vitest.Test<R>
64
64
 
65
65
  /**
66
- * @since 1.0.0
66
+ * @since 4.0.0
67
67
  */
68
68
  prop: <const Arbs extends Arbitraries, A, E>(
69
69
  name: string,
@@ -95,7 +95,7 @@ export namespace Vitest {
95
95
  }
96
96
 
97
97
  /**
98
- * @since 1.0.0
98
+ * @since 4.0.0
99
99
  */
100
100
  export interface MethodsNonLive<R = never> extends API {
101
101
  readonly effect: Vitest.Tester<R | Scope.Scope>
@@ -114,7 +114,7 @@ export namespace Vitest {
114
114
  }
115
115
 
116
116
  /**
117
- * @since 1.0.0
117
+ * @since 4.0.0
118
118
  */
119
119
  readonly prop: <const Arbs extends Arbitraries>(
120
120
  name: string,
@@ -140,7 +140,7 @@ export namespace Vitest {
140
140
  }
141
141
 
142
142
  /**
143
- * @since 1.0.0
143
+ * @since 4.0.0
144
144
  */
145
145
  export interface Methods<R = never> extends MethodsNonLive<R> {
146
146
  readonly live: Vitest.Tester<Scope.Scope | R>
@@ -159,17 +159,17 @@ export namespace Vitest {
159
159
  }
160
160
 
161
161
  /**
162
- * @since 1.0.0
162
+ * @since 4.0.0
163
163
  */
164
164
  export const addEqualityTesters: () => void = internal.addEqualityTesters
165
165
 
166
166
  /**
167
- * @since 1.0.0
167
+ * @since 4.0.0
168
168
  */
169
169
  export const effect: Vitest.Tester<Scope.Scope> = internal.effect
170
170
 
171
171
  /**
172
- * @since 1.0.0
172
+ * @since 4.0.0
173
173
  */
174
174
  export const live: Vitest.Tester<Scope.Scope> = internal.live
175
175
 
@@ -177,7 +177,7 @@ export const live: Vitest.Tester<Scope.Scope> = internal.live
177
177
  * Share a `Layer` between multiple tests, optionally wrapping
178
178
  * the tests in a `describe` block if a name is provided.
179
179
  *
180
- * @since 1.0.0
180
+ * @since 4.0.0
181
181
  *
182
182
  * ```ts
183
183
  * import { expect, layer } from "@effect/vitest"
@@ -226,7 +226,7 @@ export const layer: <R, E>(
226
226
  } = internal.layer
227
227
 
228
228
  /**
229
- * @since 1.0.0
229
+ * @since 4.0.0
230
230
  */
231
231
  export const flakyTest: <A, E, R>(
232
232
  self: Effect.Effect<A, E, R | Scope.Scope>,
@@ -234,29 +234,26 @@ export const flakyTest: <A, E, R>(
234
234
  ) => Effect.Effect<A, never, R> = internal.flakyTest
235
235
 
236
236
  /**
237
- * @since 1.0.0
237
+ * @since 4.0.0
238
238
  */
239
239
  export const prop: Vitest.Methods["prop"] = internal.prop
240
240
 
241
241
  /**
242
- * @since 1.0.0
242
+ * @since 4.0.0
243
243
  */
244
244
 
245
- /** @ignored */
246
- const methods = { effect, live, flakyTest, layer, prop } as const
247
-
248
245
  /**
249
- * @since 1.0.0
246
+ * @since 4.0.0
250
247
  */
251
- export const it: Vitest.Methods = Object.assign(V.it, methods)
248
+ export const it: Vitest.Methods = internal.makeMethods(V.it)
252
249
 
253
250
  /**
254
- * @since 1.0.0
251
+ * @since 4.0.0
255
252
  */
256
253
  export const makeMethods: (it: V.TestAPI) => Vitest.Methods = internal.makeMethods
257
254
 
258
255
  /**
259
- * @since 1.0.0
256
+ * @since 4.0.0
260
257
  */
261
258
  export const describeWrapped: (name: string, f: (it: Vitest.Methods) => void) => V.SuiteCollector =
262
259
  internal.describeWrapped
@@ -1,7 +1,8 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
+ import { getCurrentSuite } from "@vitest/runner"
5
6
  import * as Cause from "effect/Cause"
6
7
  import * as Duration from "effect/Duration"
7
8
  import * as Effect from "effect/Effect"
@@ -48,6 +49,44 @@ export const addEqualityTesters = () => {
48
49
  /** @internal */
49
50
  const testOptions = (timeout?: number | V.TestOptions) => typeof timeout === "number" ? { timeout } : timeout ?? {}
50
51
 
52
+ const hookTimeout = (timeout?: Duration.Input) =>
53
+ timeout === undefined ? undefined : Duration.toMillis(Duration.fromInputUnsafe(timeout))
54
+
55
+ const makeItProxy = <Methods extends object>(
56
+ it: V.TestAPI,
57
+ overrides: Methods
58
+ ): Methods & V.TestAPI =>
59
+ new Proxy(it as Methods & V.TestAPI, {
60
+ apply(target, thisArg, argArray) {
61
+ return Reflect.apply(target, thisArg, argArray)
62
+ },
63
+ get(target, property, receiver) {
64
+ if (property in overrides) {
65
+ return Reflect.get(overrides, property)
66
+ }
67
+ const value = Reflect.get(target, property, receiver)
68
+ return typeof value === "function" ? value.bind(target) : value
69
+ }
70
+ })
71
+
72
+ type CollectedTask = {
73
+ readonly type: string
74
+ readonly mode?: string
75
+ readonly tasks?: ReadonlyArray<CollectedTask>
76
+ }
77
+
78
+ const collectTasks = (tasks: ReadonlyArray<CollectedTask>, acc: Array<V.TestContext["task"]> = []) => {
79
+ for (let i = 0; i < tasks.length; i++) {
80
+ const task = tasks[i]
81
+ if (task.type === "test" && task.mode !== "skip" && task.mode !== "todo") {
82
+ acc.push(task as V.TestContext["task"])
83
+ } else if (task.tasks !== undefined) {
84
+ collectTasks(task.tasks, acc)
85
+ }
86
+ }
87
+ return acc
88
+ }
89
+
51
90
  /** @internal */
52
91
  const makeTester = <R>(
53
92
  mapEffect: <A, E>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, never>,
@@ -207,9 +246,17 @@ export const layer = <R, E>(
207
246
  Effect.cached,
208
247
  Effect.runSync
209
248
  )
249
+ let closed = false
250
+ const closeScope = (ctx?: Vitest.TestContext) => {
251
+ if (closed) {
252
+ return Promise.resolve()
253
+ }
254
+ closed = true
255
+ return runPromise(Scope.close(scope, Exit.void), ctx)
256
+ }
210
257
 
211
258
  const makeIt = (it: V.TestAPI): Vitest.Vitest.MethodsNonLive<R> =>
212
- Object.assign(it, {
259
+ makeItProxy(it, {
213
260
  effect: makeTester<R | Scope.Scope>(
214
261
  (effect) =>
215
262
  Effect.flatMap(contextEffect, (context) =>
@@ -224,30 +271,58 @@ export const layer = <R, E>(
224
271
  layer<R2, E2>(nestedLayer: Layer.Layer<R2, E2, R>, options?: {
225
272
  readonly timeout?: Duration.Input
226
273
  }) {
227
- return layer(Layer.provideMerge(nestedLayer, withTestEnv), { ...options, memoMap, excludeTestServices })
274
+ return layer(Layer.provideMerge(nestedLayer, withTestEnv), {
275
+ ...options,
276
+ memoMap: Layer.forkMemoMapUnsafe(memoMap),
277
+ excludeTestServices
278
+ })
228
279
  }
229
280
  })
230
281
 
231
282
  if (args.length === 1) {
232
- V.beforeAll(
233
- () => runPromise(Effect.asVoid(contextEffect)),
234
- options?.timeout ? Duration.toMillis(Duration.fromInputUnsafe(options.timeout)) : undefined
283
+ const currentSuite = getCurrentSuite()
284
+ const previousTasks = new Set(currentSuite.tasks)
285
+
286
+ args[0](makeIt(V.it))
287
+
288
+ const blockTasks = collectTasks(
289
+ currentSuite.tasks.filter((task) => !previousTasks.has(task)) as ReadonlyArray<CollectedTask>
235
290
  )
236
- V.afterAll(
237
- () => runPromise(Scope.close(scope, Exit.void)),
238
- options?.timeout ? Duration.toMillis(Duration.fromInputUnsafe(options.timeout)) : undefined
291
+ if (blockTasks.length === 0) {
292
+ V.afterAll(() => closeScope(), hookTimeout(options?.timeout))
293
+ return
294
+ }
295
+
296
+ const blockTaskSet = new Set(blockTasks)
297
+ let remaining = blockTasks.length
298
+
299
+ V.beforeEach(
300
+ (ctx) => {
301
+ if (!blockTaskSet.has(ctx.task)) {
302
+ return
303
+ }
304
+ ctx.onTestFinished(() => {
305
+ remaining--
306
+ if (remaining === 0) {
307
+ return closeScope(ctx)
308
+ }
309
+ })
310
+ return runPromise(Effect.asVoid(contextEffect), ctx)
311
+ },
312
+ hookTimeout(options?.timeout)
239
313
  )
240
- return args[0](makeIt(V.it))
314
+ V.afterAll(() => closeScope(), hookTimeout(options?.timeout))
315
+ return
241
316
  }
242
317
 
243
318
  return V.describe(args[0], () => {
244
319
  V.beforeAll(
245
320
  () => runPromise(Effect.asVoid(contextEffect)),
246
- options?.timeout ? Duration.toMillis(Duration.fromInputUnsafe(options.timeout)) : undefined
321
+ hookTimeout(options?.timeout)
247
322
  )
248
323
  V.afterAll(
249
- () => runPromise(Scope.close(scope, Exit.void)),
250
- options?.timeout ? Duration.toMillis(Duration.fromInputUnsafe(options.timeout)) : undefined
324
+ () => closeScope(),
325
+ hookTimeout(options?.timeout)
251
326
  )
252
327
  return args[1](makeIt(V.it))
253
328
  })
@@ -278,7 +353,7 @@ export const flakyTest = <A, E, R>(
278
353
 
279
354
  /** @internal */
280
355
  export const makeMethods = (it: V.TestAPI): Vitest.Vitest.Methods =>
281
- Object.assign(it, {
356
+ makeItProxy(it, {
282
357
  effect: makeTester<Scope.Scope>(flow(Effect.scoped, Effect.provide(TestEnv)), it),
283
358
  live: makeTester<Scope.Scope>(Effect.scoped, it),
284
359
  flakyTest,