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
22 changes: 16 additions & 6 deletions packages/flutter_tools/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.



import 'dart:math' as math;

import 'package:meta/meta.dart';
Expand Down Expand Up @@ -201,12 +199,12 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
)
..addOption('reporter',
abbr: 'r',
defaultsTo: 'compact',
help: 'Set how to print test results.',
allowed: <String>['compact', 'expanded', 'json'],
allowed: <String>['compact', 'expanded', 'github', 'json'],
allowedHelp: <String, String>{
'compact': 'A single line that updates dynamically.',
'compact': 'A single line that updates dynamically (The default reporter).',
'expanded': 'A separate line for each update. May be preferred when logging to a file or in continuous integration.',
'github': 'A custom reporter for GitHub Actions (the default reporter when running on GitHub Actions).',
'json': 'A machine-readable format. See: https://dart.dev/go/test-docs/json_reporter.md',
},
)
Expand Down Expand Up @@ -256,6 +254,18 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
@override
String get category => FlutterCommandCategory.project;

// Lookup the default reporter if one was not specified.
String _getReporter() {
final String? reporter = stringArgDeprecated('reporter');
if (reporter != null) {
return reporter;
}
if (globals.platform.environment['GITHUB_ACTIONS']?.toLowerCase() == 'true') {
return 'github';
}
return 'compact';
}

@override
Future<FlutterCommandResult> verifyThenRunCommand(String? commandPath) {
_testFiles = argResults!.rest.map<String>(globals.fs.path.absolute).toList();
Expand Down Expand Up @@ -463,7 +473,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
flutterProject: flutterProject,
web: stringArgDeprecated('platform') == 'chrome',
randomSeed: stringArgDeprecated('test-randomize-ordering-seed'),
reporter: stringArgDeprecated('reporter'),
reporter: _getReporter(),
timeout: stringArgDeprecated('timeout'),
runSkipped: boolArgDeprecated('run-skipped'),
shardIndex: shardIndex,
Expand Down
57 changes: 57 additions & 0 deletions packages/flutter_tools/test/commands.shard/hermetic/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/test.dart';
import 'package:flutter_tools/src/device.dart';
Expand Down Expand Up @@ -660,6 +661,60 @@ dev_dependencies:
]),
});

testUsingContext('Tests on github actions default to github reporter', () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);

final TestCommand testCommand = TestCommand(testRunner: testRunner);
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);

await commandRunner.run(const <String>[
'test',
'--no-pub',
]);

expect(
testRunner.lastReporterOption,
'github',
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(
environment: <String, String>{
'GITHUB_ACTIONS': 'true',
},
),
DeviceManager: () => _FakeDeviceManager(<Device>[
FakeDevice('ephemeral', 'ephemeral', type: PlatformType.android),
]),
});

testUsingContext('Tests default to compact reporter if not specified and not on Github actions', () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);

final TestCommand testCommand = TestCommand(testRunner: testRunner);
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);

await commandRunner.run(const <String>[
'test',
'--no-pub',
]);

expect(
testRunner.lastReporterOption,
'compact',
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(
environment: <String, String>{}
),
DeviceManager: () => _FakeDeviceManager(<Device>[
FakeDevice('ephemeral', 'ephemeral', type: PlatformType.android),
]),
});

testUsingContext('Integration tests given flavor', () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);

Expand Down Expand Up @@ -789,6 +844,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
Duration? leastRunTime;
bool? lastEnableObservatoryValue;
late DebuggingOptions lastDebuggingOptionsValue;
String? lastReporterOption;

@override
Future<int> runTests(
Expand Down Expand Up @@ -824,6 +880,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
}) async {
lastEnableObservatoryValue = enableObservatory;
lastDebuggingOptionsValue = debuggingOptions;
lastReporterOption = reporter;

if (leastRunTime != null) {
await Future<void>.delayed(leastRunTime!);
Expand Down