Skip to content

Commit

Permalink
fix(vitest,runner): simplify test.extend type exports (#6707)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Oct 15, 2024
1 parent 62ac4eb commit e5c388f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/runner/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ interface ExtendedAPI<ExtraContext> {
runIf: (condition: any) => ChainableTestAPI<ExtraContext>
}

export type CustomAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> &
export type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> &
ExtendedAPI<ExtraContext> & {
extend: <T extends Record<string, any> = object>(
fixtures: Fixtures<T, ExtraContext>
) => CustomAPI<{
) => TestAPI<{
[K in keyof T | keyof ExtraContext]: K extends keyof T
? T[K]
: K extends keyof ExtraContext
Expand All @@ -424,7 +424,7 @@ export type CustomAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> &
}>
}

export type TestAPI<ExtraContext = object> = CustomAPI<ExtraContext>
export type { TestAPI as CustomAPI }

export interface FixtureOptions {
/**
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/dts-fixture/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@vitest/test-dts-fixture",
"type": "module",
"private": true,
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.json",
"check": "tsc -p tsconfig.check.json",
"test": "pnpm build && pnpm check"
},
"devDependencies": {
"vitest": "workspace:*"
}
}
7 changes: 7 additions & 0 deletions test/dts-fixture/src/repro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'vitest'

export const myTest = test.extend<{ now: number }>({
now: async ({}, use) => {
await use(Date.now())
},
})
12 changes: 12 additions & 0 deletions test/dts-fixture/tsconfig.check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"types": [],
"strict": true,
"noEmit": true,
"verbatimModuleSyntax": true
},
"include": ["dist"]
}
14 changes: 14 additions & 0 deletions test/dts-fixture/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"declaration": true,
"declarationMap": true,
"outDir": "dist",
"sourceMap": true,
"verbatimModuleSyntax": true
},
"include": ["src"]
}

0 comments on commit e5c388f

Please sign in to comment.