From 2cc6809f8cf2c6a41a2649b7abe0b0749fa2c2d4 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 15 Oct 2024 11:14:55 +0900 Subject: [PATCH 1/6] fix(vitest,runner): tweak `test.extend` type exports --- packages/vitest/src/public/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vitest/src/public/index.ts b/packages/vitest/src/public/index.ts index 4798ba6c23ad..47325439f184 100644 --- a/packages/vitest/src/public/index.ts +++ b/packages/vitest/src/public/index.ts @@ -179,6 +179,7 @@ export type { TestFunction, TestOptions, TestAPI, + CustomAPI, SuiteAPI, HookListener, HookCleanupCallback, From a888558f5b12e89090c59380c4df67b6418534c3 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 15 Oct 2024 11:39:46 +0900 Subject: [PATCH 2/6] refactor: tweak --- packages/runner/src/types/tasks.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 { /** From dfb817ce43660bf9fa5d046fd83935c97ea60876 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 15 Oct 2024 11:40:52 +0900 Subject: [PATCH 3/6] chore: cleanup --- packages/vitest/src/public/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vitest/src/public/index.ts b/packages/vitest/src/public/index.ts index 47325439f184..4798ba6c23ad 100644 --- a/packages/vitest/src/public/index.ts +++ b/packages/vitest/src/public/index.ts @@ -179,7 +179,6 @@ export type { TestFunction, TestOptions, TestAPI, - CustomAPI, SuiteAPI, HookListener, HookCleanupCallback, From 6232cf88fec695a7be5d109e13e0108b1de1eec4 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 15 Oct 2024 17:41:36 +0900 Subject: [PATCH 4/6] test: add test/dts-fixture --- pnpm-lock.yaml | 6 ++++++ test/dts-fixture/package.json | 12 ++++++++++++ test/dts-fixture/src/repro.ts | 7 +++++++ test/dts-fixture/tsconfig.check.json | 16 ++++++++++++++++ test/dts-fixture/tsconfig.json | 14 ++++++++++++++ 5 files changed, 55 insertions(+) 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/pnpm-lock.yaml b/pnpm-lock.yaml index 2c606b041ef5..929a3f09d22d 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..113c422cd4ed --- /dev/null +++ b/test/dts-fixture/package.json @@ -0,0 +1,12 @@ +{ + "name": "@vitest/test-dts-fixture", + "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..e9b77fa8e201 --- /dev/null +++ b/test/dts-fixture/tsconfig.check.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ESNext", + // TODO: type check fails with NodeNext. probably we should fix this. + // node_modules/.pnpm/vitest@2.1.0-beta.1_@types+node@22.7.5/node_modules/vitest/index.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/index.js")' call instead. + // 1 export * from './dist/index.js' + // ~~~~~~~~~~~~~~~~~ + "module": "ESNext", + "moduleResolution": "Bundler", + "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"] +} From ec4f8a4b53957ee7e3354d6e4a98d24c82e93289 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 15 Oct 2024 17:45:47 +0900 Subject: [PATCH 5/6] chore: cleanup --- test/dts-fixture/tsconfig.check.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/dts-fixture/tsconfig.check.json b/test/dts-fixture/tsconfig.check.json index e9b77fa8e201..95be68d126e2 100644 --- a/test/dts-fixture/tsconfig.check.json +++ b/test/dts-fixture/tsconfig.check.json @@ -2,9 +2,9 @@ "compilerOptions": { "target": "ESNext", // TODO: type check fails with NodeNext. probably we should fix this. - // node_modules/.pnpm/vitest@2.1.0-beta.1_@types+node@22.7.5/node_modules/vitest/index.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/index.js")' call instead. - // 1 export * from './dist/index.js' - // ~~~~~~~~~~~~~~~~~ + // ../../packages/vitest/index.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/index.js")' call instead. + // 1 export * from './dist/index.js' + // ~~~~~~~~~~~~~~~~~ "module": "ESNext", "moduleResolution": "Bundler", "types": [], From 2efa152ce12adeba2cc5c6b0ba620ba48d3909e9 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 15 Oct 2024 18:11:47 +0900 Subject: [PATCH 6/6] test: add type module, then NodeNext is happy --- test/dts-fixture/package.json | 1 + test/dts-fixture/tsconfig.check.json | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/dts-fixture/package.json b/test/dts-fixture/package.json index 113c422cd4ed..265568018441 100644 --- a/test/dts-fixture/package.json +++ b/test/dts-fixture/package.json @@ -1,5 +1,6 @@ { "name": "@vitest/test-dts-fixture", + "type": "module", "private": true, "scripts": { "build": "rm -rf dist && tsc -p tsconfig.json", diff --git a/test/dts-fixture/tsconfig.check.json b/test/dts-fixture/tsconfig.check.json index 95be68d126e2..bd4257e82675 100644 --- a/test/dts-fixture/tsconfig.check.json +++ b/test/dts-fixture/tsconfig.check.json @@ -1,12 +1,8 @@ { "compilerOptions": { "target": "ESNext", - // TODO: type check fails with NodeNext. probably we should fix this. - // ../../packages/vitest/index.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/index.js")' call instead. - // 1 export * from './dist/index.js' - // ~~~~~~~~~~~~~~~~~ - "module": "ESNext", - "moduleResolution": "Bundler", + "module": "NodeNext", + "moduleResolution": "NodeNext", "types": [], "strict": true, "noEmit": true,