Skip to content
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

tsconfig.spec.json types are not being resolved when opening testing files in VSCode #29239

Closed
arkthur opened this issue Dec 31, 2024 · 2 comments

Comments

@arkthur
Copy link

arkthur commented Dec 31, 2024

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

In an Angular project created by CLI, there are three tsconfig files: the base one, the app one and the tests (spec) one. Since Angular has been moving towards esbuild and Vite to build its apps, I'm trying Vitest to run its unit tests. For this, I'm using the integration made by Analog.js (https://analogjs.org/docs/features/testing/vitest).

Everything works fine testing-wise, but in VSCode, and after I removed every package related to any other test runner (karma and jasmine in this case), when I open any ´src/**/*.spec.ts´ file, there are error concerning typing not being resolved for every global testing function, like ´describe´, ´it´ or ´expect´, even though, and as per instructed, ´vitest/globals´ are being correctly referenced in the ´tsconfig.spec.json´.

When I open any testing file, aside of the errors, VSCode tells me the config file it's using to resolve this file is the base one (tsconfig.json). And, if I add ´vitest/globals´ to the base config, errors disappear.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-kgrhhncg

Please provide the exception or error you saw

Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. ts(2582)

Cannot find name 'beforeEach'.ts(2304)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.0.5
Node: 22.12.0
Package Manager: npm 10.9.0
OS: win32 x64

Angular: 19.0.4
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.7
@angular-devkit/build-angular   19.0.5
@angular-devkit/core            19.0.5
@angular-devkit/schematics      19.0.5
@angular/cdk                    19.0.3
@angular/cli                    19.0.5
@angular/material               19.0.3
@schematics/angular             19.0.5
rxjs                            7.8.1
typescript                      5.6.3

Anything else?

Note

I have doubts about this issue being Angular related. Maybe this is a TypeScript and/or VSCode error. Even so, this issue might be of the interest of the Angular team concerning the way ´tsconfig.json´ files are being used by VSCode to resolve its ts files.

@alan-agius4 alan-agius4 transferred this issue from angular/angular Dec 31, 2024
@JeanMeche
Copy link
Member

JeanMeche commented Jan 1, 2025

Hi!
Please have a look at vitest-dev/vitest#5086 and microsoft/TypeScript#37053, this is a TS issue.

What I would suggest is to drop the globals and import directly from vitest.

import {describe, beforeEach, it, expect} from 'vitest';

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2025
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants