Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: web_socket_channel
version: 1.0.4
version: 1.0.5-dev
description: StreamChannel wrappers for WebSockets.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/web_socket_channel
Expand All @@ -13,4 +13,4 @@ dependencies:
stream_channel: '^1.2.0'

dev_dependencies:
test: '^0.12.0'
test: '^0.12.18'
54 changes: 43 additions & 11 deletions test/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('browser')
@Skip(
"This suite requires a WebSocket server, which is currently unsupported\n"
"by the test package (dart-lang/test#330). It's currently set up to talk\n"
"to a hard-coded server on localhost:1234 that is spawned in \n"
"html_test_server.dart.")

import 'dart:async';
import 'dart:html';
Expand All @@ -20,13 +15,34 @@ import 'package:web_socket_channel/html.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

void main() {
var channel;
int port;
setUpAll(() async {
var channel = spawnHybridCode(r"""
import 'dart:io';

import 'package:stream_channel/stream_channel.dart';

hybridMain(StreamChannel channel) async {
var server = await HttpServer.bind('localhost', 0);
server.transform(new WebSocketTransformer()).listen((webSocket) {
webSocket.listen((request) {
webSocket.add(request);
});
});
channel.sink.add(server.port);
}
""", stayAlive: true);

port = await channel.stream.first;
});

WebSocketChannel channel;
tearDown(() {
if (channel != null) channel.sink.close();
});

test("communicates using an existing WebSocket", () async {
var webSocket = new WebSocket("ws://localhost:1234");
var webSocket = new WebSocket("ws://localhost:$port");
channel = new HtmlWebSocketChannel(webSocket);

var queue = new StreamQueue(channel.stream);
Expand All @@ -42,7 +58,7 @@ void main() {
});

test("communicates using an existing open WebSocket", () async {
var webSocket = new WebSocket("ws://localhost:1234");
var webSocket = new WebSocket("ws://localhost:$port");
await webSocket.onOpen.first;

channel = new HtmlWebSocketChannel(webSocket);
Expand All @@ -53,7 +69,7 @@ void main() {
});

test(".connect defaults to binary lists", () async {
channel = new HtmlWebSocketChannel.connect("ws://localhost:1234");
channel = new HtmlWebSocketChannel.connect("ws://localhost:$port");

var queue = new StreamQueue(channel.stream);
channel.sink.add("foo");
Expand All @@ -65,7 +81,7 @@ void main() {

test(".connect can use blobs", () async {
channel = new HtmlWebSocketChannel.connect(
"ws://localhost:1234", binaryType: BinaryType.blob);
"ws://localhost:$port", binaryType: BinaryType.blob);

var queue = new StreamQueue(channel.stream);
channel.sink.add("foo");
Expand All @@ -77,9 +93,25 @@ void main() {

test(".connect wraps a connection error in WebSocketChannelException",
() async {
// Spawn a server that will immediately reject the connection.
var serverChannel = spawnHybridCode(r"""
import 'dart:io';

import 'package:stream_channel/stream_channel.dart';

hybridMain(StreamChannel channel) async {
var server = await ServerSocket.bind('localhost', 0);
server.listen((socket) {
socket.close();
});
channel.sink.add(server.port);
}
""");

// TODO(nweiz): Make this channel use a port number that's guaranteed to be
// invalid.
var channel = new HtmlWebSocketChannel.connect("ws://localhost:1235");
var channel = new HtmlWebSocketChannel.connect(
"ws://localhost:${await serverChannel.stream.first}");
expect(channel.stream.toList(),
throwsA(new isInstanceOf<WebSocketChannelException>()));
});
Expand Down
16 changes: 0 additions & 16 deletions test/html_test_server.dart

This file was deleted.