+1
This commit is contained in:
parent
0466346f2d
commit
ab788d30af
4 changed files with 26 additions and 19 deletions
|
@ -12,7 +12,7 @@
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Dart SDK" level="application" />
|
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -1,5 +1,5 @@
|
||||||
# angel_test
|
# angel_test
|
||||||
[![version 1.0.5](https://img.shields.io/badge/pub-1.0.5-brightgreen.svg)](https://pub.dartlang.org/packages/angel_test)
|
[![version 1.0.5+1](https://img.shields.io/badge/pub-1.0.5+1-brightgreen.svg)](https://pub.dartlang.org/packages/angel_test)
|
||||||
[![build status](https://travis-ci.org/angel-dart/test.svg)](https://travis-ci.org/angel-dart/test)
|
[![build status](https://travis-ci.org/angel-dart/test.svg)](https://travis-ci.org/angel-dart/test)
|
||||||
|
|
||||||
Testing utility library for the Angel framework.
|
Testing utility library for the Angel framework.
|
||||||
|
|
|
@ -23,9 +23,15 @@ final Uuid _uuid = new Uuid();
|
||||||
|
|
||||||
/// Shorthand for bootstrapping a [TestClient].
|
/// Shorthand for bootstrapping a [TestClient].
|
||||||
Future<TestClient> connectTo(Angel app,
|
Future<TestClient> connectTo(Angel app,
|
||||||
{Map initialSession, bool autoDecodeGzip: true}) async =>
|
{Map initialSession, bool autoDecodeGzip: true}) async {
|
||||||
new TestClient(app, autoDecodeGzip: autoDecodeGzip != false)
|
if (!app.isProduction)
|
||||||
..session.addAll(initialSession ?? {});
|
app.properties.putIfAbsent('testMode', () => true);
|
||||||
|
|
||||||
|
for (var plugin in app.justBeforeStart)
|
||||||
|
await plugin(app);
|
||||||
|
return new TestClient(app, autoDecodeGzip: autoDecodeGzip != false)
|
||||||
|
..session.addAll(initialSession ?? {});
|
||||||
|
}
|
||||||
|
|
||||||
/// An `angel_client` that sends mock requests to a server, rather than actual HTTP transactions.
|
/// An `angel_client` that sends mock requests to a server, rather than actual HTTP transactions.
|
||||||
class TestClient extends client.BaseAngelClient {
|
class TestClient extends client.BaseAngelClient {
|
||||||
|
@ -48,9 +54,7 @@ class TestClient extends client.BaseAngelClient {
|
||||||
|
|
||||||
TestClient(this.server, {this.autoDecodeGzip: true}) : super(null, '/');
|
TestClient(this.server, {this.autoDecodeGzip: true}) : super(null, '/');
|
||||||
|
|
||||||
Future close() async {
|
Future close() => server.close();
|
||||||
await server.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Opens a WebSockets connection to the server. This will automatically bind the server
|
/// 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!).
|
/// over HTTP, if it is not already listening. Unfortunately, WebSockets cannot be mocked (yet!).
|
||||||
|
@ -65,13 +69,13 @@ class TestClient extends client.BaseAngelClient {
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<http.Response> sendUnstreamed(
|
Future<http.Response> sendUnstreamed(String method, url,
|
||||||
String method, url, Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
[body, Encoding encoding]) =>
|
[body, Encoding encoding]) =>
|
||||||
send(method, url, headers, body, encoding).then(http.Response.fromStream);
|
send(method, url, headers, body, encoding).then(http.Response.fromStream);
|
||||||
|
|
||||||
Future<http.StreamedResponse> send(
|
Future<http.StreamedResponse> send(String method, url,
|
||||||
String method, url, Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
[body, Encoding encoding]) async {
|
[body, Encoding encoding]) async {
|
||||||
var rq = new MockHttpRequest(
|
var rq = new MockHttpRequest(
|
||||||
method, url is Uri ? url : Uri.parse(url.toString()));
|
method, url is Uri ? url : Uri.parse(url.toString()));
|
||||||
|
@ -80,7 +84,9 @@ class TestClient extends client.BaseAngelClient {
|
||||||
if (authToken?.isNotEmpty == true)
|
if (authToken?.isNotEmpty == true)
|
||||||
rq.headers.set(HttpHeaders.AUTHORIZATION, 'Bearer $authToken');
|
rq.headers.set(HttpHeaders.AUTHORIZATION, 'Bearer $authToken');
|
||||||
|
|
||||||
rq..cookies.addAll(cookies)..session.addAll(session);
|
rq
|
||||||
|
..cookies.addAll(cookies)
|
||||||
|
..session.addAll(session);
|
||||||
|
|
||||||
if (body is Stream<List<int>>) {
|
if (body is Stream<List<int>>) {
|
||||||
await rq.addStream(body);
|
await rq.addStream(body);
|
||||||
|
@ -96,7 +102,8 @@ class TestClient extends client.BaseAngelClient {
|
||||||
} else if (rq.headers.contentType?.mimeType ==
|
} else if (rq.headers.contentType?.mimeType ==
|
||||||
'application/x-www-form-urlencoded') {
|
'application/x-www-form-urlencoded') {
|
||||||
rq.write(body.keys.fold<List<String>>([],
|
rq.write(body.keys.fold<List<String>>([],
|
||||||
(out, k) => out..add('$k=' + Uri.encodeComponent(body[k]))).join());
|
(out, k) => out..add('$k=' + Uri.encodeComponent(body[k])))
|
||||||
|
.join());
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedError(
|
throw new UnsupportedError(
|
||||||
'Map bodies can only be sent for requests with the content type application/json or application/x-www-form-urlencoded.');
|
'Map bodies can only be sent for requests with the content type application/json or application/x-www-form-urlencoded.');
|
||||||
|
@ -130,9 +137,9 @@ class TestClient extends client.BaseAngelClient {
|
||||||
isRedirect: rs.headers[HttpHeaders.LOCATION] != null,
|
isRedirect: rs.headers[HttpHeaders.LOCATION] != null,
|
||||||
headers: extractedHeaders,
|
headers: extractedHeaders,
|
||||||
persistentConnection:
|
persistentConnection:
|
||||||
rq.headers.value(HttpHeaders.CONNECTION)?.toLowerCase()?.trim() ==
|
rq.headers.value(HttpHeaders.CONNECTION)?.toLowerCase()?.trim() ==
|
||||||
'keep-alive' ||
|
'keep-alive' ||
|
||||||
rq.headers.persistentConnection == true,
|
rq.headers.persistentConnection == true,
|
||||||
reasonPhrase: rs.reasonPhrase);
|
reasonPhrase: rs.reasonPhrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ author: "Tobe O <thosakwe@gmail.com>"
|
||||||
description: "Testing utility library for the Angel framework."
|
description: "Testing utility library for the Angel framework."
|
||||||
homepage: "https://github.com/angel-dart/test.git"
|
homepage: "https://github.com/angel-dart/test.git"
|
||||||
name: "angel_test"
|
name: "angel_test"
|
||||||
version: 1.0.5
|
version: 1.0.5+1
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_client: "^1.0.0"
|
angel_client: "^1.0.0"
|
||||||
angel_framework: "^1.0.0-dev"
|
angel_framework: "^1.0.0-dev"
|
||||||
|
|
Loading…
Reference in a new issue