From 30197ce15ee518f5c1de47943435f65a27af7c63 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 30 Jul 2025 01:51:13 +0000 Subject: [PATCH] Allow connecting to the runner from test suite Closes #2497 Add a zone variable when the declarer runs `main` from the test suite which gives access to the `connectOut` callback which creates a channel back to the runner with a provided name. Add an optional argument allowing a map of zone values to the `declare` method and use it from the remote listener. --- pkgs/test_api/CHANGELOG.md | 4 +++- pkgs/test_api/lib/src/backend/declarer.dart | 4 ++-- pkgs/test_api/lib/src/backend/remote_listener.dart | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkgs/test_api/CHANGELOG.md b/pkgs/test_api/CHANGELOG.md index 0208cbf5d..a813dca9e 100644 --- a/pkgs/test_api/CHANGELOG.md +++ b/pkgs/test_api/CHANGELOG.md @@ -1,7 +1,9 @@ ## 0.7.8-wip +* Add a zone function available from the test suite `main` that allows creating + channels to the test runner. * Restrict to latest version of analyzer package. -- Require Dart 3.7 +* Require Dart 3.7 ## 0.7.7 diff --git a/pkgs/test_api/lib/src/backend/declarer.dart b/pkgs/test_api/lib/src/backend/declarer.dart index 4551a7d9f..7f9e4df3b 100644 --- a/pkgs/test_api/lib/src/backend/declarer.dart +++ b/pkgs/test_api/lib/src/backend/declarer.dart @@ -191,8 +191,8 @@ class Declarer { /// Runs [body] with this declarer as [Declarer.current]. /// /// Returns the return value of [body]. - T declare(T Function() body) => - runZoned(body, zoneValues: {#test.declarer: this}); + T declare(T Function() body, {Map? zoneValues}) => + runZoned(body, zoneValues: {#test.declarer: this, ...?zoneValues}); /// Defines a test case with the given name and body. void test( diff --git a/pkgs/test_api/lib/src/backend/remote_listener.dart b/pkgs/test_api/lib/src/backend/remote_listener.dart index eb6fb343e..1f58c2574 100644 --- a/pkgs/test_api/lib/src/backend/remote_listener.dart +++ b/pkgs/test_api/lib/src/backend/remote_listener.dart @@ -133,7 +133,12 @@ final class RemoteListener { await beforeLoad(suiteChannelManager.connectOut); } - await declarer.declare(main); + await declarer.declare( + main, + zoneValues: { + #test.openChannelCallback: suiteChannelManager.connectOut, + }, + ); var suite = Suite( declarer.build(),