Skip to content

Commit eb40a6a

Browse files
committedApr 15, 2024
fix(e2e): improve types for fetch and mockLogger
1 parent 87db2e0 commit eb40a6a

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed
 

‎src/core/mock.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { consola } from 'consola'
2+
import type { LogType } from 'consola'
23
import { useTestContext } from './context'
34

45
export function mockFn () {
56
const ctx = useTestContext()
67
return ctx.mockFn
78
}
89

9-
export function mockLogger (): Record<string, Function> {
10-
const mocks: any = {}
10+
export function mockLogger (): Record<LogType, (...args: any[]) => void> {
11+
const mocks: Partial<Record<LogType, (...args: any[]) => void>> = {}
1112
consola.mockTypes((type) => {
1213
mocks[type] = mockFn()
13-
return mocks[type]
14+
return mocks[type]!
1415
})
15-
return mocks
16+
return mocks as Record<LogType, (...args: any[]) => void>
1617
}

‎src/core/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function stopServer () {
7373
}
7474
}
7575

76-
export function fetch (path: string, options?: any) {
76+
export function fetch (path: string, options?: RequestInit) {
7777
return _fetch(url(path), options)
7878
}
7979

‎src/core/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface TestContext {
3232
browser?: Browser
3333
url?: string
3434
serverProcess?: ExecaChildProcess
35-
mockFn?: Function
35+
mockFn?: (...args: any[]) => unknown
3636
/**
3737
* Functions to run on the vitest `afterAll` hook.
3838
* Useful for removing anything created during the test.

0 commit comments

Comments
 (0)