Skip to content

Commit a9ca7d6

Browse files
authored
Fix code coverage script by using the root-level package_config.json (#8288)
1 parent 2318c9d commit a9ca7d6

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

pkg/code_coverage/bin/code_coverage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Future<void> main() async {
5353
'run',
5454
'coverage:format_coverage',
5555
'--packages',
56-
p.join(pkgDir, '.dart_tool', 'package_config.json'),
56+
p.join(projectDir.path, '.dart_tool', 'package_config.json'),
5757
'-i',
5858
rawOutputDir,
5959
'--base-directory',

pkg/code_coverage/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ rm ${APP_ALL_TEST_PATH}
6161
echo "Exporting to LCOV"
6262
cd "${APP_DIR}"
6363
dart run coverage:format_coverage \
64-
--packages "${APP_DIR}/.dart_tool/package_config.json" \
64+
--packages "${PROJECT_DIR}/.dart_tool/package_config.json" \
6565
-i "${OUTPUT_DIR}/raw/app_unit.json" \
6666
--base-directory "${PROJECT_DIR}" \
6767
--lcov \

pkg/code_coverage/lib/format_lcov.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Future main() async {
5656
!e.key.startsWith('pkg/pub_integration/'))
5757
].nonNulls;
5858
final pubDevEntry = Entry('pub-dev')
59-
..covered = libEntries.map((e) => e.covered).reduce((a, b) => a + b)
60-
..total = libEntries.map((e) => e.total).reduce((a, b) => a + b);
59+
..covered = libEntries.map((e) => e.covered).fold(0, (a, b) => a + b)
60+
..total = libEntries.map((e) => e.total).fold(0, (a, b) => a + b);
6161
output.writeln([
6262
pubDevEntry.formatted('pub-dev'),
6363
_tree['app/lib']?.formatted('app'),

pkg/code_coverage/lib/test_runner.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,20 @@ Future<void> _convertToLcov(
118118
final out = File(outputFile);
119119
if (await out.exists()) return;
120120
await out.parent.create(recursive: true);
121+
final baseDir =
122+
Directory(packageDir.contains('/app') ? '../' : '../../').absolute.path;
121123
await Process.run(
122124
'dart',
123125
[
124126
'pub',
125127
'run',
126128
'coverage:format_coverage',
127129
'--packages',
128-
'$packageDir/.dart_tool/package_config.json',
130+
'$baseDir/.dart_tool/package_config.json',
129131
'-i',
130132
inputFile,
131133
'--base-directory',
132-
packageDir.contains('/app') ? '../' : '../../',
134+
baseDir,
133135
'--lcov',
134136
'--out',
135137
outputFile,

0 commit comments

Comments
 (0)