Skip to content

Commit

Permalink
fix(e2e): improve types for fetch and mockLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Apr 15, 2024
1 parent 87db2e0 commit eb40a6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/core/mock.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { consola } from 'consola'
import type { LogType } from 'consola'
import { useTestContext } from './context'

export function mockFn () {
const ctx = useTestContext()
return ctx.mockFn
}

export function mockLogger (): Record<string, Function> {
const mocks: any = {}
export function mockLogger (): Record<LogType, (...args: any[]) => void> {
const mocks: Partial<Record<LogType, (...args: any[]) => void>> = {}
consola.mockTypes((type) => {
mocks[type] = mockFn()
return mocks[type]
return mocks[type]!
})
return mocks
return mocks as Record<LogType, (...args: any[]) => void>
}
2 changes: 1 addition & 1 deletion src/core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function stopServer () {
}
}

export function fetch (path: string, options?: any) {
export function fetch (path: string, options?: RequestInit) {
return _fetch(url(path), options)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface TestContext {
browser?: Browser
url?: string
serverProcess?: ExecaChildProcess
mockFn?: Function
mockFn?: (...args: any[]) => unknown
/**
* Functions to run on the vitest `afterAll` hook.
* Useful for removing anything created during the test.
Expand Down

0 comments on commit eb40a6a

Please sign in to comment.