Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vitest): "vi" doesn't rely on context #4031

Merged
merged 1 commit into from Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 24 additions & 23 deletions packages/vitest/src/integrations/vi.ts
Expand Up @@ -200,7 +200,7 @@ function createVitest(): VitestUtils {
return stack?.file || ''
}

return {
const utils: VitestUtils = {
useFakeTimers(config?: FakeTimerInstallOpts) {
if (config) {
_timers.configure(config)
Expand All @@ -210,58 +210,58 @@ function createVitest(): VitestUtils {
_timers.configure(workerState.config.fakeTimers)
}
_timers.useFakeTimers()
return this
return utils
},

useRealTimers() {
_timers.useRealTimers()
_mockedDate = null
return this
return utils
},

runOnlyPendingTimers() {
_timers.runOnlyPendingTimers()
return this
return utils
},

async runOnlyPendingTimersAsync() {
await _timers.runOnlyPendingTimersAsync()
return this
return utils
},

runAllTimers() {
_timers.runAllTimers()
return this
return utils
},

async runAllTimersAsync() {
await _timers.runAllTimersAsync()
return this
return utils
},

runAllTicks() {
_timers.runAllTicks()
return this
return utils
},

advanceTimersByTime(ms: number) {
_timers.advanceTimersByTime(ms)
return this
return utils
},

async advanceTimersByTimeAsync(ms: number) {
await _timers.advanceTimersByTimeAsync(ms)
return this
return utils
},

advanceTimersToNextTimer() {
_timers.advanceTimersToNextTimer()
return this
return utils
},

async advanceTimersToNextTimerAsync() {
await _timers.advanceTimersToNextTimerAsync()
return this
return utils
},

getTimerCount() {
Expand All @@ -272,7 +272,7 @@ function createVitest(): VitestUtils {
const date = time instanceof Date ? time : new Date(time)
_mockedDate = date
_timers.setSystemTime(date)
return this
return utils
},

getMockedSystemTime() {
Expand All @@ -285,7 +285,7 @@ function createVitest(): VitestUtils {

clearAllTimers() {
_timers.clearAllTimers()
return this
return utils
},

// mocks
Expand Down Expand Up @@ -337,17 +337,17 @@ function createVitest(): VitestUtils {

clearAllMocks() {
spies.forEach(spy => spy.mockClear())
return this
return utils
},

resetAllMocks() {
spies.forEach(spy => spy.mockReset())
return this
return utils
},

restoreAllMocks() {
spies.forEach(spy => spy.mockRestore())
return this
return utils
},

stubGlobal(name: string | symbol | number, value: any) {
Expand All @@ -359,14 +359,14 @@ function createVitest(): VitestUtils {
configurable: true,
enumerable: true,
})
return this
return utils
},

stubEnv(name: string, value: string) {
if (!_stubsEnv.has(name))
_stubsEnv.set(name, process.env[name])
process.env[name] = value
return this
return utils
},

unstubAllGlobals() {
Expand All @@ -377,7 +377,7 @@ function createVitest(): VitestUtils {
Object.defineProperty(globalThis, name, original)
})
_stubsGlobal.clear()
return this
return utils
},

unstubAllEnvs() {
Expand All @@ -388,13 +388,13 @@ function createVitest(): VitestUtils {
process.env[name] = original
})
_stubsEnv.clear()
return this
return utils
},

resetModules() {
const state = getWorkerState()
resetModules(state.moduleCache)
return this
return utils
},

async dynamicImportSettled() {
Expand All @@ -414,8 +414,9 @@ function createVitest(): VitestUtils {
Object.assign(state.config, _config)
}
},

}

return utils
}

export const vitest = createVitest()
Expand Down