From dcbaee53897d02a2511dbed593595dabc4e37310 Mon Sep 17 00:00:00 2001
From: Jackson Gardner <jacksongardner@google.com>
Date: Thu, 15 Feb 2024 14:19:49 -0800
Subject: [PATCH] Explicitly pass the web renderer into the tests. (#6140)

The web tests currently all assume to be using the html renderer. `flutter test` previously erroneously was serving files for the HTML renderer by default (which is not the intended behavior). After this was fixed, the tests started running on the CanvasKit renderer and some of them broke. If we are relying on the html renderer, we should explicitly pass it when running `flutter test`
---
 script/tool/lib/src/dart_test_command.dart        |  7 +++++--
 script/tool/lib/src/drive_examples_command.dart   |  1 +
 script/tool/test/dart_test_command_test.dart      | 10 +++++-----
 script/tool/test/drive_examples_command_test.dart |  7 +++++++
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/script/tool/lib/src/dart_test_command.dart b/script/tool/lib/src/dart_test_command.dart
index df0ee71400..1c188ff38a 100644
--- a/script/tool/lib/src/dart_test_command.dart
+++ b/script/tool/lib/src/dart_test_command.dart
@@ -98,9 +98,11 @@ class DartTestCommand extends PackageLoopingCommand {
       platform = 'chrome';
     }
 
+    // All the web tests assume the html renderer currently.
+    final String? webRenderer = (platform == 'chrome') ? 'html' : null;
     bool passed;
     if (package.requiresFlutter()) {
-      passed = await _runFlutterTests(package, platform: platform);
+      passed = await _runFlutterTests(package, platform: platform, webRenderer: webRenderer);
     } else {
       passed = await _runDartTests(package, platform: platform);
     }
@@ -109,7 +111,7 @@ class DartTestCommand extends PackageLoopingCommand {
 
   /// Runs the Dart tests for a Flutter package, returning true on success.
   Future<bool> _runFlutterTests(RepositoryPackage package,
-      {String? platform}) async {
+      {String? platform, String? webRenderer}) async {
     final String experiment = getStringArg(kEnableExperiment);
 
     final int exitCode = await processRunner.runAndStream(
@@ -121,6 +123,7 @@ class DartTestCommand extends PackageLoopingCommand {
         // Flutter defaults to VM mode (under a different name) and explicitly
         // setting it is deprecated, so pass nothing in that case.
         if (platform != null && platform != 'vm') '--platform=$platform',
+        if (webRenderer != null) '--web-renderer=$webRenderer',
       ],
       workingDir: package.directory,
     );
diff --git a/script/tool/lib/src/drive_examples_command.dart b/script/tool/lib/src/drive_examples_command.dart
index ff73044f6c..f3baa5c7ce 100644
--- a/script/tool/lib/src/drive_examples_command.dart
+++ b/script/tool/lib/src/drive_examples_command.dart
@@ -119,6 +119,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
           'web-server',
           '--web-port=7357',
           '--browser-name=chrome',
+          '--web-renderer=html',
           if (platform.environment.containsKey('CHROME_EXECUTABLE'))
             '--chrome-binary=${platform.environment['CHROME_EXECUTABLE']}',
         ],
diff --git a/script/tool/test/dart_test_command_test.dart b/script/tool/test/dart_test_command_test.dart
index 5752d7439e..d56bb44b0f 100644
--- a/script/tool/test/dart_test_command_test.dart
+++ b/script/tool/test/dart_test_command_test.dart
@@ -265,7 +265,7 @@ void main() {
         orderedEquals(<ProcessCall>[
           ProcessCall(
               getFlutterCommand(mockPlatform),
-              const <String>['test', '--color', '--platform=chrome'],
+              const <String>['test', '--color', '--platform=chrome', '--web-renderer=html'],
               package.path),
         ]),
       );
@@ -289,7 +289,7 @@ void main() {
         orderedEquals(<ProcessCall>[
           ProcessCall(
               getFlutterCommand(mockPlatform),
-              const <String>['test', '--color', '--platform=chrome'],
+              const <String>['test', '--color', '--platform=chrome', '--web-renderer=html'],
               plugin.path),
         ]),
       );
@@ -314,7 +314,7 @@ void main() {
         orderedEquals(<ProcessCall>[
           ProcessCall(
               getFlutterCommand(mockPlatform),
-              const <String>['test', '--color', '--platform=chrome'],
+              const <String>['test', '--color', '--platform=chrome', '--web-renderer=html'],
               plugin.path),
         ]),
       );
@@ -339,7 +339,7 @@ void main() {
         orderedEquals(<ProcessCall>[
           ProcessCall(
               getFlutterCommand(mockPlatform),
-              const <String>['test', '--color', '--platform=chrome'],
+              const <String>['test', '--color', '--platform=chrome', '--web-renderer=html'],
               plugin.path),
         ]),
       );
@@ -409,7 +409,7 @@ void main() {
         orderedEquals(<ProcessCall>[
           ProcessCall(
               getFlutterCommand(mockPlatform),
-              const <String>['test', '--color', '--platform=chrome'],
+              const <String>['test', '--color', '--platform=chrome', '--web-renderer=html'],
               plugin.path),
         ]),
       );
diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart
index 60df1b70ae..92d4921a0b 100644
--- a/script/tool/test/drive_examples_command_test.dart
+++ b/script/tool/test/drive_examples_command_test.dart
@@ -678,6 +678,7 @@ void main() {
                   'web-server',
                   '--web-port=7357',
                   '--browser-name=chrome',
+                  '--web-renderer=html',
                   '--driver',
                   'test_driver/integration_test.dart',
                   '--target',
@@ -726,6 +727,7 @@ void main() {
                   'web-server',
                   '--web-port=7357',
                   '--browser-name=chrome',
+                  '--web-renderer=html',
                   '--driver',
                   'test_driver/integration_test.dart',
                   '--target',
@@ -777,6 +779,7 @@ void main() {
                   'web-server',
                   '--web-port=7357',
                   '--browser-name=chrome',
+                  '--web-renderer=html',
                   '--chrome-binary=/path/to/chrome',
                   '--driver',
                   'test_driver/integration_test.dart',
@@ -1223,6 +1226,7 @@ void main() {
                   'web-server',
                   '--web-port=7357',
                   '--browser-name=chrome',
+                  '--web-renderer=html',
                   '--driver',
                   'test_driver/integration_test.dart',
                   '--target',
@@ -1237,6 +1241,7 @@ void main() {
                   'web-server',
                   '--web-port=7357',
                   '--browser-name=chrome',
+                  '--web-renderer=html',
                   '--driver',
                   'test_driver/integration_test.dart',
                   '--target',
@@ -1334,6 +1339,7 @@ void main() {
                     'web-server',
                     '--web-port=7357',
                     '--browser-name=chrome',
+                    '--web-renderer=html',
                     '--driver',
                     'test_driver/integration_test.dart',
                     '--target',
@@ -1413,6 +1419,7 @@ void main() {
                     'web-server',
                     '--web-port=7357',
                     '--browser-name=chrome',
+                    '--web-renderer=html',
                     '--driver',
                     'test_driver/integration_test.dart',
                     '--target',