tools icon indicating copy to clipboard operation
tools copied to clipboard

[coverage] Could not find package `test` or file `test`

Open abikko opened this issue 10 months ago • 13 comments

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

abikko avatar May 03 '25 17:05 abikko

P.S I am not using pub workspaces

abikko avatar May 03 '25 17:05 abikko

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?

liamappelbe avatar May 20 '25 04:05 liamappelbe

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

benthillerkus avatar Jun 04 '25 23:06 benthillerkus

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:

  1. Ignore the workspace, cd into the subdir, run your workflow normally. Run pub get and your test_with_coverage command all from that subdir.
  2. 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 avatar Jun 04 '25 23:06 liamappelbe

@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

benthillerkus avatar Jun 05 '25 00:06 benthillerkus

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?

liamappelbe avatar Jun 05 '25 00:06 liamappelbe

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.

benthillerkus avatar Jun 05 '25 10:06 benthillerkus

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_shapes from 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?

liamappelbe avatar Jun 05 '25 22:06 liamappelbe

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)

benthillerkus avatar Jun 06 '25 08:06 benthillerkus

@liamappelbe were you able to confirm?

benthillerkus avatar Jun 21 '25 15:06 benthillerkus

Not yet. It's on my todo list, but I've been busy with other projects.

liamappelbe avatar Jun 25 '25 00:06 liamappelbe

@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.

liamappelbe avatar Jun 26 '25 01:06 liamappelbe

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

benthillerkus avatar Jun 26 '25 01:06 benthillerkus