From 49f20bb77749ec7b44344fd9c42d593ae20c78f0 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Mon, 2 Dec 2024 14:00:30 +0900 Subject: [PATCH] chore: run typecheck in unit tests (#18858) --- packages/vite/package.json | 2 +- packages/vite/src/node/__tests__/config.spec.ts | 4 ++-- packages/vite/src/node/__tests__/plugins/json.spec.ts | 6 +++++- packages/vite/src/node/__tests__/tsconfig.json | 8 -------- packages/vite/src/node/ssr/runtime/__tests__/utils.ts | 1 + packages/vite/src/node/tsconfig.build.json | 4 ++++ packages/vite/src/node/tsconfig.json | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) delete mode 100644 packages/vite/src/node/__tests__/tsconfig.json create mode 100644 packages/vite/src/node/tsconfig.build.json diff --git a/packages/vite/package.json b/packages/vite/package.json index da50a48d9b7e2a..e9a23a92f47474 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -75,7 +75,7 @@ "build": "premove dist && pnpm build-bundle && pnpm build-types", "build-bundle": "rollup --config rollup.config.ts --configPlugin esbuild", "build-types": "pnpm build-types-temp && pnpm build-types-roll && pnpm build-types-check", - "build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node", + "build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node/tsconfig.build.json", "build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin esbuild && premove temp", "build-types-check": "tsc --project tsconfig.check.json", "typecheck": "tsc --noEmit && tsc --noEmit -p src/node", diff --git a/packages/vite/src/node/__tests__/config.spec.ts b/packages/vite/src/node/__tests__/config.spec.ts index b1f1adc1179633..5903437cdb39a5 100644 --- a/packages/vite/src/node/__tests__/config.spec.ts +++ b/packages/vite/src/node/__tests__/config.spec.ts @@ -1,7 +1,7 @@ import http from 'node:http' import { describe, expect, test } from 'vitest' -import type { InlineConfig } from '..' -import type { PluginOption, UserConfig, UserConfigExport } from '../config' +import type { InlineConfig, PluginOption } from '..' +import type { UserConfig, UserConfigExport } from '../config' import { defineConfig, resolveConfig } from '../config' import { resolveEnvPrefix } from '../env' import { createLogger, mergeConfig } from '../publicUtils' diff --git a/packages/vite/src/node/__tests__/plugins/json.spec.ts b/packages/vite/src/node/__tests__/plugins/json.spec.ts index cde30624472dfd..3e114fd3dd145b 100644 --- a/packages/vite/src/node/__tests__/plugins/json.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/json.spec.ts @@ -30,7 +30,11 @@ test('can extract json error position', () => { }) describe('transform', () => { - const transform = (input: string, opts: JsonOptions, isBuild: boolean) => { + const transform = ( + input: string, + opts: Required, + isBuild: boolean, + ) => { const plugin = jsonPlugin(opts, isBuild) return (plugin.transform! as Function)(input, 'test.json').code } diff --git a/packages/vite/src/node/__tests__/tsconfig.json b/packages/vite/src/node/__tests__/tsconfig.json deleted file mode 100644 index ebfc2d30cf7493..00000000000000 --- a/packages/vite/src/node/__tests__/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../../tsconfig.base.json", - "compilerOptions": { - "esModuleInterop": true, - "declaration": false, - "resolveJsonModule": true - } -} diff --git a/packages/vite/src/node/ssr/runtime/__tests__/utils.ts b/packages/vite/src/node/ssr/runtime/__tests__/utils.ts index 37fc8439f97bf7..7ab3a40fbfef8e 100644 --- a/packages/vite/src/node/ssr/runtime/__tests__/utils.ts +++ b/packages/vite/src/node/ssr/runtime/__tests__/utils.ts @@ -32,6 +32,7 @@ export async function createModuleRunnerTester( } beforeEach(async (t) => { + // @ts-ignore globalThis.__HMR__ = {} t.server = await createServer({ diff --git a/packages/vite/src/node/tsconfig.build.json b/packages/vite/src/node/tsconfig.build.json new file mode 100644 index 00000000000000..b83e7a5cbf59e5 --- /dev/null +++ b/packages/vite/src/node/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["**/__tests__"] +} diff --git a/packages/vite/src/node/tsconfig.json b/packages/vite/src/node/tsconfig.json index 85c9d0b7cc3b87..07f09247251237 100644 --- a/packages/vite/src/node/tsconfig.json +++ b/packages/vite/src/node/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.base.json", "include": ["./", "../module-runner", "../types"], - "exclude": ["../**/__tests__"], + "exclude": ["**/fixtures"], "compilerOptions": { // https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping#node-18 "lib": ["ES2023", "DOM"], // DOM because we have client code that gets inlined via function.toString()