Skip to content

Commit 5aef971

Browse files
authored
Allow connecting to the runner from test suite (#2526)
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.
1 parent 953e828 commit 5aef971

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

pkgs/test_api/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## 0.7.8-wip
22

3+
* Add a zone function available from the test suite `main` that allows creating
4+
channels to the test runner.
35
* Restrict to latest version of analyzer package.
4-
- Require Dart 3.7
6+
* Require Dart 3.7
57

68
## 0.7.7
79

pkgs/test_api/lib/src/backend/declarer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ class Declarer {
191191
/// Runs [body] with this declarer as [Declarer.current].
192192
///
193193
/// Returns the return value of [body].
194-
T declare<T>(T Function() body) =>
195-
runZoned(body, zoneValues: {#test.declarer: this});
194+
T declare<T>(T Function() body, {Map<Symbol, Object?>? zoneValues}) =>
195+
runZoned(body, zoneValues: {#test.declarer: this, ...?zoneValues});
196196

197197
/// Defines a test case with the given name and body.
198198
void test(

pkgs/test_api/lib/src/backend/remote_listener.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ final class RemoteListener {
133133
await beforeLoad(suiteChannelManager.connectOut);
134134
}
135135

136-
await declarer.declare(main);
136+
await declarer.declare(
137+
main,
138+
zoneValues: {
139+
#test.openChannelCallback: suiteChannelManager.connectOut,
140+
},
141+
);
137142

138143
var suite = Suite(
139144
declarer.build(),

0 commit comments

Comments
 (0)