2016-12-23 20:57:46 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:angel_framework/angel_framework.dart' as srv;
|
|
|
|
import 'package:angel_websocket/io.dart' as ws;
|
|
|
|
import 'package:angel_websocket/server.dart' as srv;
|
2017-09-24 04:37:58 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2016-12-23 20:57:46 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'common.dart';
|
|
|
|
|
|
|
|
main() {
|
|
|
|
srv.Angel app;
|
|
|
|
ws.WebSockets client;
|
|
|
|
srv.AngelWebSocket websockets;
|
|
|
|
HttpServer server;
|
|
|
|
String url;
|
|
|
|
|
|
|
|
setUp(() async {
|
|
|
|
app = new srv.Angel()..use('/api/todos', new TodoService());
|
|
|
|
|
2017-09-24 04:37:58 +00:00
|
|
|
websockets = new srv.AngelWebSocket(app)
|
2016-12-23 20:57:46 +00:00
|
|
|
..onData.listen((data) {
|
|
|
|
print('Received by server: $data');
|
|
|
|
});
|
|
|
|
|
2017-09-24 04:37:58 +00:00
|
|
|
await app.configure(websockets.configureServer);
|
|
|
|
app.all('/ws', websockets.handleRequest);
|
|
|
|
app.logger = new Logger('angel_auth')..onRecord.listen(print);
|
2017-01-28 21:38:26 +00:00
|
|
|
server = await app.startServer();
|
2016-12-23 20:57:46 +00:00
|
|
|
url = 'ws://${server.address.address}:${server.port}/ws';
|
|
|
|
|
|
|
|
client = new ws.WebSockets(url);
|
|
|
|
await client.connect();
|
|
|
|
|
|
|
|
client
|
|
|
|
..onData.listen((data) {
|
|
|
|
print('Received by client: $data');
|
|
|
|
})
|
|
|
|
..onError.listen((error) {
|
|
|
|
// Auto-fail tests on errors ;)
|
|
|
|
stderr.writeln(error);
|
|
|
|
error.errors.forEach(stderr.writeln);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
await client.close();
|
|
|
|
await server.close(force: true);
|
|
|
|
app = null;
|
|
|
|
client = null;
|
|
|
|
server = null;
|
|
|
|
url = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
group('service.io', () {
|
|
|
|
test('index', () => testIndex(client));
|
|
|
|
});
|
|
|
|
}
|