Skip to content

Commit 3e61e13

Browse files
committed
fix: vitest tsconfig should include all files under src
Fixes vuejs#55 Fixes the case that a `.spec.ts` file inside `__test__/` imports a module outside of `__test__/` (a cross-(typescript-)project reference). Note that TypeScript looks for `include` patterns in `references` top-down, so `tsconfig.app.json` must come before `tsconfig.vitest.json` so that the `src/**` modules can get the most-accurate type hints. The previous tsconfig only works for `.vue` imports in `.spec.ts`, which seems to be a Volar bug. We shouldn't rely on that. This fix is a more accurate configuration.
1 parent 7426bbb commit 3e61e13

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

template/tsconfig/vitest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"scripts": {
3-
"typecheck": "vue-tsc --noEmit && vue-tsc --noEmit -p tsconfig.vitest.json --composite false"
3+
"typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false"
44
},
55
"devDependencies": {
66
"@types/jsdom": "^16.2.14"
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "@vue/tsconfig/tsconfig.web.json",
3+
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
4+
"exclude": ["src/**/__tests__/*"],
5+
"compilerOptions": {
6+
"composite": true,
7+
"baseUrl": ".",
8+
"paths": {
9+
"@/*": ["./src/*"]
10+
}
11+
}
12+
}

template/tsconfig/vitest/tsconfig.json

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
{
2-
"extends": "@vue/tsconfig/tsconfig.web.json",
3-
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
4-
"exclude": ["src/**/__tests__/*"],
5-
"compilerOptions": {
6-
"baseUrl": ".",
7-
"paths": {
8-
"@/*": ["./src/*"]
9-
}
10-
},
11-
2+
"files": [],
123
"references": [
134
{
145
"path": "./tsconfig.vite-config.json"
156
},
7+
{
8+
"path": "./tsconfig.app.json"
9+
},
1610
{
1711
"path": "./tsconfig.vitest.json"
1812
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
2-
"extends": "@vue/tsconfig/tsconfig.node.json",
3-
"include": ["src/**/__tests__/*"],
2+
"extends": "./tsconfig.app.json",
3+
"exclude": [],
44
"compilerOptions": {
55
"composite": true,
6-
"baseUrl": ".",
7-
"paths": {
8-
"@/*": ["./src/*"]
9-
},
10-
"types": ["node", "jsdom"]
6+
"lib": [],
7+
"types": ["node", "vitest"]
118
}
129
}

0 commit comments

Comments
 (0)