Skip to content

Commit c30f0fc

Browse files
committed
fix: change to promise union type
1 parent e441e4a commit c30f0fc

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

packages/vitest/src/integrations/vi.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { assertTypes, createSimpleStackTrace } from '@vitest/utils'
33
import { parseSingleStack } from '../utils/source-map'
44
import type { VitestMocker } from '../runtime/mocker'
55
import type { ResolvedConfig, RuntimeConfig } from '../types'
6-
import type { MockFactoryWithHelper, PromiseMockFactoryWithHelper } from '../types/mocker'
6+
import type { MockFactoryWithHelper } from '../types/mocker'
77
import { getWorkerState } from '../utils/global'
88
import { resetModules, waitForImportsToResolve } from '../utils/modules'
99
import { isChildProcess } from '../utils/base'
@@ -194,8 +194,6 @@ export interface VitestUtils {
194194
mock(path: string, factory?: MockFactoryWithHelper): void
195195
// eslint-disable-next-line ts/method-signature-style
196196
mock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T>): void
197-
// eslint-disable-next-line ts/method-signature-style
198-
mock<T>(module: Promise<T>, factory?: PromiseMockFactoryWithHelper<T>): void
199197

200198
/**
201199
* Removes module from mocked registry. All calls to import will return the original module even if it was mocked before.
@@ -221,8 +219,6 @@ export interface VitestUtils {
221219
doMock(path: string, factory?: MockFactoryWithHelper): void
222220
// eslint-disable-next-line ts/method-signature-style
223221
doMock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T>): void
224-
// eslint-disable-next-line ts/method-signature-style
225-
doMock<T>(module: Promise<T>, factory?: PromiseMockFactoryWithHelper<T>): void
226222
/**
227223
* Removes module from mocked registry. All subsequent calls to import will return original module.
228224
*

packages/vitest/src/types/mocker.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
type Promisable<T> = T | Promise<T>
2+
13
export type MockFactoryWithHelper<M = unknown> = (
24
importOriginal: <T extends M = M>() => Promise<T>
3-
) => Record<keyof M, any> | null
4-
export type PromiseMockFactoryWithHelper<M = unknown> = (
5-
importOriginal: <T extends M = M>() => Promise<T>
6-
) => Promise<Record<keyof M, any>> | null
5+
) => Promisable<Record<keyof M, any> | null>
76
export type MockFactory = () => any
87

98
export type MockMap = Map<string, Record<string, string | null | MockFactory>>

0 commit comments

Comments
 (0)