File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11## 1.16.1-wip
22
3+ - Fix ` HitMap.parseFiles ` to allow empty ` {} ` coverage files written by
4+ ` dart test --coverage ` for skipped test suites.
35- ` Resolver.resolve ` rejects ` package: ` and ` dart: ` URIs outside known roots.
46
57## 1.16.0
Original file line number Diff line number Diff line change @@ -172,7 +172,8 @@ class HitMap {
172172 final ignoredLinesInFilesCache = < String , List <List <int >>? > {};
173173 for (var file in files) {
174174 final contents = file.readAsStringSync ();
175- switch (json.decode (contents)) {
175+ final decoded = json.decode (contents);
176+ switch (decoded) {
176177 case {'coverage' : final List jsonResult}:
177178 globalHitmap.merge (
178179 HitMap .parseJsonSync (
@@ -186,7 +187,11 @@ class HitMap {
186187 scopeOutput: scopeOutput,
187188 ),
188189 );
189- case final decoded:
190+ case Map (isEmpty: true ):
191+ // `dart test --coverage` outputs `{}` for suites where all tests
192+ // were skipped.
193+ break ;
194+ default :
190195 throw FormatException (
191196 'Unrecognized coverage JSON in "${file .path }". Expected a '
192197 '{"coverage": [...]} report, but got ${decoded .runtimeType }.' ,
Original file line number Diff line number Diff line change @@ -208,7 +208,6 @@ void main() {
208208 '{"coverage": null}' ,
209209 '{"coverage": {}}' ,
210210 '{"coverage": "nope"}' ,
211- '{}' ,
212211 '"a string"' ,
213212 '42' ,
214213 'null' ,
@@ -235,6 +234,21 @@ void main() {
235234 }
236235 });
237236
237+ test (
238+ 'HitMap.parseFiles ignores empty JSON file from skipped test suite' ,
239+ () async {
240+ final tempDir = Directory .systemTemp.createTempSync ('hitmap_empty_' );
241+ final tempFile = File ('${tempDir .path }/empty.json' )
242+ ..writeAsStringSync ('{}' );
243+ try {
244+ final hitmap = await HitMap .parseFiles ([tempFile]);
245+ expect (hitmap, isEmpty);
246+ } finally {
247+ tempDir.deleteSync (recursive: true );
248+ }
249+ },
250+ );
251+
238252 group ('HitMap scopeOutput and ScopedOutput' , () {
239253 late Directory tempDir;
240254 late String packagesPath;
Original file line number Diff line number Diff line change @@ -186,6 +186,23 @@ void main() {
186186 }
187187 });
188188
189+ test (
190+ 'HitMap.parseFiles ignores empty JSON file from skipped test suite' ,
191+ () async {
192+ final tempDir = await Directory .systemTemp.createTemp ('coverage.test.' );
193+
194+ try {
195+ final outputFile = File (p.join (tempDir.path, 'coverage.json' ));
196+ await outputFile.writeAsString ('{}' , flush: true );
197+
198+ final parsedResult = await HitMap .parseFiles ([outputFile]);
199+ expect (parsedResult, isEmpty);
200+ } finally {
201+ await tempDir.delete (recursive: true );
202+ }
203+ },
204+ );
205+
189206 test ('HitMap.parseFiles with packagesPath and checkIgnoredLines' , () async {
190207 final tempDir = await Directory .systemTemp.createTemp ('coverage.test.' );
191208
You can’t perform that action at this time.
0 commit comments