reuse compiled tests on mac web engine builds (removes 6-7 minutes in build time)

led test run: https://ci.chromium.org/raw/build/logs.chromium.org/flutter/led/yjbanov_google.com/20fd2b5b2bdd75d3dea88074d662fed4cae1c93ada389a633fc6a94f6085f020/+/build.proto?server=chromium-swarm.appspot.com

Change-Id: I5787c9256ad14733b0396cee9875eceb08d12d60
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/28240
Reviewed-by: Godofredo Contreras <godofredoc@google.com>
Commit-Queue: Yegor Jbanov <yjbanov@google.com>
diff --git a/recipes/engine/web_engine.expected/mac-post-submit.json b/recipes/engine/web_engine.expected/mac-post-submit.json
index c2872da..78fe095 100644
--- a/recipes/engine/web_engine.expected/mac-post-submit.json
+++ b/recipes/engine/web_engine.expected/mac-post-submit.json
@@ -897,9 +897,8 @@
     "cmd": [
       "[CACHE]/builder/src/out/host_debug_unopt/dart-sdk/bin/dart",
       "dev/felt.dart",
-      "test",
-      "--browser",
-      "safari"
+      "run",
+      "compile_tests"
     ],
     "cwd": "[CACHE]/builder/src/flutter/lib/web_ui",
     "env": {
@@ -922,7 +921,37 @@
         "RECIPE_REPO[depot_tools]"
       ]
     },
-    "name": "test: felt test safari desktop"
+    "name": "test: Compile tests"
+  },
+  {
+    "cmd": [
+      "[CACHE]/builder/src/out/host_debug_unopt/dart-sdk/bin/dart",
+      "dev/felt.dart",
+      "run",
+      "run_tests_safari"
+    ],
+    "cwd": "[CACHE]/builder/src/flutter/lib/web_ui",
+    "env": {
+      "ANDROID_HOME": "[CACHE]/builder/src/third_party/android_tools/sdk",
+      "CHROME_NO_SANDBOX": "true",
+      "ENGINE_PATH": "[CACHE]/builder",
+      "FLUTTER_PREBUILT_DART_SDK": "True",
+      "GOMA_DIR": "[CACHE]/goma/client"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CACHE]/builder/src/third_party/dart/tools/sdks/dart-sdk/bin"
+      ]
+    },
+    "env_suffixes": {
+      "DEPOT_TOOLS_UPDATE": [
+        "0"
+      ],
+      "PATH": [
+        "RECIPE_REPO[depot_tools]"
+      ]
+    },
+    "name": "test: Run tests on macOS Safari"
   },
   {
     "cmd": [
@@ -1076,10 +1105,9 @@
     "cmd": [
       "[CACHE]/builder/src/out/host_debug_unopt/dart-sdk/bin/dart",
       "dev/felt.dart",
-      "test",
-      "--browser",
-      "ios-safari",
-      "--require-skia-gold"
+      "run",
+      "--require-skia-gold",
+      "run_tests_ios-safari"
     ],
     "cwd": "[CACHE]/builder/src/flutter/lib/web_ui",
     "env": {
@@ -1102,7 +1130,7 @@
         "RECIPE_REPO[depot_tools]"
       ]
     },
-    "name": "test: felt ios-safari test"
+    "name": "test: Run tests on iOS Safari"
   },
   {
     "cmd": [],
diff --git a/recipes/engine/web_engine.py b/recipes/engine/web_engine.py
index 94de584..078247e 100644
--- a/recipes/engine/web_engine.py
+++ b/recipes/engine/web_engine.py
@@ -186,18 +186,25 @@
       api.step('dart pub get in web_engine_tester', [local_dart, 'pub', 'get'])
     with api.context(cwd=checkout.join('flutter', 'lib', 'web_ui')):
       api.step('dart pub get in web_engine_tester', [local_dart, 'pub', 'get'])
-      # TODO(nurhan): carry licenses to another shard when we have more
-      # resources.
       felt_licenses = copy.deepcopy(felt_cmd)
       felt_licenses.append('check-licenses')
       api.step('felt licenses', felt_licenses)
       if api.platform.is_mac:
-        additional_args_safari_desktop = ['--browser', 'safari']
-        felt_test_safari_desktop = copy.deepcopy(felt_cmd)
-        felt_test_safari_desktop.append('test')
-        felt_test_safari_desktop.extend(additional_args_safari_desktop)
+        # On macOS, compile tests once, then reuse compiled tests across iOS and
+        # desktop Safari.
+        felt_run_compile_tests = copy.deepcopy(felt_cmd)
+        felt_run_compile_tests.append('run')
+        felt_run_compile_tests.append('compile_tests')
         api.retry.step(
-            api.test_utils.test_step_name('felt test safari desktop'),
+            api.test_utils.test_step_name('Compile tests'),
+            felt_run_compile_tests
+        )
+
+        felt_test_safari_desktop = copy.deepcopy(felt_cmd)
+        felt_test_safari_desktop.append('run')
+        felt_test_safari_desktop.append('run_tests_safari')
+        api.retry.step(
+            api.test_utils.test_step_name('Run tests on macOS Safari'),
             felt_test_safari_desktop
         )
       if api.platform.is_linux:
@@ -220,10 +227,11 @@
         with SetupXcode(api):
           with recipe_api.defer_results():
             felt_test = copy.deepcopy(felt_cmd)
-            felt_test.append('test')
-            felt_test.extend(additional_args)
+            felt_test.append('run')
+            felt_test.append('--require-skia-gold')
+            felt_test.append('run_tests_ios-safari')
             api.step(
-                api.test_utils.test_step_name('felt ios-safari test'), felt_test
+                api.test_utils.test_step_name('Run tests on iOS Safari'), felt_test
             )
             CleanUpProcesses(api)
       else: