Skip to content

Commit 2096773

Browse files
Update the use of 'package:shelf_web_socket's webSocketHandler method (#2421)
- add a 2nd argument to the closure passed into package:shelf_web_socket's `webSocketHandler` method - widen the dep on package:shelf_web_socket This will allow us to add more type info to the closure that `webSocketHandler` expects; it's currently an untyped Function. See also dart-lang/shelf#457 and dart-lang/shelf#463. This forward declares compatibility with `3.0` of `package:shelf_web_socket`; I _think_ this is necessary - as `dart test` uses both package:test and package:shelf_web_socket - but happy to hear otherwise. --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Most changes should add an entry to the changelog and may need to [rev the pubspec package version](https://github.com/dart-lang/sdk/blob/main/docs/External-Package-Maintenance.md#making-a-change). - Changes to packages require [corresponding tests](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md#Testing). Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback. </details> --------- Co-authored-by: Jacob MacDonald <[email protected]>
1 parent 1d28d73 commit 2096773

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.25.11
2+
3+
* Update to be forward compatible with `package:shelf_web_socket` version `3.x`.
4+
15
## 1.25.10
26

37
* Update the `package:vm_service` constraint to allow version `15.x`.

pkgs/test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ import 'package:stream_channel/stream_channel.dart';
798798
// returned spawnHybridCode().
799799
hybridMain(StreamChannel channel) async {
800800
// Start a WebSocket server that just sends "hello!" to its clients.
801-
var server = await io.serve(webSocketHandler((webSocket) {
801+
var server = await io.serve(webSocketHandler((webSocket, _) {
802802
webSocket.sink.add('hello!');
803803
}), 'localhost', 0);
804804

pkgs/test/lib/src/runner/browser/compilers/dart2js.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ class Dart2JsSupport extends CompilerSupport with JsHtmlWrapper {
174174
@override
175175
(Uri, Future<WebSocketChannel>) get webSocket {
176176
var completer = Completer<WebSocketChannel>.sync();
177-
var path = _webSocketHandler.create(webSocketHandler(completer.complete));
177+
// Note: the WebSocketChannel type below is needed for compatibility with
178+
// package:shelf_web_socket v2.
179+
var path =
180+
_webSocketHandler.create(webSocketHandler((WebSocketChannel ws, _) {
181+
completer.complete(ws);
182+
}));
178183
var webSocketUrl = serverUrl.replace(scheme: 'ws').resolve(path);
179184
return (webSocketUrl, completer.future);
180185
}

pkgs/test/lib/src/runner/browser/compilers/dart2wasm.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ class Dart2WasmSupport extends CompilerSupport with WasmHtmlWrapper {
180180
@override
181181
(Uri, Future<WebSocketChannel>) get webSocket {
182182
var completer = Completer<WebSocketChannel>.sync();
183-
var path = _webSocketHandler.create(webSocketHandler(completer.complete));
183+
// Note: the WebSocketChannel type below is needed for compatibility with
184+
// package:shelf_web_socket v2.
185+
var path =
186+
_webSocketHandler.create(webSocketHandler((WebSocketChannel ws, _) {
187+
completer.complete(ws);
188+
}));
184189
var webSocketUrl = serverUrl.replace(scheme: 'ws').resolve(path);
185190
return (webSocketUrl, completer.future);
186191
}

pkgs/test/lib/src/runner/browser/compilers/precompiled.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ abstract class PrecompiledSupport extends CompilerSupport {
137137
@override
138138
(Uri, Future<WebSocketChannel>) get webSocket {
139139
var completer = Completer<WebSocketChannel>.sync();
140-
var path = _webSocketHandler.create(webSocketHandler(completer.complete));
140+
// Note: the WebSocketChannel type below is needed for compatibility with
141+
// package:shelf_web_socket v2.
142+
var path =
143+
_webSocketHandler.create(webSocketHandler((WebSocketChannel ws, _) {
144+
completer.complete(ws);
145+
}));
141146
var webSocketUrl = serverUrl.replace(scheme: 'ws').resolve(path);
142147
return (webSocketUrl, completer.future);
143148
}

pkgs/test/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test
2-
version: 1.25.10
2+
version: 1.25.11
33
description: >-
44
A full featured library for writing and running Dart tests across platforms.
55
repository: https://github.com/dart-lang/test/tree/master/pkgs/test

pkgs/test/test/runner/browser/code_server.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ class CodeServer {
5959
/// future that will complete to the WebSocket.
6060
Future<WebSocketChannel> handleWebSocket() {
6161
var completer = Completer<WebSocketChannel>();
62-
_handler.expect('GET', '/', webSocketHandler(completer.complete));
62+
// Note: the WebSocketChannel type below is needed for compatibility with
63+
// package:shelf_web_socket v2.
64+
_handler.expect('GET', '/', webSocketHandler((WebSocketChannel ws, _) {
65+
completer.complete(ws);
66+
}));
6367
return completer.future;
6468
}
6569
}

0 commit comments

Comments
 (0)