Restore _guardIfGuarded

Without this an erroring future that originates in `setUpAll` can't
complete (to an error) in a teardown added by the setup with
`addTearDown`.

Instead use `Invoker.guard` and store the variable, Run both the `main`
and the tests themselves in that same zone. There might be a more
targeted way we can handle this though, and hopefully also alleviate the
`guardIfGuarded` stuff.
diff --git a/pkgs/test_api/lib/src/backend/invoker.dart b/pkgs/test_api/lib/src/backend/invoker.dart
index 20c591c..5c765a4 100644
--- a/pkgs/test_api/lib/src/backend/invoker.dart
+++ b/pkgs/test_api/lib/src/backend/invoker.dart
@@ -170,7 +170,7 @@
   /// code there is:
   ///
   /// - Optionally a zone for [Chain.capture].
-  /// - A zone using [Invoker.guard].
+  /// - Optionally a zone using [Invoker.guard].
   /// - A zone capturing [print] calls as well as setting zone values including
   /// `#test.invoker`.
   /// - A separate [waitForOutstandingCallbacks] zone for each of the test body
@@ -389,7 +389,7 @@
     _runCount++;
     _declaringZone.run(() {
       Chain.capture(() {
-        Invoker.guard(() {
+        _guardIfGuarded(() {
           runZoned(() async {
             _outstandingCallbackZones.add(Zone.current);
 
@@ -433,6 +433,15 @@
     });
   }
 
+  /// Runs [callback], in a [Invoker.guard] context if [_guarded] is `true`.
+  void _guardIfGuarded(void Function() callback) {
+    if (_guarded) {
+      Invoker.guard(callback);
+    } else {
+      callback();
+    }
+  }
+
   /// Prints [text] as a message to [_controller].
   void _print(String text) => _controller.message(Message.print(text));
 
diff --git a/pkgs/test_api/lib/src/remote_listener.dart b/pkgs/test_api/lib/src/remote_listener.dart
index f095335..62ccd9d 100644
--- a/pkgs/test_api/lib/src/remote_listener.dart
+++ b/pkgs/test_api/lib/src/remote_listener.dart
@@ -117,15 +117,20 @@
 
           if (beforeLoad != null) await beforeLoad();
 
-          await declarer.declare(main as Function());
+          Zone invokerGuardedZone;
+          Invoker.guard(() {
+            invokerGuardedZone = Zone.current;
+          });
+          await invokerGuardedZone.runUnary(
+              declarer.declare, main as Function());
 
           var suite = Suite(
               declarer.build(), SuitePlatform.deserialize(message['platform']),
               path: message['path'] as String);
 
           runZoned(() {
-            Invoker.guard(
-                () => RemoteListener._(suite, printZone)._listen(channel));
+            invokerGuardedZone
+                .run(() => RemoteListener._(suite, printZone)._listen(channel));
           },
               // Make the declarer visible to running tests so that they'll throw
               // useful errors when calling `test()` and `group()` within a test,