Skip to content

Commit

Permalink
Update the use of 'package:shelf_web_socket's webSocketHandler meth…
Browse files Browse the repository at this point in the history
…od (#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 <jakemac@google.com>
  • Loading branch information
devoncarew and jakemac53 authored Dec 3, 2024
1 parent 1d28d73 commit 2096773
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.25.11

* Update to be forward compatible with `package:shelf_web_socket` version `3.x`.

## 1.25.10

* Update the `package:vm_service` constraint to allow version `15.x`.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ import 'package:stream_channel/stream_channel.dart';
// returned spawnHybridCode().
hybridMain(StreamChannel channel) async {
// Start a WebSocket server that just sends "hello!" to its clients.
var server = await io.serve(webSocketHandler((webSocket) {
var server = await io.serve(webSocketHandler((webSocket, _) {
webSocket.sink.add('hello!');
}), 'localhost', 0);
Expand Down
7 changes: 6 additions & 1 deletion pkgs/test/lib/src/runner/browser/compilers/dart2js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ class Dart2JsSupport extends CompilerSupport with JsHtmlWrapper {
@override
(Uri, Future<WebSocketChannel>) get webSocket {
var completer = Completer<WebSocketChannel>.sync();
var path = _webSocketHandler.create(webSocketHandler(completer.complete));
// Note: the WebSocketChannel type below is needed for compatibility with
// package:shelf_web_socket v2.
var path =
_webSocketHandler.create(webSocketHandler((WebSocketChannel ws, _) {
completer.complete(ws);
}));
var webSocketUrl = serverUrl.replace(scheme: 'ws').resolve(path);
return (webSocketUrl, completer.future);
}
Expand Down
7 changes: 6 additions & 1 deletion pkgs/test/lib/src/runner/browser/compilers/dart2wasm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ class Dart2WasmSupport extends CompilerSupport with WasmHtmlWrapper {
@override
(Uri, Future<WebSocketChannel>) get webSocket {
var completer = Completer<WebSocketChannel>.sync();
var path = _webSocketHandler.create(webSocketHandler(completer.complete));
// Note: the WebSocketChannel type below is needed for compatibility with
// package:shelf_web_socket v2.
var path =
_webSocketHandler.create(webSocketHandler((WebSocketChannel ws, _) {
completer.complete(ws);
}));
var webSocketUrl = serverUrl.replace(scheme: 'ws').resolve(path);
return (webSocketUrl, completer.future);
}
Expand Down
7 changes: 6 additions & 1 deletion pkgs/test/lib/src/runner/browser/compilers/precompiled.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ abstract class PrecompiledSupport extends CompilerSupport {
@override
(Uri, Future<WebSocketChannel>) get webSocket {
var completer = Completer<WebSocketChannel>.sync();
var path = _webSocketHandler.create(webSocketHandler(completer.complete));
// Note: the WebSocketChannel type below is needed for compatibility with
// package:shelf_web_socket v2.
var path =
_webSocketHandler.create(webSocketHandler((WebSocketChannel ws, _) {
completer.complete(ws);
}));
var webSocketUrl = serverUrl.replace(scheme: 'ws').resolve(path);
return (webSocketUrl, completer.future);
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test
version: 1.25.10
version: 1.25.11
description: >-
A full featured library for writing and running Dart tests across platforms.
repository: https://github.com/dart-lang/test/tree/master/pkgs/test
Expand Down
6 changes: 5 additions & 1 deletion pkgs/test/test/runner/browser/code_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class CodeServer {
/// future that will complete to the WebSocket.
Future<WebSocketChannel> handleWebSocket() {
var completer = Completer<WebSocketChannel>();
_handler.expect('GET', '/', webSocketHandler(completer.complete));
// Note: the WebSocketChannel type below is needed for compatibility with
// package:shelf_web_socket v2.
_handler.expect('GET', '/', webSocketHandler((WebSocketChannel ws, _) {
completer.complete(ws);
}));
return completer.future;
}
}
Expand Down

0 comments on commit 2096773

Please sign in to comment.