Skip to content

Projects must list all files or use an 'include' pattern.ts(6307) #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paparent opened this issue Feb 14, 2022 · 4 comments · Fixed by #56
Closed

Projects must list all files or use an 'include' pattern.ts(6307) #55

paparent opened this issue Feb 14, 2022 · 4 comments · Fixed by #56

Comments

@paparent
Copy link

Hi!

I'm trying to get unit tests to work properly and don't know how to deal with the following situation:

I started a new project with npm init vue@3 like so:

✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit Testing? … No / Yes
✔ Add Cypress for End-to-End testing? … No / Yes
✔ Add ESLint for code quality? … No / Yes
✔ Add Prettier for code formatting? … No / Yes

At root of the src folder I add a simple TS file:

export const add = (a: number, b: number) => a + b;

And in my test, when I import it:

import { add } from '../utils';

I get the following error message:

module "...../src/utils"
File '..../src/utils.ts' is not listed within the file list of project '..../tsconfig.vitest.json'. Projects must list all files or use an 'include' pattern.ts(6307)

I left the tsconfigs file untouched, but here there are:

{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },

  "references": [
    {
      "path": "./tsconfig.vite-config.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ]
}
{
  "extends": "@vue/tsconfig/tsconfig.node.json",
  "include": ["src/**/__tests__/*"],
  "compilerOptions": {
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "types": ["node", "jsdom"]
  }
}
@haoqunjiang
Copy link
Member

What's the path of your test file?

@paparent
Copy link
Author

What's the path of your test file?

test file is in src/__tests__/utils.test.ts, and tested file is src/utils.ts.

haoqunjiang added a commit to haoqunjiang/create-vue that referenced this issue Feb 15, 2022
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.
@haoqunjiang
Copy link
Member

Opened a PR for this: #56

Thank you so much for the report! It's a huge oversight on my part.

@paparent
Copy link
Author

@sodatea no worries! I'm starting a brand new project. So I either open issues here and there or PRs when I know how to fix them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants