Skip to content

[tool] Adds --wasm flag to the drive-examples command #7162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
3 changes: 3 additions & 0 deletions script/tool/lib/src/common/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const String kEnableExperiment = 'enable-experiment';
/// land (e.g., dependency overrides in federated plugin combination PRs).
const String kDoNotLandWarning = 'DO NOT MERGE';

/// Key for enabling web WASM compilation
const String kWebWasmFlag = 'wasm';

/// Target platforms supported by Flutter.
// ignore: public_member_api_docs
enum FlutterPlatform { android, ios, linux, macos, web, windows }
Expand Down
23 changes: 17 additions & 6 deletions script/tool/lib/src/drive_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'common/package_looping_command.dart';
import 'common/plugin_utils.dart';
import 'common/repository_package.dart';

const int _exitNoPlatformFlags = 2;
const int _exitInvalidArgs = 2;
const int _exitNoAvailableDevice = 3;

// From https://flutter.dev/to/integration-test-on-web
Expand All @@ -40,6 +40,8 @@ class DriveExamplesCommand extends PackageLoopingCommand {
help: 'Runs the web implementation of the examples');
argParser.addFlag(platformWindows,
help: 'Runs the Windows implementation of the examples');
argParser.addFlag(kWebWasmFlag,
help: 'Compile to WebAssembly rather than JavaScript');
argParser.addOption(
kEnableExperiment,
defaultsTo: '',
Expand Down Expand Up @@ -84,7 +86,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
printError(
'Exactly one of ${platformSwitches.map((String platform) => '--$platform').join(', ')} '
'must be specified.');
throw ToolExit(_exitNoPlatformFlags);
throw ToolExit(_exitInvalidArgs);
}

String? androidDevice;
Expand All @@ -107,22 +109,31 @@ class DriveExamplesCommand extends PackageLoopingCommand {
iOSDevice = devices.first;
}

final bool useWasm = getBoolArg(kWebWasmFlag);
final bool hasPlatformWeb = getBoolArg(platformWeb);
if (useWasm && !hasPlatformWeb) {
printError('--wasm is only supported on the web platform');
throw ToolExit(_exitInvalidArgs);
}

_targetDeviceFlags = <String, List<String>>{
if (getBoolArg(platformAndroid))
platformAndroid: <String>['-d', androidDevice!],
if (getBoolArg(platformIOS)) platformIOS: <String>['-d', iOSDevice!],
if (getBoolArg(platformLinux)) platformLinux: <String>['-d', 'linux'],
if (getBoolArg(platformMacOS)) platformMacOS: <String>['-d', 'macos'],
if (getBoolArg(platformWeb))
if (hasPlatformWeb)
platformWeb: <String>[
'-d',
'web-server',
'--web-port=7357',
'--browser-name=chrome',
if (useWasm)
'--wasm'
// TODO(dit): Clean this up, https://github.com/flutter/flutter/issues/151869
if (platform.environment['CHANNEL']?.toLowerCase() == 'master')
'--web-renderer=canvaskit',
if (platform.environment['CHANNEL']?.toLowerCase() != 'master')
else if (platform.environment['CHANNEL']?.toLowerCase() == 'master')
'--web-renderer=canvaskit'
else
'--web-renderer=html',
if (platform.environment.containsKey('CHROME_EXECUTABLE'))
'--chrome-binary=${platform.environment['CHROME_EXECUTABLE']}',
Expand Down
69 changes: 69 additions & 0 deletions script/tool/test/drive_examples_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ void main() {
);
});

test('fails if wasm flag is present but not web platform', () async {
setMockFlutterDevicesOutput();
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['drive-examples', '--android', '--wasm'],
errorHandler: (Error e) {
commandError = e;
});

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains('--wasm is only supported on the web platform'),
]),
);
});

test('fails if multiple platforms are provided', () async {
setMockFlutterDevicesOutput();
Error? commandError;
Expand Down Expand Up @@ -691,6 +709,57 @@ void main() {
]));
});

test('drives a web plugin compiled to WASM', () async {
final RepositoryPackage plugin = createFakePlugin(
'plugin',
packagesDir,
extraFiles: <String>[
'example/integration_test/plugin_test.dart',
'example/test_driver/integration_test.dart',
'example/web/index.html',
],
platformSupport: <String, PlatformDetails>{
platformWeb: const PlatformDetails(PlatformSupport.inline),
},
);

final Directory pluginExampleDirectory = getExampleDir(plugin);

final List<String> output = await runCapturingPrint(runner, <String>[
'drive-examples',
'--web',
'--wasm',
]);

expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for plugin'),
contains('No issues found!'),
]),
);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>[
'drive',
'-d',
'web-server',
'--web-port=7357',
'--browser-name=chrome',
'--wasm',
'--driver',
'test_driver/integration_test.dart',
'--target',
'integration_test/plugin_test.dart',
],
pluginExampleDirectory.path),
]));
});

// TODO(dit): Clean this up, https://github.com/flutter/flutter/issues/151869
test('drives a web plugin (html renderer in stable)', () async {
// Override the platform to simulate CHANNEL: stable
Expand Down