Unverified Commit 0c80a312 authored by Ferhat's avatar Ferhat Committed by GitHub

[web] Reland - Switch flutter tool web-renderer default for web to auto (#73595)

parent 535392bf
......@@ -461,7 +461,7 @@ abstract class FlutterCommand extends Command<void> {
void usesWebRendererOption() {
argParser.addOption('web-renderer',
defaultsTo: 'html',
defaultsTo: 'auto',
allowed: <String>['auto', 'canvaskit', 'html'],
help: 'The renderer implementation to use when building for the web. Possible values are:\n'
'html - always use the HTML renderer. This renderer uses a combination of HTML, CSS, SVG, 2D Canvas, and WebGL. This is the default.\n'
......@@ -902,7 +902,7 @@ abstract class FlutterCommand extends Command<void> {
? stringsArg(FlutterOptions.kDartDefinesOption)
: <String>[];
if (argParser.options.containsKey('web-renderer') && argResults.wasParsed('web-renderer')) {
if (argParser.options.containsKey('web-renderer')) {
dartDefines = updateDartDefines(dartDefines, stringArg('web-renderer'));
}
......
......@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/build_web.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
......@@ -97,6 +98,58 @@ void main() {
testUsingContext('Builds a web bundle - end to end', () async {
final BuildCommand buildCommand = BuildCommand();
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web']);
expect(fileSystem.file(fileSystem.path.join('lib', 'generated_plugin_registrant.dart')).existsSync(), true);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
Pub: () => MockPub(),
ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => MockBuildSystem(),
});
testUsingContext('hidden if feature flag is not enabled', () async {
expect(BuildWebCommand(verboseHelp: false).hidden, true);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
Pub: () => MockPub(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('not hidden if feature flag is enabled', () async {
expect(BuildWebCommand(verboseHelp: false).hidden, false);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
Pub: () => MockPub(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Defaults to web renderer auto mode when no option is specified', () async {
final TestWebBuildCommand buildCommand = TestWebBuildCommand();
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web']);
final BuildInfo buildInfo =
await buildCommand.webCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
expect(buildInfo.dartDefines, contains('FLUTTER_WEB_AUTO_DETECT=true'));
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
Pub: () => MockPub(),
ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => MockBuildSystem(),
});
}
void setupFileSystemForEndToEndTest(FileSystem fileSystem) {
final List<String> dependencies = <String>[
fileSystem.path.join('packages', 'flutter_tools', 'lib', 'src', 'build_system', 'targets', 'web.dart'),
fileSystem.path.join('bin', 'cache', 'flutter_web_sdk'),
......@@ -150,38 +203,25 @@ class UrlLauncherPlugin {}
when(globals.buildSystem.build(any, any)).thenAnswer((Invocation invocation) async {
return BuildResult(success: true);
});
await runner.run(<String>['build', 'web']);
expect(fileSystem.file(fileSystem.path.join('lib', 'generated_plugin_registrant.dart')).existsSync(), true);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
Pub: () => MockPub(),
ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => MockBuildSystem(),
});
testUsingContext('hidden if feature flag is not enabled', () async {
expect(BuildWebCommand(verboseHelp: false).hidden, true);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
Pub: () => MockPub(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('not hidden if feature flag is enabled', () async {
expect(BuildWebCommand(verboseHelp: false).hidden, false);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
Pub: () => MockPub(),
ProcessManager: () => FakeProcessManager.any(),
});
}
class MockBuildSystem extends Mock implements BuildSystem {}
class MockPub extends Mock implements Pub {}
class TestWebBuildCommand extends FlutterCommand {
TestWebBuildCommand({ bool verboseHelp = false }) :
webCommand = BuildWebCommand(verboseHelp: verboseHelp) {
addSubcommand(webCommand);
}
final BuildWebCommand webCommand;
@override
final String name = 'build';
@override
final String description = 'Build a test executable app.';
@override
Future<FlutterCommandResult> runCommand() async => null;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment