GeezerVison is showing github.com — "No test suite found in file" error when running Vitest · Issue #32252 · angular/angular-cli
"No test suite found in file" error when running Vitest #32252DescriptionWhich @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
No
Description
I came across this error and the fix seemed to be to remove the export const statement from the spec, then export it from its own file.
I first reported this to Vitest, but they pointed out that running the test using npm run test fails while simple running with the command vitest passes. The maintainers suggested that it was an Angular bug.
I created a new StackBlitz from the Angular template, ensured that it was the latest version of Angular, installed vitest and jsdom, and added the minimum config to get it up and running.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/stackblitz-starters-sj74ev3n?file=src%2Fabc.spec.ts
Please provide the exception or error you saw
❯ npm run test
> test
> ng test --no-watch
RUN v4.0.16 /home/projects/stackblitz-starters-sj74ev3n
✓ demo src/abc.spec.ts > Main > should run 2ms
✓ demo src/abc.spec.ts > Main > should run 0ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL demo src/main.spec.ts [ src/main.spec.ts ]
Error: No test suite found in file /home/projects/stackblitz-starters-sj74ev3n/src/main.spec.ts
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed | 1 passed (2)
Tests 2 passed (2)
Start at 14:05:42
Duration 3.52s (transform 91ms, setup 2.06s, import 51ms, tests 5ms, environment 620ms)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI : 21.0.2
Angular : 21.0.3
Node.js : 20.19.1
Package Manager : npm 10.8.2
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations │ 21.0.3 │ ^21.0.3 │
│ @angular/build │ 21.0.2 │ ^21.0.2 │
│ @angular/cli │ 21.0.2 │ ^21.0.2 │
│ @angular/common │ 21.0.3 │ ^21.0.3 │
│ @angular/compiler │ 21.0.3 │ ^21.0.3 │
│ @angular/compiler-cli │ 21.0.3 │ ^21.0.3 │
│ @angular/core │ 21.0.3 │ ^21.0.3 │
│ @angular/forms │ 21.0.3 │ ^21.0.3 │
│ @angular/platform-browser │ 21.0.3 │ ^21.0.3 │
│ @angular/router │ 21.0.3 │ ^21.0.3 │
│ rxjs │ 7.8.2 │ ^7.8.1 │
│ typescript │ 5.9.3 │ ^5.9.3 │
│ vitest │ 4.0.16 │ ^4.0.15 │
│ zone.js │ 0.16.0 │ ^0.16.0 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else?
Original issue report to Vitest: vitest-dev/vitest#9412 (comment) Activityclydin commented on Jan 8, 2026 The output above shows that src/abc.spec.ts is running the tests from both of those files.
With Vitest used directly, the tests in src/main.spec.ts are being run twice without direct indication that it is happening.
Is that intentional?
Running with ng test --no-watch --include src/abc.spec.ts executes all the tests in the project; as does ng test --no-watch --exclude src/main.spec.ts.
The use of fileParallelism: false in the custom configuration seems to be triggering the behavior with the Angular CLI integration. Removing that line maintains Vitest's double execution of src/main.spec.ts. While the loading of a custom configuration is fully supported, the contents and their interactions are on a best-effort basis. For more information please see the documentation at https://angular.dev/guide/testing#advanced-vitest-configuration. However, in this case, other than fileParallelism it does not appear that any of the options used necessitate a custom configuration file. SebastianStehle commented on Feb 7, 2026 I have a strange problem that could be related to that. I am running a build in github action over docker. And I get random errors like
#33 61.90 FAIL squidex src/app/shared/services/assets.service.spec.ts [ src/app/shared/services/assets.service.spec.ts ]
#33 61.90 Error: No test suite found in file /build/src/app/shared/services/assets.service.spec.ts
https://github.com/Squidex/squidex/actions/runs/21786191853/job/62857975805
It is not always the same files. So far I have no idea how to reproduce it as it never happens locally.
This is my dockerfile
FROM squidex/frontend-build:22.19 AS frontend
WORKDIR /build
ENV CONTINUOUS_INTEGRATION=1
COPY frontend/package*.json ./
RUN npm install --loglevel=error --force
COPY frontend .
RUN npm run lint \
&& npm run test:coverage \
&& npm run build
my build image is node:22.19.0-slim + chromium. rdamazio commented on Mar 11, 2026 Also started seeing this after moving from Karma to vitest. air2 commented on Mar 11, 2026 As far as I can tell this happens, when the file is imported by an other test BEFORE the tests in the file itself are executed, so the order of test executing is causing the randomness in this.
I moved all my exports in *.spec.ts files to *.mock.ts files to work around this issue and I must say in the end I think the code is cleaner now. But yeah it's a nasty issue. rdamazio commented on Mar 12, 2026 Yes, ordering was it for mine too, but it wasn't obvious at all, and only happened in GitHub Actions, not on my Mac (thanks Antigravity for finding the root cause and fixing it! It'd have taken me a long time).
This was the fix for me (at a first glance, nothing to do with the test suites): rdamazio/efis-editor@862fd9a clydin commented on Aug 13, 2026 angular-automatic-lock-bot commented on Oct 19, 2026 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.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|