Skip to content

Commit 0d0f35f

Browse files
authored
fix(vitest): "vi" doesn't rely on context (#4031)
1 parent 9f04386 commit 0d0f35f

File tree

1 file changed

+24
-23
lines changed
  • packages/vitest/src/integrations

1 file changed

+24
-23
lines changed

packages/vitest/src/integrations/vi.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function createVitest(): VitestUtils {
200200
return stack?.file || ''
201201
}
202202

203-
return {
203+
const utils: VitestUtils = {
204204
useFakeTimers(config?: FakeTimerInstallOpts) {
205205
if (config) {
206206
_timers.configure(config)
@@ -210,58 +210,58 @@ function createVitest(): VitestUtils {
210210
_timers.configure(workerState.config.fakeTimers)
211211
}
212212
_timers.useFakeTimers()
213-
return this
213+
return utils
214214
},
215215

216216
useRealTimers() {
217217
_timers.useRealTimers()
218218
_mockedDate = null
219-
return this
219+
return utils
220220
},
221221

222222
runOnlyPendingTimers() {
223223
_timers.runOnlyPendingTimers()
224-
return this
224+
return utils
225225
},
226226

227227
async runOnlyPendingTimersAsync() {
228228
await _timers.runOnlyPendingTimersAsync()
229-
return this
229+
return utils
230230
},
231231

232232
runAllTimers() {
233233
_timers.runAllTimers()
234-
return this
234+
return utils
235235
},
236236

237237
async runAllTimersAsync() {
238238
await _timers.runAllTimersAsync()
239-
return this
239+
return utils
240240
},
241241

242242
runAllTicks() {
243243
_timers.runAllTicks()
244-
return this
244+
return utils
245245
},
246246

247247
advanceTimersByTime(ms: number) {
248248
_timers.advanceTimersByTime(ms)
249-
return this
249+
return utils
250250
},
251251

252252
async advanceTimersByTimeAsync(ms: number) {
253253
await _timers.advanceTimersByTimeAsync(ms)
254-
return this
254+
return utils
255255
},
256256

257257
advanceTimersToNextTimer() {
258258
_timers.advanceTimersToNextTimer()
259-
return this
259+
return utils
260260
},
261261

262262
async advanceTimersToNextTimerAsync() {
263263
await _timers.advanceTimersToNextTimerAsync()
264-
return this
264+
return utils
265265
},
266266

267267
getTimerCount() {
@@ -272,7 +272,7 @@ function createVitest(): VitestUtils {
272272
const date = time instanceof Date ? time : new Date(time)
273273
_mockedDate = date
274274
_timers.setSystemTime(date)
275-
return this
275+
return utils
276276
},
277277

278278
getMockedSystemTime() {
@@ -285,7 +285,7 @@ function createVitest(): VitestUtils {
285285

286286
clearAllTimers() {
287287
_timers.clearAllTimers()
288-
return this
288+
return utils
289289
},
290290

291291
// mocks
@@ -337,17 +337,17 @@ function createVitest(): VitestUtils {
337337

338338
clearAllMocks() {
339339
spies.forEach(spy => spy.mockClear())
340-
return this
340+
return utils
341341
},
342342

343343
resetAllMocks() {
344344
spies.forEach(spy => spy.mockReset())
345-
return this
345+
return utils
346346
},
347347

348348
restoreAllMocks() {
349349
spies.forEach(spy => spy.mockRestore())
350-
return this
350+
return utils
351351
},
352352

353353
stubGlobal(name: string | symbol | number, value: any) {
@@ -359,14 +359,14 @@ function createVitest(): VitestUtils {
359359
configurable: true,
360360
enumerable: true,
361361
})
362-
return this
362+
return utils
363363
},
364364

365365
stubEnv(name: string, value: string) {
366366
if (!_stubsEnv.has(name))
367367
_stubsEnv.set(name, process.env[name])
368368
process.env[name] = value
369-
return this
369+
return utils
370370
},
371371

372372
unstubAllGlobals() {
@@ -377,7 +377,7 @@ function createVitest(): VitestUtils {
377377
Object.defineProperty(globalThis, name, original)
378378
})
379379
_stubsGlobal.clear()
380-
return this
380+
return utils
381381
},
382382

383383
unstubAllEnvs() {
@@ -388,13 +388,13 @@ function createVitest(): VitestUtils {
388388
process.env[name] = original
389389
})
390390
_stubsEnv.clear()
391-
return this
391+
return utils
392392
},
393393

394394
resetModules() {
395395
const state = getWorkerState()
396396
resetModules(state.moduleCache)
397-
return this
397+
return utils
398398
},
399399

400400
async dynamicImportSettled() {
@@ -414,8 +414,9 @@ function createVitest(): VitestUtils {
414414
Object.assign(state.config, _config)
415415
}
416416
},
417-
418417
}
418+
419+
return utils
419420
}
420421

421422
export const vitest = createVitest()

0 commit comments

Comments
 (0)