Skip to content

Commit ba98d6e

Browse files
kevmoosuryaKommana2662
authored andcommitted
refactor(flutter_tools): finish TestCommand OptionDescriptor and OptionBundle migration (flutter#194361)
Completes the `flutter test` migration to the shared option bundles and web/debugging descriptors from flutter#194356, removing the remaining imperative option helpers and untyped argument lookups. Part of flutter#194338 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent 1186a94 commit ba98d6e

2 files changed

Lines changed: 68 additions & 34 deletions

File tree

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

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import '../device.dart';
2222
import '../native_assets.dart';
2323
import '../project.dart';
2424
import '../runner/flutter_command.dart';
25-
import '../runner/flutter_command_runner.dart';
2625
import '../test/coverage_collector.dart';
2726
import '../test/event_printer.dart';
2827
import '../test/runner.dart';
@@ -31,6 +30,7 @@ import '../test/test_wrapper.dart';
3130
import '../test/watcher.dart';
3231
import '../web/compile.dart';
3332
import '../web/web_constants.dart';
33+
import '../web/web_options.dart';
3434

3535
/// The name of the directory where Integration Tests are placed.
3636
///
@@ -74,25 +74,32 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
7474
FlutterTestRunner? testRunner,
7575
this.testWrapper = const TestWrapper(),
7676
this.verbose = false,
77-
bool verboseHelp = false,
77+
super.verboseHelp = false,
7878
}) : _toolContext = toolContext,
7979
_testRunner = testRunner ?? FlutterTestRunner(toolContext: toolContext),
8080
super(toolContext: toolContext) {
8181
requiresPubspecYaml();
82-
usesPubOption();
83-
usesFrontendServerStarterPathOption(verboseHelp: verboseHelp);
84-
usesTrackWidgetCreation(verboseHelp: verboseHelp);
85-
addEnableExperimentation(hide: !verboseHelp);
86-
usesDartDefineOption();
87-
usesDeviceUserOption();
88-
usesFlavorOption();
89-
addEnableImpellerFlag(verboseHelp: verboseHelp);
90-
addMachineOutputFlag(verboseHelp: verboseHelp);
91-
addEnableFlutterGpuFlag(verboseHelp: verboseHelp);
92-
addEnableHcppFlag(verboseHelp: verboseHelp);
93-
usesDeprecatedJsInteropFlag(verboseHelp: verboseHelp);
82+
enableUsesPubOption();
83+
enableUsesFatalWarnings();
84+
registerOptionBundles(const <OptionBundle>[
85+
DdsAndDevToolsOptionsBundle(includeDevTools: false),
86+
]);
9487

9588
argParser.addDescriptors(const <OptionDescriptor<Object?>>[
89+
CommonOptions.pub,
90+
BuildInfoOptions.frontendServerStarterPath,
91+
BuildInfoOptions.trackWidgetCreation,
92+
CommonOptions.enableExperiment,
93+
CommonOptions.dartDefines,
94+
CommonOptions.dartDefineFromFile,
95+
CommonOptions.deviceUser,
96+
BuildInfoOptions.flavor,
97+
DebuggingOptionDescriptors.enableImpeller,
98+
CommonOptions.machine,
99+
DebuggingOptionDescriptors.enableFlutterGpu,
100+
DebuggingOptionDescriptors.enableHcpp,
101+
WebOptions.deprecatedJsInterop,
102+
CommonOptions.fatalWarnings,
96103
_experimentalFasterTesting,
97104
_name,
98105
_plainName,
@@ -123,12 +130,9 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
123130
_timeout,
124131
_ignoreTimeouts,
125132
_wasm,
126-
_crossOriginIsolation,
133+
WebOptions.crossOriginIsolation,
127134
_uninstall,
128135
], verboseHelp: verboseHelp);
129-
130-
addDdsOptions(verboseHelp: verboseHelp);
131-
usesFatalWarningsOption(verboseHelp: verboseHelp);
132136
}
133137

