From e5c388f0151cd1122f0c6ad342cd65a90a30cefc Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 15 Oct 2024 18:39:25 +0900 Subject: [PATCH] fix(vitest,runner): simplify `test.extend` type exports (#6707) --- packages/runner/src/types/tasks.ts | 6 +++--- pnpm-lock.yaml | 6 ++++++ test/dts-fixture/package.json | 13 +++++++++++++ test/dts-fixture/src/repro.ts | 7 +++++++ test/dts-fixture/tsconfig.check.json | 12 ++++++++++++ test/dts-fixture/tsconfig.json | 14 ++++++++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/dts-fixture/package.json create mode 100644 test/dts-fixture/src/repro.ts create mode 100644 test/dts-fixture/tsconfig.check.json create mode 100644 test/dts-fixture/tsconfig.json diff --git a/packages/runner/src/types/tasks.ts b/packages/runner/src/types/tasks.ts index 5cf376b69a06..5c89f1a9cffd 100644 --- a/packages/runner/src/types/tasks.ts +++ b/packages/runner/src/types/tasks.ts @@ -411,11 +411,11 @@ interface ExtendedAPI { runIf: (condition: any) => ChainableTestAPI } -export type CustomAPI = ChainableTestAPI & +export type TestAPI = ChainableTestAPI & ExtendedAPI & { extend: = object>( fixtures: Fixtures - ) => CustomAPI<{ + ) => TestAPI<{ [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext @@ -424,7 +424,7 @@ export type CustomAPI = ChainableTestAPI & }> } -export type TestAPI = CustomAPI +export type { TestAPI as CustomAPI } export interface FixtureOptions { /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 910d6569aeca..cfd2be69d5ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1259,6 +1259,12 @@ importers: specifier: latest version: 9.2.1 + test/dts-fixture: + devDependencies: + vitest: + specifier: workspace:* + version: link:../../packages/vitest + test/global-setup: devDependencies: vitest: diff --git a/test/dts-fixture/package.json b/test/dts-fixture/package.json new file mode 100644 index 000000000000..265568018441 --- /dev/null +++ b/test/dts-fixture/package.json @@ -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:*" + } +} diff --git a/test/dts-fixture/src/repro.ts b/test/dts-fixture/src/repro.ts new file mode 100644 index 000000000000..dd15c27a142e --- /dev/null +++ b/test/dts-fixture/src/repro.ts @@ -0,0 +1,7 @@ +import { test } from 'vitest' + +export const myTest = test.extend<{ now: number }>({ + now: async ({}, use) => { + await use(Date.now()) + }, +}) diff --git a/test/dts-fixture/tsconfig.check.json b/test/dts-fixture/tsconfig.check.json new file mode 100644 index 000000000000..bd4257e82675 --- /dev/null +++ b/test/dts-fixture/tsconfig.check.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "types": [], + "strict": true, + "noEmit": true, + "verbatimModuleSyntax": true + }, + "include": ["dist"] +} diff --git a/test/dts-fixture/tsconfig.json b/test/dts-fixture/tsconfig.json new file mode 100644 index 000000000000..764098fa8e24 --- /dev/null +++ b/test/dts-fixture/tsconfig.json @@ -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"] +}