Search code examples
darttestingtest-coverage

Dart test coverage not showing up for lib files


How do you make coverage reports include those in under lib directory? Right now when I run tests with dart test --coverage="coverage", it will only record coverage on my test files and not on the lib files. But when I change the imports declaration for my lib files relatively like:

import '../../lib/conventional.dart';

...instead of:

import 'package:conventional/conventional.dart';

...it works. Maybe I'm doing something wrong? Dart version is Dart SDK version: 2.12.0 (stable) on "linux_x64" and coverage version is 1.0.1. The source code can be found here: https://github.com/asartalo/conventional/


Solution

  • I asked the question on reddit and got an answer there. So after running dart test --coverage="coverage", I needed to add --packages=.packages as in:

    dart test --coverage="coverage"
    format_coverage --lcov --in=coverage --out=coverage.lcov --packages=.packages --report-on=lib
    

    Before, I didn't include the --packages=.packages option and so it was only showing coverage for the test files. The documentation for this said:

        --packages           path to the package spec file
    

    ..and didn't mention anything about the significance of that. It's been frustrating.