Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: vitest tsconfig should include all files under src
Fixes #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.
  • Loading branch information
haoqunjiang committed Feb 15, 2022
commit 3e61e13c31544b660731ff4f066f22bc110856e0
2 changes: 1 addition & 1 deletion template/tsconfig/vitest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"typecheck": "vue-tsc --noEmit && vue-tsc --noEmit -p tsconfig.vitest.json --composite false"
"typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false"
},
"devDependencies": {
"@types/jsdom": "^16.2.14"
Expand Down
12 changes: 12 additions & 0 deletions template/tsconfig/vitest/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
14 changes: 4 additions & 10 deletions template/tsconfig/vitest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},

"files": [],
"references": [
{
"path": "./tsconfig.vite-config.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.vitest.json"
}
Expand Down
11 changes: 4 additions & 7 deletions template/tsconfig/vitest/tsconfig.vitest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"extends": "@vue/tsconfig/tsconfig.node.json",
"include": ["src/**/__tests__/*"],
"extends": "./tsconfig.app.json",
"exclude": [],
"compilerOptions": {
"composite": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"types": ["node", "jsdom"]
"lib": [],
"types": ["node", "vitest"]
}
}