Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions pkgs/test/test/runner/coverage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,95 @@ end_of_record
''');
});

test('gathers coverage for code outside of lib in json mode', () async {
await d.dir(d.sandbox, [
d.dir('dart_frog_sample', [
d.file('pubspec.yaml', '''
name: dart_frog_sample
version: 1.0.0
environment:
sdk: ^3.5.0
dependencies:
dart_frog: ^1.0.0
dev_dependencies:
mocktail: ^1.0.0
test: ^1.26.2
'''),
d.dir('routes', [
d.file('index.dart', '''
import 'package:dart_frog/dart_frog.dart';
Response onRequest(RequestContext context) {
return Response(body: 'Welcome to Dart Frog!');
}
'''),
]),
d.dir('test', [
d.dir('routes', [
d.file('index_test.dart', '''
import 'dart:io';
import 'package:dart_frog/dart_frog.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

import '../../routes/index.dart' as route;

class _MockRequestContext extends Mock implements RequestContext {}

void main() {
group('GET /', () {
test('responds with a 200 and "Welcome to Dart Frog!".', () {
final context = _MockRequestContext();
final response = route.onRequest(context);
expect(response.statusCode, equals(HttpStatus.ok));
expect(
response.body(),
completion(equals('Welcome to Dart Frog!')),
);
});
});
}
'''),
]),
]),
]),
]).create();

final pkgDir = p.join(d.sandbox, 'dart_frog_sample');
await (await runPub([
'global',
'activate',
'coverage',
], workingDirectory: pkgDir)).shouldExit(0);
await (await runPub(['get'], workingDirectory: pkgDir)).shouldExit(0);
final lcovFile = p.join(coverageDirectory.path, 'lcov.info');
var test = await runTest(
['--coverage', coverageDirectory.path, 'test/routes/index_test.dart'],
packageConfig: p.join(pkgDir, '.dart_tool/package_config.json'),
workingDirectory: pkgDir,
);
await validateTest(test);
await (await runPub([
'global',
'run',
'coverage:format_coverage',
'--lcov',
'--in=${coverageDirectory.path}',
'--out=$lcovFile',
'--report-on=lib,routes',
], workingDirectory: pkgDir)).shouldExit(0);
expect(
File(lcovFile).readAsStringSync(),
contains('''
SF:${p.join(pkgDir, 'routes', 'index.dart')}
DA:2,1
DA:3,1
LF:2
LH:2
end_of_record
'''),
);
});

test('gathers coverage for Chrome tests', () async {
await (await runPub(['get'], workingDirectory: pkgDir)).shouldExit(0);
var test = await runTest(
Expand Down
1 change: 1 addition & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.6.16-wip

- Fix coverage reporting to report all coverage when using JSON workflow.
* Add `SuiteConfiguration.suiteLoadTimeout` to configure the timeout for loading a test suite.
* Removed hard-coded timeout of 12m for loading a test suite and set default to `none`.

Expand Down
11 changes: 10 additions & 1 deletion pkgs/test_core/lib/src/runner/vm/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ Future<Map<String, dynamic>> _gatherCoverage(
false,
false,
false,
await _filterCoveragePackages(config.coveragePackages),
await _filterCoveragePackages(config.coveragePackages, config.coverageLcov),
isolateIds: {isolateId!},
branchCoverage: config.branchCoverage,
);
Expand Down Expand Up @@ -456,7 +456,16 @@ void _setupPauseAfterTests() {

Future<Set<String>> _filterCoveragePackages(
List<RegExp>? coveragePackages,
String? coverageLcov,
) async {
if (coverageLcov == null && coveragePackages == null) {
// If no filters were provided and the JSON workflow is used, report all
// coverage. This is required to maintain backward compatibility
// particularly in cases where coverage is required for files outside of the
// lib directory.
// See https://github.com/dart-lang/test/issues/2581.
return {};
}
if (coveragePackages == null || coveragePackages.isEmpty) {
return workspacePackageNames(await currentPackage);
} else {
Expand Down
Loading