├── .gitignore ├── README.md └── dart-coverage-helper /.gitignore: -------------------------------------------------------------------------------- 1 | .history 2 | .vscode 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Helper for full tests coverage checkup for you Dart/Flutter project 2 | 3 | ## Installation 4 | 5 | 1. Clone the script to any location 6 | 7 | ```bash 8 | wget https://raw.githubusercontent.com/priezz/dart_full_coverage/master/dart-coverage-helper 9 | ``` 10 | 11 | 2. Make it executable 12 | 13 | ```bash 14 | chmod +x dart-coverage-helper 15 | ``` 16 | 17 | 3. Ensure that the location of the script is in your `PATH` environment variable. 18 | 19 | That's it! 20 | 21 | ## Usage 22 | 23 | Run from the root of your Dart/Flutter project 24 | 25 | ```bash 26 | dart-coverage-helper 27 | ``` 28 | 29 | Then generate the coverage report as usual 30 | 31 | ```bash 32 | flutter test --coverage # for Flutter project 33 | # or 34 | pub run test_coverage # for Dart project 35 | ``` 36 | 37 | (optional) Generate HTML report with [`genhtml`](https://github.com/linux-test-project/lcov) tool 38 | 39 | ```bash 40 | genhtml -o coverage coverage/lcov.info 41 | ``` 42 | 43 | ## How it works 44 | 45 | The script just scans your `lib` directory for `*.dart` files (excluding `*.g.dart`) and imports 46 | them into the generated `test/coverage_test.dart` file. This way the coverage analyzers will go 47 | through the whole project. 48 | -------------------------------------------------------------------------------- /dart-coverage-helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | outputFile="$(pwd)/test/coverage_test.dart" 4 | packageName="$(cat pubspec.yaml| grep '^name: ' | awk '{print $2}')" 5 | 6 | if [ "$packageName" = "" ]; then 7 | echo "Run $0 from the root of your Dart/Flutter project" 8 | exit 1 9 | fi 10 | 11 | echo "/// *** GENERATED FILE - ANY CHANGES WOULD BE OBSOLETE ON NEXT GENERATION *** ///\n" > "$outputFile" 12 | echo "/// Helper to test coverage for all project files" >> "$outputFile" 13 | echo "// ignore_for_file: unused_import" >> "$outputFile" 14 | find lib -name '*.dart' | grep -v '.g.dart' | grep -v 'generated_plugin_registrant' | awk -v package=$packageName '{gsub("^lib", "", $1); printf("import '\''package:%s%s'\'';\n", package, $1);}' >> "$outputFile" 15 | echo "\nvoid main() {}" >> "$outputFile" 16 | --------------------------------------------------------------------------------