Skip to content

Commit ebbc94b

Browse files
mateusfccpdaniel-v
and
daniel-v
authored
allow passing --file-reporter option to test running refs flutter#69425 (flutter#120716)
* allow passing --file-reporter option to test running refs flutter#69425 * Add trailing comma to help to meet style requirements * Add space between tests for clarity --------- Co-authored-by: daniel-v <dvarga@skawa.hu>
1 parent 23df770 commit ebbc94b

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

packages/flutter_tools/lib/src/commands/test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
208208
'json': 'A machine-readable format. See: https://dart.dev/go/test-docs/json_reporter.md',
209209
},
210210
)
211+
..addOption('file-reporter',
212+
help: 'Enable an additional reporter writing test results to a file.\n'
213+
'Should be in the form <reporter>:<filepath>, '
214+
'Example: "json:reports/tests.json".'
215+
)
211216
..addOption('timeout',
212217
help: 'The default test timeout, specified either '
213218
'in seconds (e.g. "60s"), '
@@ -463,6 +468,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
463468
web: stringArgDeprecated('platform') == 'chrome',
464469
randomSeed: stringArgDeprecated('test-randomize-ordering-seed'),
465470
reporter: stringArgDeprecated('reporter'),
471+
fileReporter: stringArg('file-reporter'),
466472
timeout: stringArgDeprecated('timeout'),
467473
runSkipped: boolArgDeprecated('run-skipped'),
468474
shardIndex: shardIndex,

packages/flutter_tools/lib/src/test/runner.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ abstract class FlutterTestRunner {
4545
bool web = false,
4646
String? randomSeed,
4747
String? reporter,
48+
String? fileReporter,
4849
String? timeout,
4950
bool runSkipped = false,
5051
int? shardIndex,
@@ -82,6 +83,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
8283
bool web = false,
8384
String? randomSeed,
8485
String? reporter,
86+
String? fileReporter,
8587
String? timeout,
8688
bool runSkipped = false,
8789
int? shardIndex,
@@ -103,6 +105,8 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
103105
...<String>['-r', 'json']
104106
else if (reporter != null)
105107
...<String>['-r', reporter],
108+
if (fileReporter != null)
109+
'--file-reporter=$fileReporter',
106110
if (timeout != null)
107111
...<String>['--timeout', timeout],
108112
'--concurrency=$concurrency',

packages/flutter_tools/test/commands.shard/hermetic/test_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,41 @@ dev_dependencies:
804804
ProcessManager: () => FakeProcessManager.any(),
805805
});
806806
});
807+
808+
group('File Reporter', () {
809+
testUsingContext('defaults to unset null value', () async {
810+
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
811+
812+
final TestCommand testCommand = TestCommand(testRunner: testRunner);
813+
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
814+
815+
await commandRunner.run(const <String>[
816+
'test',
817+
'--no-pub',
818+
]);
819+
expect(testRunner.lastFileReporterValue, null);
820+
}, overrides: <Type, Generator>{
821+
FileSystem: () => fs,
822+
ProcessManager: () => FakeProcessManager.any(),
823+
});
824+
825+
testUsingContext('when set --file-reporter value is passed on', () async {
826+
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
827+
828+
final TestCommand testCommand = TestCommand(testRunner: testRunner);
829+
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
830+
831+
await commandRunner.run(const <String>[
832+
'test',
833+
'--no-pub',
834+
'--file-reporter=json:out.jsonl'
835+
]);
836+
expect(testRunner.lastFileReporterValue, 'json:out.jsonl');
837+
}, overrides: <Type, Generator>{
838+
FileSystem: () => fs,
839+
ProcessManager: () => FakeProcessManager.any(),
840+
});
841+
});
807842
}
808843

809844
class FakeFlutterTestRunner implements FlutterTestRunner {
@@ -813,6 +848,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
813848
Duration? leastRunTime;
814849
bool? lastEnableObservatoryValue;
815850
late DebuggingOptions lastDebuggingOptionsValue;
851+
String? lastFileReporterValue;
816852
String? lastReporterOption;
817853

818854
@override
@@ -839,6 +875,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
839875
bool web = false,
840876
String? randomSeed,
841877
String? reporter,
878+
String? fileReporter,
842879
String? timeout,
843880
bool runSkipped = false,
844881
int? shardIndex,
@@ -849,6 +886,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
849886
}) async {
850887
lastEnableObservatoryValue = enableObservatory;
851888
lastDebuggingOptionsValue = debuggingOptions;
889+
lastFileReporterValue = fileReporter;
852890
lastReporterOption = reporter;
853891

854892
if (leastRunTime != null) {

0 commit comments

Comments
 (0)