Skip to content

Code covarage isn't collected if the packages folder name does not match the package name in pubspec.yaml #5706

Closed

Description

@sma

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

  1. DanTup commented on Sep 17, 2025

    @DanTup
    Member

    If I add the --coverage-package option, that file is now empty

    Can you confirm whether the name being passed here matches exactly the name in the pubspec.yaml and 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 flutter here.

    I just re-tested with a sample project here and everything worked:

    Image

    Are you able to test with a new sample project too, to see whether it's something specific to your project? Thanks!

  2. added
    awaiting infoRequires more information from the customer to progress
    on Sep 17, 2025
  3. DanTup commented on Sep 17, 2025

    @DanTup
    Member

    Are you able to test with a new sample project too

    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:

    • the --coverage-package arg
    • the pubspec.yaml
    • the name of the folder the project is in

    Looking at the code, we do appear to have some assumptions about the folder name matching the package name:

    workspacePackageNames = workspacePackagePaths.map((packagePath) => path.basename(packagePath));

    I think this could be the issue.. This might not be a safe assumption.

  4. added this to the v3.120.0 milestone on Sep 17, 2025
  5. added
    in testingRelates to test execution of Dart/Flutter tests for end users
    on Sep 17, 2025
  6. sma commented on Sep 17, 2025

    @sma
    Author

    To reproduce:

    flutter create foo
    cd foo
    

    ...verify that the widget_test runs with coverage.

    Now change name: foo to name: bar in pubspec.yaml and make the test import 'package:bar/main.dart'; instead.

    …verify that code coverage doesn't show up anymore.

  7. removed
    awaiting infoRequires more information from the customer to progress
    on Sep 17, 2025
  8. changed the title [-]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[/+] on Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in testingRelates to test execution of Dart/Flutter tests for end usersis bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions