Skip to content

Commit 5ef2dd9

Browse files
authored
fix(test_core): fix writeCoverage to handle a null hit map (#2563)
1 parent 80a4934 commit 5ef2dd9

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 1.27.1-wip
22

3+
* Bump `test_core` to 0.6.14
34
* Removed unused `js` dependency
45

56
## 1.27.0

pkgs/test/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies:
3636

3737
# Use an exact version until the test_api and test_core package are stable.
3838
test_api: 0.7.8
39-
test_core: 0.6.13
39+
test_core: 0.6.14
4040

4141
typed_data: ^1.3.0
4242
web_socket_channel: '>=2.0.0 <4.0.0'

pkgs/test_core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.14
2+
3+
* Fix type cast when parsing a `null` hit map.
4+
15
## 0.6.13
26

37
* Require Dart 3.7

pkgs/test_core/lib/src/runner/coverage.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ Future<Coverage> writeCoverage(
3030
await out.flush();
3131
await out.close();
3232
}
33-
return HitMap.parseJson(coverage['coverage'] as List<Map<String, dynamic>>);
33+
return switch (coverage['coverage']) {
34+
// Matching on `List<dynamic>` the runtime type of `List` in JSON is
35+
// never `Map<String, dynamic>`. The `cast` below ensures the runtime type
36+
// is correct for `HitMap.parseJson`.
37+
List<dynamic> hitMapJson => HitMap.parseJson(
38+
hitMapJson.cast<Map<String, dynamic>>(),
39+
),
40+
null => const {},
41+
_ => throw StateError('Invalid coverage data'),
42+
};
3443
}
3544

3645
Future<void> writeCoverageLcov(

pkgs/test_core/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test_core
2-
version: 0.6.13
2+
version: 0.6.14
33
description: A basic library for writing tests and running them on the VM.
44
repository: https://github.com/dart-lang/test/tree/master/pkgs/test_core
55
issue_tracker: https://github.com/dart-lang/test/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Atest

0 commit comments

Comments
 (0)