diff --git a/CHANGELOG.md b/CHANGELOG.md index 199efeb1..2d4ab078 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ * Migrated json_god to 4.0.0 (13/13 tests passed) * Migrated angel_client to 4.0.0 (6/13 tests passed) * Migrated angel_websocket to 4.0.0 (2/3 tests passed) -* Updated test to 3.0.0 (in progress) +* Updated test to 4.0.0 (1/1 test passed) * Updated jael to 3.0.0 (in progress) * Updated jael_preprocessor to 3.0.0 (in progress) * Updated angel_jael to 3.0.0 (in progress) @@ -41,7 +41,7 @@ * Updated angel_validate to 3.0.0 * Added and updated json_god to 3.0.0 * Updated angel_client to 3.0.0 -* Updated angel_websocket to 3.0.0 (one issue to be resolved) +* Updated angel_websocket to 3.0.0 * Updated jael to 3.0.0 * Updated jael_preprocessor to 3.0.0 * Updated test to 3.0.0 diff --git a/packages/test/example/main.dart b/packages/test/example/main.dart index d498306d..794d2180 100644 --- a/packages/test/example/main.dart +++ b/packages/test/example/main.dart @@ -6,8 +6,8 @@ import 'package:angel_websocket/server.dart'; import 'package:test/test.dart'; main() { - Angel app; - TestClient client; + Angel? app; + late TestClient client; setUp(() async { app = new Angel() @@ -43,15 +43,15 @@ main() { index: ([params]) async => [ {'michael': 'jackson'} ], - create: (data, [params]) async => {'foo': 'bar'})); + create: (dynamic data, [params]) async => {'foo': 'bar'})); var ws = new AngelWebSocket(app); - await app.configure(ws.configureServer); - app.all('/ws', ws.handleRequest); + await app!.configure(ws.configureServer); + app!.all('/ws', ws.handleRequest); - app.errorHandler = (e, req, res) => e.toJson(); + app!.errorHandler = (e, req, res) => e.toJson(); - client = await connectTo(app); + client = await connectTo(app!); }); tearDown(() async { diff --git a/packages/test/lib/src/client.dart b/packages/test/lib/src/client.dart index aeae1363..9262d649 100644 --- a/packages/test/lib/src/client.dart +++ b/packages/test/lib/src/client.dart @@ -24,7 +24,7 @@ final Uuid _uuid = new Uuid();*/ /// Shorthand for bootstrapping a [TestClient]. Future connectTo(Angel app, - {Map initialSession, + {Map? initialSession, bool autoDecodeGzip: true, bool useZone: false}) async { print("Load configuration"); @@ -58,9 +58,9 @@ class TestClient extends client.BaseAngelClient { final Angel server; @override - String authToken; + String? authToken; - AngelHttp _http; + late AngelHttp _http; TestClient(this.server, {this.autoDecodeGzip: true, bool useZone: false}) : super(http.IOClient(), '/') { @@ -68,14 +68,14 @@ class TestClient extends client.BaseAngelClient { } Future close() { - this.client.close(); + this.client!.close(); return server.close(); } /// Opens a WebSockets connection to the server. This will automatically bind the server /// over HTTP, if it is not already listening. Unfortunately, WebSockets cannot be mocked (yet!). Future websocket( - {String path: '/ws', Duration timeout}) async { + {String path: '/ws', Duration? timeout}) async { if (_http.server == null) await _http.startServer(); var url = _http.uri.replace(scheme: 'ws', path: path); var ws = _MockWebSockets(this, url.toString()); @@ -93,7 +93,7 @@ class TestClient extends client.BaseAngelClient { rq.headers.add('authorization', 'Basic $encoded'); } else if (rq.headers.value('authorization')?.startsWith('Basic ') == true) { - var encoded = rq.headers.value('authorization').substring(6); + var encoded = rq.headers.value('authorization')!.substring(6); var decoded = utf8.decode(base64Url.decode(encoded)); var oldRq = rq; var newRq = MockHttpRequest(rq.method, rq.uri.replace(userInfo: decoded)); @@ -139,14 +139,14 @@ class TestClient extends client.BaseAngelClient { isRedirect: rs.headers['location'] != null, headers: extractedHeaders, persistentConnection: - rq.headers.value('connection')?.toLowerCase()?.trim() == + rq.headers.value('connection')?.toLowerCase().trim() == 'keep-alive', //|| keepAliveState, reasonPhrase: rs.reasonPhrase); } @override - String basePath; + late String basePath; @override Stream authenticateViaPopup(String url, {String eventName: 'token'}) { @@ -160,7 +160,7 @@ class TestClient extends client.BaseAngelClient { @override client.Service service(String path, - {Type type, client.AngelDeserializer deserializer}) { + {Type? type, client.AngelDeserializer? deserializer}) { String uri = path.toString().replaceAll(_straySlashes, ""); return _services.putIfAbsent(uri, () => _MockService(this, uri, deserializer: deserializer)) @@ -172,12 +172,12 @@ class _MockService extends client.BaseAngelService { final TestClient _app; _MockService(this._app, String basePath, - {client.AngelDeserializer deserializer}) + {client.AngelDeserializer? deserializer}) : super(null, _app, basePath, deserializer: deserializer); @override Future send(http.BaseRequest request) { - if (app.authToken != null && app.authToken.isNotEmpty) { + if (app.authToken != null && app.authToken!.isNotEmpty) { request.headers['authorization'] ??= 'Bearer ${app.authToken}'; } diff --git a/packages/test/lib/src/matchers.dart b/packages/test/lib/src/matchers.dart index 4fc664b0..8f95670e 100644 --- a/packages/test/lib/src/matchers.dart +++ b/packages/test/lib/src/matchers.dart @@ -9,7 +9,9 @@ import 'package:angel_validate/angel_validate.dart'; /// /// You can optionally check for a matching [message], [statusCode] and [errors]. Matcher isAngelHttpException( - {String message, int statusCode, Iterable errors: const []}) => + {String? message, + int? statusCode, + Iterable errors: const []}) => new _IsAngelHttpException( message: message, statusCode: statusCode, errors: errors); @@ -98,7 +100,7 @@ class _HasContentType extends Matcher { if (!item.headers.containsKey('content-type')) return false; if (contentType is ContentType) { - var compare = ContentType.parse(item.headers['content-type']); + var compare = ContentType.parse(item.headers['content-type']!); return equals(contentType.mimeType) .matches(compare.mimeType, matchState); } else { @@ -136,7 +138,7 @@ class _HasHeader extends Matcher { Iterable v = value is Iterable ? (value as Iterable) : [value]; return v .map((x) => x.toString()) - .every(item.headers[key.toLowerCase()].split(',').contains); + .every(item.headers[key.toLowerCase()]!.split(',').contains); } } else { return false; @@ -182,13 +184,13 @@ class _HasValidBody extends Matcher { } class _IsAngelHttpException extends Matcher { - String message; - int statusCode; + String? message; + int? statusCode; final List errors = []; _IsAngelHttpException( {this.message, this.statusCode, Iterable errors: const []}) { - this.errors.addAll(errors ?? []); + this.errors.addAll(errors); } @override diff --git a/packages/test/pubspec.yaml b/packages/test/pubspec.yaml index b34e93e5..37b5fa80 100644 --- a/packages/test/pubspec.yaml +++ b/packages/test/pubspec.yaml @@ -2,40 +2,44 @@ author: Tobe O description: Testing utility library for the Angel framework. Use with package:test. homepage: https://github.com/angel-dart/test.git name: angel_test -version: 3.0.0 +version: 4.0.0 publish_to: none environment: - sdk: ">=2.10.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: angel_client: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/client angel_framework: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/framework angel_http_exception: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/http_exception angel_validate: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/validate angel_websocket: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/websocket - http: ^0.13.0 - matcher: ^0.12.0 - mock_request: ^1.0.0 - web_socket_channel: ^1.2.0 + http: ^0.13.1 + matcher: ^0.12.10 + mock_request: + git: + url: https://github.com/dukefirehawk/angel.git + ref: sdk-2.12.x_nnbd + path: packages/mock_request + web_socket_channel: ^2.0.0 dev_dependencies: - test: ^1.15.7 + test: ^1.17.1 diff --git a/packages/test/test/simple_test.dart b/packages/test/test/simple_test.dart index bed37d3f..05493336 100644 --- a/packages/test/test/simple_test.dart +++ b/packages/test/test/simple_test.dart @@ -6,13 +6,13 @@ import 'package:angel_websocket/server.dart'; import 'package:test/test.dart'; void main() { - Angel app; - TestClient client; + Angel? app; + late TestClient client; setUp(() async { app = Angel(reflector: MirrorsReflector()) ..get('/hello', (req, res) => 'Hello') - ..get('/user_info', (req, res) => {'u': req.uri.userInfo}) + ..get('/user_info', (req, res) => {'u': req.uri!.userInfo}) ..get( '/error', (req, res) => throw AngelHttpException.forbidden(message: 'Test') @@ -48,12 +48,12 @@ void main() { {'foo': 'bar'})); var ws = AngelWebSocket(app); - await app.configure(ws.configureServer); - app.all('/ws', ws.handleRequest); + await app!.configure(ws.configureServer); + app!.all('/ws', ws.handleRequest); - app.errorHandler = (e, req, res) => e.toJson(); + app!.errorHandler = (e, req, res) => e.toJson(); - client = await connectTo(app, useZone: false); + client = await connectTo(app!, useZone: false); }); tearDown(() async {