Skip to content

Commit

Permalink
fix: change to promise union type
Browse files Browse the repository at this point in the history
  • Loading branch information
syi0808 committed Jul 23, 2024
1 parent e441e4a commit c30f0fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 1 addition & 5 deletions packages/vitest/src/integrations/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assertTypes, createSimpleStackTrace } from '@vitest/utils'
import { parseSingleStack } from '../utils/source-map'
import type { VitestMocker } from '../runtime/mocker'
import type { ResolvedConfig, RuntimeConfig } from '../types'
import type { MockFactoryWithHelper, PromiseMockFactoryWithHelper } from '../types/mocker'
import type { MockFactoryWithHelper } from '../types/mocker'
import { getWorkerState } from '../utils/global'
import { resetModules, waitForImportsToResolve } from '../utils/modules'
import { isChildProcess } from '../utils/base'
Expand Down Expand Up @@ -194,8 +194,6 @@ export interface VitestUtils {
mock(path: string, factory?: MockFactoryWithHelper): void
// eslint-disable-next-line ts/method-signature-style
mock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T>): void
// eslint-disable-next-line ts/method-signature-style
mock<T>(module: Promise<T>, factory?: PromiseMockFactoryWithHelper<T>): void

/**
* Removes module from mocked registry. All calls to import will return the original module even if it was mocked before.
Expand All @@ -221,8 +219,6 @@ export interface VitestUtils {
doMock(path: string, factory?: MockFactoryWithHelper): void
// eslint-disable-next-line ts/method-signature-style
doMock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T>): void
// eslint-disable-next-line ts/method-signature-style
doMock<T>(module: Promise<T>, factory?: PromiseMockFactoryWithHelper<T>): void
/**
* Removes module from mocked registry. All subsequent calls to import will return original module.
*
Expand Down
7 changes: 3 additions & 4 deletions packages/vitest/src/types/mocker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
type Promisable<T> = T | Promise<T>

export type MockFactoryWithHelper<M = unknown> = (
importOriginal: <T extends M = M>() => Promise<T>
) => Record<keyof M, any> | null
export type PromiseMockFactoryWithHelper<M = unknown> = (
importOriginal: <T extends M = M>() => Promise<T>
) => Promise<Record<keyof M, any>> | null
) => Promisable<Record<keyof M, any> | null>
export type MockFactory = () => any

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

0 comments on commit c30f0fc

Please sign in to comment.