Repository navigation
Code covarage isn't collected if the packages folder name does not match the package name in pubspec.yaml #5706
Description
Since v3.118 (I'm at v3.118.1 now), my project lost the ability to generate code coverage in Flutter projects. I'm pretty sure that before that version, it worked. Unfortunately, with that update, I also updated Flutter to 3.35.
I created the following log file which I redacted, hoping it will help to pin down the issue.
I'm selecting a single test file, clicking the coverage icon.
I'd expect code coverage for that file, but don't get any.
!! ⚠️ PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING ⚠️ !!
Dart Code extension: 3.118.1
Flutter extension: 3.118.0 (activated)
App: Visual Studio Code
App Host: desktop
Version: mac 1.104.0
Workspace type: Flutter (LSP)
Workspace name: ...
Dart (3.9.2): /Users/sma/Work/flutter/bin/cache/dart-sdk
Flutter (3.35.3): /Users/sma/Work/flutter (No device)
...
[12:18:20] [General] [Info] Debug session starting...
{
"suppressPrompts": false,
"name": "... Tests (iPhone 16 Pro)",
"noDebug": true,
"request": "launch",
"type": "dart",
"args": [],
"cwd": "/Users/sma/Work/<appname>",
"coverageFilePath": "/var/folders/hb/vckjfn4x5wv5gyk2nml5y3pc0000gn/T/flutter-coverage-90c7.lcov",
"expectSingleTest": false,
"program": "/Users/sma/Work/<appname>/test/unit/data_exception_test.dart",
"toolArgs": [
"--coverage",
"--branch-coverage",
"--coverage-path",
"/var/folders/hb/vckjfn4x5wv5gyk2nml5y3pc0000gn/T/flutter-coverage-90c7.lcov",
"--coverage-package",
"<appname>",
"-d",
"2FBE561C-2E8E-406B-BE4C-7BA99F0571C4"
],
"dartCodeDebugSessionID": "session-4d4d9",
"projectRootPath": "/Users/sma/Work/<appname>",
"deviceId": "2FBE561C-2E8E-406B-BE4C-7BA99F0571C4",
"deviceName": "iPhone 16 Pro (ios)",
"toolEnv": {
"FLUTTER_HOST": "VSCode",
"PUB_ENVIRONMENT": "vscode.dart-code",
"FLUTTER_ROOT": "/Users/sma/Work/flutter"
},
"sendLogsToClient": true,
"sendCustomProgressEvents": true,
"allowAnsiColorOutput": true,
"additionalProjectPaths": [
"/Users/sma/Work/<appname>"
],
"vmAdditionalArgs": [],
"vmServicePort": 0,
"dartSdkPath": "/Users/sma/Work/flutter/bin/cache/dart-sdk",
"maxLogLineLength": 2000,
"debugSdkLibraries": false,
"debugExternalPackageLibraries": false,
"showDartDeveloperLogs": true,
"evaluateGettersInDebugViews": true,
"showGettersInDebugViews": true,
"evaluateToStringInDebugViews": true,
"flutterSdkPath": "/Users/sma/Work/flutter",
"useInspectorNotificationsForWidgetErrors": false,
"showMemoryUsage": false,
"debuggerType": 3
}
I checked ls /var/folders/hb/vckjfn4x5wv5gyk2nml5y3pc0000gn/T/*.lcov and there are plenty of files, however the file in question is empty!
If I run flutter test test/unit/data_exception_test.dart --coverage --branch-coverage manually, I get an coverage/lcov.info file as expected. If I add the --coverage-package option, that file is now empty. The tests run in both cases.
The <appname> is correct, though.
Perhaps this is a bug in the flutter tooling?
update: I think, I pinned down the problem. <appname> aka package name and the folder name differ in one character. The plugin passes the foldername instead of the package name.
Activity
DanTup commentedon Sep 17, 2025
Can you confirm whether the name being passed here matches exactly the name in the
pubspec.yamland the folder name of the package?We started passing this in #5631 to support collecting coverage from all packages in your workspace. If we're passing the wrong value(s) then that sounds like a bug here, but if the package name is correct then I wonder if there's a bug in
flutterhere.I just re-tested with a sample project here and everything worked:
Are you able to test with a new sample project too, to see whether it's something specific to your project? Thanks!
DanTup commentedon Sep 17, 2025
I just noticed in the title of this issue you wrote "one of my projects" so perhaps that already explains this.
In which case, I guess the question is what's different with that project. My first suggestions would be to check the name of the package in:
--coverage-packageargLooking at the code, we do appear to have some assumptions about the folder name matching the package name:
I think this could be the issue.. This might not be a safe assumption.
sma commentedon Sep 17, 2025
To reproduce:
...verify that the
widget_testruns with coverage.Now change
name: footoname: barinpubspec.yamland make the testimport 'package:bar/main.dart';instead.…verify that code coverage doesn't show up anymore.
[-]One of my projects lost the ability to display code coverage[/-][+]Code covarage isn't collected if the packages folder name does not match the package name in pubspec.yaml[/+]