[flutter_tools] support github reporter (#115137)
* [flutter_tools] support github reporter * Update packages/flutter_tools/lib/src/commands/test.dart Co-authored-by: Christopher Fujino <fujino@google.com> Co-authored-by: Christopher Fujino <fujino@google.com>
This commit is contained in:
parent
83cda7e52f
commit
c021d9177c
@ -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';
|
||||
@ -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',
|
||||
},
|
||||
)
|
||||
@ -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();
|
||||
@ -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,
|
||||
|
@ -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';
|
||||
@ -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);
|
||||
|
||||
@ -789,6 +844,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
|
||||
Duration? leastRunTime;
|
||||
bool? lastEnableObservatoryValue;
|
||||
late DebuggingOptions lastDebuggingOptionsValue;
|
||||
String? lastReporterOption;
|
||||
|
||||
@override
|
||||
Future<int> runTests(
|
||||
@ -824,6 +880,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
|
||||
}) async {
|
||||
lastEnableObservatoryValue = enableObservatory;
|
||||
lastDebuggingOptionsValue = debuggingOptions;
|
||||
lastReporterOption = reporter;
|
||||
|
||||
if (leastRunTime != null) {
|
||||
await Future<void>.delayed(leastRunTime!);
|
||||
|
Loading…
x
Reference in New Issue
Block a user