134138
static const _experimentalFasterTesting = FlagOptionDescriptor(
@@ -367,17 +371,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
367371
help: 'Compile to WebAssembly rather than JavaScript.\n$kWasmMoreInfo',
368372
);
369373

370-
static const _crossOriginIsolation = FlagOptionDescriptor(
371-
name: 'cross-origin-isolation',
372-
verboseOnly: true,
373-
help:
374-
'Adds the Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy '
375-
'headers to the web server. These headers are required for using APIs like '
376-
'SharedArrayBuffer. This is on by default for the "skwasm" web renderer, '
377-
'and this flag can be used to override the default. To disable this for the '
378-
'skwasm renderer, use "--no-cross-origin-isolation".',
379-
);
380-
381374
static const _uninstall = FlagOptionDescriptor(
382375
name: 'uninstall',
383376
defaultsTo: true,
@@ -567,12 +560,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
567560
debugLogsDirectoryPath: debugLogsDirectoryPath,
568561
webConfig: WebDebugConfig(
569562
renderer: webRenderer,
570-
crossOriginIsolation: wasParsed(_crossOriginIsolation)
571-
? getValue(_crossOriginIsolation)
572-
: null,
563+
crossOriginIsolation: getValue(WebOptions.crossOriginIsolation),
573564
useWasm: useWasm,
574565
),
575-
printDtd: boolArg(FlutterGlobalOptions.kPrintDtd, global: true),
566+
printDtd: getValue(CommonOptions.printDtd),
576567
enableHcpp: explicitEnableHcpp,
577568
uninstallApp: getValue(_uninstall),
578569
);
@@ -772,7 +763,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
772763
ignoreTimeouts: getValue(_ignoreTimeouts),
773764
failFast: getValue(_failFast),
774765
integrationTestDevice: integrationTestDevice,
775-
integrationTestUserIdentifier: stringArg(FlutterOptions.kDeviceUser),
766+
integrationTestUserIdentifier: getValue(CommonOptions.deviceUser),
776767
testTimeRecorder: testTimeRecorder,
777768
nativeAssetsBuilder: nativeAssetsBuilder,
778769
);

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,49 @@ resolution: workspace
20432043
]);
20442044
},
20452045
);
2046+
2047+
testUsingContext('preserves expected hidden options and test-specific --wasm help text', () {
2048+
final defaultCommand = TestCommand(toolContext: toolContext);
2049+
2050+
expect(defaultCommand.argParser.options['track-widget-creation']!.hide, isFalse);
2051+
expect(
2052+
defaultCommand.argParser.options['wasm']!.help,
2053+
startsWith('Compile to WebAssembly rather than JavaScript.'),
2054+
);
2055+
2056+
final hiddenByDefault = <String>{
2057+
for (final entry in defaultCommand.argParser.options.entries)
2058+
if (entry.value.hide) entry.key,
2059+
};
2060+
expect(
2061+
hiddenByDefault,
2062+
unorderedEquals(<String>[
2063+
'frontend-server-starter-path',
2064+
'enable-experiment',
2065+
'enable-impeller',
2066+
'machine',
2067+
'enable-flutter-gpu',
2068+
'enable-hcpp',
2069+
'deprecated-js-interop',
2070+
'fatal-warnings',
2071+
'experimental-faster-testing',
2072+
'disable-service-auth-codes',
2073+
'disable-service-origin-check',
2074+
'ipv6',
2075+
'platform',
2076+
'enable-vmservice',
2077+
'cross-origin-isolation',
2078+
'disable-dds',
2079+
]),
2080+
);
2081+
2082+
final verboseCommand = TestCommand(toolContext: toolContext, verboseHelp: true);
2083+
final hiddenInVerboseMode = <String>{
2084+
for (final entry in verboseCommand.argParser.options.entries)
2085+
if (entry.value.hide) entry.key,
2086+
};
2087+
expect(hiddenInVerboseMode, isEmpty);
2088+
});
20462089
});
20472090
}
20482091

0 commit comments

Comments
 (0)