-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Workiva/improvements-and-tests
CP-1099 Add close() to client. Add integration tests.
- Loading branch information
Showing
13 changed files
with
281 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.project | ||
packages | ||
|
||
.packages | ||
.pub | ||
packages | ||
pubspec.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "sockjs-dart-client", | ||
"version": "0.2.0", | ||
"description": "A SockJS client in Dart", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/Workiva/sockjs-dart-client.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Workiva/sockjs-dart-client/issues" | ||
}, | ||
"homepage": "https://github.com/Workiva/sockjs-dart-client", | ||
"devDependencies": { | ||
"http": "0.0.0", | ||
"sockjs": "^0.3.15" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
@TestOn('browser') | ||
library sockjs_client.test.sockjs_client_test; | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:sockjs_client/sockjs_client.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
const String echoUri = 'http://localhost:8000/echo'; | ||
const String corUri = 'http://localhost:8000/cor'; | ||
const String fofUri = 'http://localhost:8600/404'; | ||
|
||
void main() { | ||
group('SockJS Client', () { | ||
group('default', () { | ||
Client createEchoClient() => new Client(echoUri); | ||
Client createCorClient() => new Client(corUri); | ||
Client create404Client() => new Client(fofUri); | ||
|
||
integrationSuite(createEchoClient, createCorClient, create404Client); | ||
}); | ||
|
||
group('web-socket', () { | ||
Client createEchoClient() => new Client(echoUri, protocolsWhitelist: ['websocket']); | ||
Client createCorClient() => new Client(corUri, protocolsWhitelist: ['websocket']); | ||
Client create404Client() => new Client(fofUri, protocolsWhitelist: ['websocket']); | ||
|
||
integrationSuite(createEchoClient, createCorClient, create404Client); | ||
}); | ||
|
||
group('xhr-streaming', () { | ||
Client createEchoClient() => new Client(echoUri, protocolsWhitelist: ['xhr-streaming']); | ||
Client createCorClient() => new Client(corUri, protocolsWhitelist: ['xhr-streaming']); | ||
Client create404Client() => new Client(fofUri, protocolsWhitelist: ['xhr-streaming']); | ||
|
||
integrationSuite(createEchoClient, createCorClient, create404Client); | ||
}); | ||
}); | ||
} | ||
|
||
void integrationSuite(Client createEchoClient(), Client createCorClient(), Client create404Client()) { | ||
test('connecting to a SockJS server', () async { | ||
Client client = createEchoClient(); | ||
await client.onOpen.first; | ||
}); | ||
|
||
test('sending and receiving messages', () async { | ||
Client client = createEchoClient(); | ||
await client.onOpen.first; | ||
|
||
Completer c = new Completer(); | ||
var echos = []; | ||
client.onMessage.listen((MessageEvent message) { | ||
echos.add(message.data); | ||
if (echos.length == 2) { | ||
c.complete(); | ||
} | ||
}); | ||
client.send('message1'); | ||
client.send('message2'); | ||
|
||
await c.future; | ||
client.close(); | ||
|
||
expect(echos, equals(['message1', 'message2'])); | ||
}); | ||
|
||
test('client closing the connection', () async { | ||
Client client = createEchoClient(); | ||
await client.onOpen.first; | ||
client.close(); | ||
await client.onClose.first; | ||
}); | ||
|
||
test('client closing the connection with code and reason', () async { | ||
Client client = createEchoClient(); | ||
await client.onOpen.first; | ||
client.close(4001, 'Custom close.'); | ||
CloseEvent event = await client.onClose.first; | ||
expect(event.code, equals(4001)); | ||
expect(event.reason, equals('Custom close.')); | ||
}); | ||
|
||
test('server closing the connection', () async { | ||
Client client = createCorClient(); | ||
await client.onOpen.first; | ||
client.send('close'); | ||
await client.onClose.first; | ||
}); | ||
|
||
test('server closing the connection with code and reason', () async { | ||
Client client = createCorClient(); | ||
await client.onOpen.first; | ||
client.send('close::4001::Custom close.'); | ||
CloseEvent event = await client.onClose.first; | ||
expect(event.code, equals(4001)); | ||
expect(event.reason, equals('Custom close.')); | ||
}); | ||
|
||
test('handle failed connection', () async { | ||
Client client = create404Client(); | ||
await client.onClose.first; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script type="application/dart" src="sockjs_client_integration_test.dart"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
library tool.dev; | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:dart_dev/dart_dev.dart' show dev, config; | ||
import 'package:dart_dev/util.dart' show TaskProcess, reporter; | ||
|
||
main(List<String> args) async { | ||
// https://github.com/Workiva/dart_dev | ||
|
||
config.analyze.entryPoints = ['example/', 'lib/', 'tool/']; | ||
config.format.directories = ['example/', 'lib/', 'tool/']; | ||
|
||
config.coverage | ||
..before = [_startServer] | ||
..after = [_stopServer]; | ||
config.test | ||
..before = [_startServer] | ||
..after = [_stopServer] | ||
..unitTests = [] | ||
..integrationTests = ['test/sockjs_client_integration_test.dart'] | ||
..platforms = ['content-shell', 'dartium']; | ||
|
||
await dev(args); | ||
} | ||
|
||
/// Server needed for integration tests and examples. | ||
TaskProcess _server; | ||
|
||
/// Output from the server (only used if caching the output to dump at the end). | ||
List<String> _serverOutput; | ||
|
||
/// Start the server needed for integration tests and cache the server output | ||
/// until the task requiring the server has finished. Then, the server output | ||
/// will be dumped all at once. | ||
Future _startServer() async { | ||
_serverOutput = []; | ||
_server = new TaskProcess('node', ['tool/server.js']); | ||
_server.stdout.listen(_serverOutput.add); | ||
_server.stderr.listen(_serverOutput.add); | ||
// todo: wait for server to start | ||
} | ||
|
||
/// Stop the server needed for integration tests. | ||
Future _stopServer() async { | ||
if (_serverOutput != null) { | ||
reporter.logGroup('HTTP Server Logs', | ||
output: ' ${_serverOutput.join('\n')}'); | ||
} | ||
if (_server != null) { | ||
try { | ||
_server.kill(); | ||
} catch (e) {} | ||
} | ||
} |
Oops, something went wrong.