[coverage] Could not find package `test` or file `test`
Hi!
I am running fvm dart pub global run coverage:test_with_coverage
fvm flutter --version: 3.29.2
But when I run fvm flutter test - all works fine
Version of coverage: 1.13.1
My project look: project_name: -lib and other staff -test --presenter ---presenter_test.dart
P.S I am not using pub workspaces
Sounds like your working directory incorrect. What directory are you in when you run the command?
I'm not familiar with fvm (heard of it, but never used it). Maybe it alters your working directory?
Does test_with_coverage work without fvm?
Can you share your project as a github repo or a gist?
I have the same problem (I am using pub workspaces, and not using fvm though) https://github.com/benthillerkus/m3_expressive_shapes/actions/runs/15454691911/job/43504534740
I have the same problem (I am using pub workspaces, and not using fvm though) https://github.com/benthillerkus/m3_expressive_shapes/actions/runs/15454691911/job/43504534740
You have two options when testing coverage in a workspace:
- Ignore the workspace, cd into the subdir, run your workflow normally. Run
pub getand yourtest_with_coveragecommand all from that subdir. - Use the workspace, by following these instructions
It looks like you're going with option 1. In that case, my guess is that the bug is here. You're doing your pub get at the workspace level, then testing at the package level.
Github CI can be hard to debug, so you could also try to repro it locally.
@liamappelbe the weird thing is that the exact same setup works in another project of mine: https://github.com/benthillerkus/db_migrations_with_multiverse_time_travel/actions/runs/15454455493/job/43503818055
The only difference I can see is that I'm not using flutter there; just dart
Github CI can be hard to debug, so you could also try to repro it locally.
yeah I get the test Could not find package test or file test error locally too on my macbook, but I thought the CI run might be more useful to you
The only difference I can see is that I'm not using flutter there; just dart
Hmmm. Maybe Dart and Flutter search workspaces for pub deps differently? Workspaces are a fairly new feature, so it's possible this is a bug in Flutter's workspace implementation.
If you do the pub get step in the package directory, does that fix the issue?
If you do the pub get step in the package directory, does that fix the issue?
No.
Running dart run coverage:test_with_coverage --branch-coverage --function-coverage --package packages/androidx_graphics_shapes from the root also doesn't make a difference.
If you do the pub get step in the package directory, does that fix the issue?
No.
Hmmm, ok. That's weird. I'll see if I can repro this myself. Just to clarify, you said that flutter works, but pure dart doesn't?
Running
dart run coverage:test_with_coverage --branch-coverage --function-coverage --package packages/androidx_graphics_shapesfrom the root also doesn't make a difference.
The instructions I linked to said to use a slightly different command than that: dart run coverage:test_with_coverage -- packages/androidx_graphics_shapes. Does that work from the root?
Just to clarify, you said that flutter works, but pure dart doesn't?
Other way around, but it's just a theory; I just observed that my other project which doesn't have a flutter dependency works fine, with basically the same setup and approach.
The instructions I linked to said to use a slightly different command than that: dart run coverage:test_with_coverage -- packages/androidx_graphics_shapes. Does that work from the root?
No
Hmmm, ok. That's weird. I'll see if I can repro this myself
You can just try to get the tests to run with coverage on my repo: https://github.com/benthillerkus/m3_expressive_shapes (code is still WIP and I wouldn't expect the tests to actually all pass)
@liamappelbe were you able to confirm?
Not yet. It's on my todo list, but I've been busy with other projects.
@benthillerkus There's a few different issues here, but I don't think any of them are package:coverage bugs.
One problem is that your package doesn't have package:test in the pubspec.yaml. So even if I cd into packages/androidx_graphics_shapes and run dart test directly without coverage, it doesn't work. Quick fix is just to run dart pub add --dev test in that directory.
With that fixed, dart test at least runs. But your tests are flutter tests, so they all fail. The failures are the same regardless of whether you run dart test directly, or run coverage:test_with_coverage.
If you want to run flutter tests with coverage, you should just run flutter test --coverage. coverage:test_with_coverage runs tests under dart test, so won't work for flutter tests. I'm not sure how flutter test deals with workspaces, so you might need to cd into packages/androidx_graphics_shapes.
Oh wow I feel kinda stupid now; I thought that flutter test was just an alias for dart test like flutter pub, so I never considered that they would do different stuff.
And so I obviously never knew that flutter test just has --coverage build in.
My problem is fixed now