Skip to content
Open
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
12 changes: 5 additions & 7 deletions lib/src/cli/test_cli_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,17 @@ class TestCLIRunner {
p.join(cwd, 'coverage'),
);

final packagesPath = p.join(
'.dart_tool',
'package_config.json',
);
// Resolve package_config.json the way dart does: start at
// the package cwd and walk up. In a pub workspace the file
// lives at the workspace root, not in the member package.
final hitmap = await coverage.HitMap.parseFiles(
files,
packagePath: packagesPath,
packagePath: cwd,
checkIgnoredLines: checkIgnore,
);

final resolver = await coverage.Resolver.create(
packagesPath: packagesPath,
packagePath: packagesPath,
packagePath: cwd,
);

final output = hitmap.formatLcov(
Expand Down
53 changes: 53 additions & 0 deletions test/src/cli/test_cli_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,59 @@ void main() {
expect(testRunnerArgs, equals(['--coverage=coverage']));
});

test(
'resolves dart coverage package_config from the pub workspace root',
() async {
final workspaceRoot = Directory.systemTemp.createTempSync();
addTearDown(() => workspaceRoot.deleteSync(recursive: true));

final member = Directory(
p.join(workspaceRoot.path, 'packages', 'foo'),
)..createSync(recursive: true);
File(p.join(member.path, 'pubspec.yaml')).createSync();
Directory(p.join(member.path, 'test')).createSync();

// Pub workspaces only write package_config.json at the root.
File(p.join(workspaceRoot.path, '.dart_tool', 'package_config.json'))
..createSync(recursive: true)
..writeAsStringSync('{"configVersion":2,"packages":[]}');

final lcovFile = File(p.join(member.path, 'coverage', 'lcov.info'));

final originalCwd = Directory.current;
addTearDown(() => Directory.current = originalCwd);
Directory.current = member;

await expectLater(
TestCLIRunner.test(
testType: TestRunType.dart,
cwd: member.path,
collectCoverage: true,
stdout: stdoutLogs.add,
stderr: stderrLogs.add,
overrideTestRunner: testRunner(
Stream.fromIterable([
const DoneTestEvent(success: true, time: 0),
const ExitTestEvent(exitCode: 0, time: 0),
]),
onStart: () {
expect(lcovFile.existsSync(), isFalse);
lcovFile.createSync(recursive: true);
},
),
logger: logger,
),
completion(equals([ExitCode.success.code])),
);
expect(
File(
p.join(member.path, '.dart_tool', 'package_config.json'),
).existsSync(),
isFalse,
);
},
);

test('runs dart tests w/coverage and checkIgnore', () async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));
Expand Down
Loading