2016-12-23 20:57:46 +00:00
|
|
|
import 'dart:io';
|
2018-08-28 14:17:14 +00:00
|
|
|
import 'package:angel_container/mirrors.dart';
|
2016-12-23 20:57:46 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart' as srv;
|
2018-10-22 23:01:24 +00:00
|
|
|
import "package:angel_framework/http.dart" as srv;
|
2016-12-23 20:57:46 +00:00
|
|
|
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;
|
2018-07-10 16:54:55 +00:00
|
|
|
srv.AngelHttp http;
|
2016-12-23 20:57:46 +00:00
|
|
|
ws.WebSockets client;
|
|
|
|
srv.AngelWebSocket websockets;
|
|
|
|
HttpServer server;
|
|
|
|
String url;
|
|
|
|
|
|
|
|
setUp(() async {
|
2018-08-28 14:17:14 +00:00
|
|
|
app = new srv.Angel(reflector: const MirrorsReflector());
|
2018-07-10 16:54:55 +00:00
|
|
|
http = new srv.AngelHttp(app, useZone: false);
|
2016-12-23 20:57:46 +00:00
|
|
|
|
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);
|
2017-10-19 22:26:59 +00:00
|
|
|
await app.configure(new GameController(websockets).configureServer);
|
2017-09-24 04:37:58 +00:00
|
|
|
app.logger = new Logger('angel_auth')..onRecord.listen(print);
|
2016-12-23 20:57:46 +00:00
|
|
|
|
2018-07-10 16:54:55 +00:00
|
|
|
server = await http.startServer();
|
2016-12-23 20:57:46 +00:00
|
|
|
url = 'ws://${server.address.address}:${server.port}/ws';
|
|
|
|
|
|
|
|
client = new ws.WebSockets(url);
|
2017-02-28 14:15:34 +00:00
|
|
|
await client.connect(timeout: new Duration(seconds: 3));
|
2016-12-23 20:57:46 +00:00
|
|
|
|
2018-08-28 14:17:14 +00:00
|
|
|
print('Connected');
|
|
|
|
|
2016-12-23 20:57:46 +00:00
|
|
|
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();
|
2018-07-10 16:54:55 +00:00
|
|
|
await http.close();
|
2016-12-23 20:57:46 +00:00
|
|
|
app = null;
|
|
|
|
client = null;
|
|
|
|
server = null;
|
|
|
|
url = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
group('controller.io', () {
|
|
|
|
test('search', () async {
|
|
|
|
client.send('search', new ws.WebSocketAction());
|
2016-12-24 01:45:52 +00:00
|
|
|
var search = await client.on['searched'].first;
|
|
|
|
print('Searched: ${search.data}');
|
2018-07-10 16:54:55 +00:00
|
|
|
expect(new Game.fromJson(search.data as Map), equals(johnVsBob));
|
2016-12-23 20:57:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|