Only print debug URL when debugging (#2702) Either `--coverage` or `--pause-after-load` is sufficient to enable the `debug` state for the test runner, but in the case of `--coverage` without interactive debugging the VM debugger URL is not relevant to the user. Change the condition used to decide whether to include this URL in the JSON reporter output to only when `--pause-after-load` is used.
diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md index 1cbee81..fa768d3 100644 --- a/pkgs/test/CHANGELOG.md +++ b/pkgs/test/CHANGELOG.md
@@ -7,6 +7,8 @@ * Suppress dart2js compiler output for successful compiles. * Include output from passing tests messages within the `Passing tests` group in `GithubReporter`. +* Only include VM debugger in output when using interactive debugging, suppress + it when only using coverage. ## 1.31.2
diff --git a/pkgs/test/test/runner/json_reporter_test.dart b/pkgs/test/test/runner/json_reporter_test.dart index a984248..8d6913e 100644 --- a/pkgs/test/test/runner/json_reporter_test.dart +++ b/pkgs/test/test/runner/json_reporter_test.dart
@@ -6,6 +6,7 @@ library; import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:path/path.dart' as p; @@ -851,6 +852,93 @@ args: ['-p', 'chrome', '--js-trace'], ); }, tags: ['chrome']); + + test('does not emit debug events when --coverage is enabled', () async { + var tempDir = await Directory.systemTemp.createTemp('coverage_json_test'); + try { + await d.file('test.dart', ''' + import 'package:test/test.dart'; + void main() { + test('success', () {}); + } + ''').create(); + + var test = await runTest([ + 'test.dart', + '--coverage', + tempDir.path, + ], reporter: 'json'); + await test.shouldExit(0); + + var stdoutLines = await test.stdoutStream().toList(); + var events = [ + for (var line in stdoutLines) jsonDecode(line) as Map<String, dynamic>, + ]; + expect(events.where((e) => e['type'] == 'debug'), isEmpty); + } finally { + await tempDir.delete(recursive: true); + } + }); + + test( + 'emits debug events when --pause-after-load is enabled', + () async { + await d.file('test.dart', ''' + import 'package:test/test.dart'; + void main() { + test('success', () {}); + } + ''').create(); + + var test = await runTest([ + 'test.dart', + '--pause-after-load', + ], reporter: 'json'); + + await expectLater(test.stdout, emitsThrough(contains('"type":"debug"'))); + + test.stdin.writeln(); + await test.shouldExit(0); + }, + // TODO(https://github.com/dart-lang/test/issues/1613): Fix pause after load tests on windows. + testOn: '!windows', + ); + + test( + 'emits debug events when both --pause-after-load and --coverage are enabled', + () async { + var tempDir = await Directory.systemTemp.createTemp( + 'coverage_pause_json_test', + ); + try { + await d.file('test.dart', ''' + import 'package:test/test.dart'; + void main() { + test('success', () {}); + } + ''').create(); + + var test = await runTest([ + 'test.dart', + '--pause-after-load', + '--coverage', + tempDir.path, + ], reporter: 'json'); + + await expectLater( + test.stdout, + emitsThrough(contains('"type":"debug"')), + ); + + test.stdin.writeln(); + await test.shouldExit(0); + } finally { + await tempDir.delete(recursive: true); + } + }, + // TODO(https://github.com/dart-lang/test/issues/1613): Fix pause after load tests on windows. + testOn: '!windows', + ); } /// Asserts that the tests defined by [tests] produce the JSON events in
diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md index d5a1734..5306a05 100644 --- a/pkgs/test_core/CHANGELOG.md +++ b/pkgs/test_core/CHANGELOG.md
@@ -4,6 +4,8 @@ * Suppress dart2js compiler output for successful compiles. * Include passing test messages within the `Passing tests` group in `GithubReporter`. +* Only include VM debugger in output when using interactive debugging, suppress + it when only using coverage. ## 0.6.19
diff --git a/pkgs/test_core/lib/src/runner/configuration/reporters.dart b/pkgs/test_core/lib/src/runner/configuration/reporters.dart index 1f8a1fd..c21cffa 100644 --- a/pkgs/test_core/lib/src/runner/configuration/reporters.dart +++ b/pkgs/test_core/lib/src/runner/configuration/reporters.dart
@@ -91,7 +91,7 @@ 'A machine-readable format (see ' 'https://dart.dev/go/test-docs/json_reporter.md).', (config, engine, sink) => - JsonReporter.watch(engine, sink, isDebugRun: config.debug), + JsonReporter.watch(engine, sink, isDebugRun: config.pauseAfterLoad), ), 'silent': ReporterDetails( 'A reporter with no output. '