From f8db3107b959bc91f0c4fd983338bbd781c60fdd Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Sun, 20 Oct 2024 21:52:47 -0700 Subject: [PATCH] add: adding support for code coverage --- .gitignore | 4 ++++ .melos/coverage.yaml | 17 +++++++++++++++++ melos.yaml | 6 ++++++ packages/container/container/pubspec.yaml | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .melos/coverage.yaml diff --git a/.gitignore b/.gitignore index 51f1333..7bed930 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,10 @@ .packages build/ +# Coverage files +coverage/ +coverage_report/ + # Files and directories created by developer spike/ devbox.d/ diff --git a/.melos/coverage.yaml b/.melos/coverage.yaml new file mode 100644 index 0000000..f553692 --- /dev/null +++ b/.melos/coverage.yaml @@ -0,0 +1,17 @@ +scripts: + _: &coverage_scripts + coverage: + run: > + melos exec -c 1 --fail-fast -- "dart pub add --dev coverage && dart test --coverage=coverage && dart pub global activate coverage && dart pub global run coverage:format_coverage -l --packages=.dart_tool/package_config.json --report-on=lib/ -i coverage -o coverage/lcov.info && dart pub remove coverage" + description: Run tests with coverage and generate LCOV report for each package + coverage_report: + run: > + melos exec -c 1 --fail-fast -- " + if [ -s coverage/lcov.info ]; then + genhtml -o coverage_report coverage/lcov.info; + echo 'Coverage report generated successfully.'; + else + echo 'No valid coverage data found. Skipping report generation.'; + fi + " + description: Generate HTML coverage report from LCOV data for each package, if valid data exists diff --git a/melos.yaml b/melos.yaml index 0eb4a4d..9dd3e41 100644 --- a/melos.yaml +++ b/melos.yaml @@ -62,6 +62,12 @@ scripts: docs:serve:custom: run: "melos exec --scope=\"$MELOS_SCOPE\" -- \"echo 'Serving docs for {MELOS_PACKAGE_NAME}' && dhttpd --path doc --port \\${DOC_PORT:-8080}\"\n" description: Serve generated documentation for specified packages (use with MELOS_SCOPE and optionally DOC_PORT env vars) + coverage: + run: "melos exec -c 1 --fail-fast -- \"dart pub add --dev coverage && dart test --coverage=coverage && dart pub global activate coverage && dart pub global run coverage:format_coverage -l --packages=.dart_tool\/package_config.json --report-on=lib\/ -i coverage -o coverage\/lcov.info && dart pub remove coverage\"\n" + description: Run tests with coverage and generate LCOV report for each package + coverage_report: + run: "melos exec -c 1 --fail-fast -- \" if [ -s coverage\/lcov.info ]; then\n genhtml -o coverage_report coverage\/lcov.info;\n echo 'Coverage report generated successfully.';\nelse\n echo 'No valid coverage data found. Skipping report generation.';\nfi \"\n" + description: "Generate HTML coverage report from LCOV data for each package, if valid data exists" test: run: melos exec -c 1 --fail-fast -- "dart test" description: Run tests for all packages diff --git a/packages/container/container/pubspec.yaml b/packages/container/container/pubspec.yaml index 6f39c52..362838e 100644 --- a/packages/container/container/pubspec.yaml +++ b/packages/container/container/pubspec.yaml @@ -11,4 +11,4 @@ dependencies: quiver: ^3.2.0 dev_dependencies: test: ^1.24.0 - lints: ^4.0.0 \ No newline at end of file + lints: ^4.0.0