Migrate from pkg/scheduled_test and enable travis (#5)
* Stop using pkg/scheduled_test
* Add analysis_options, enable travis
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..2fb8c53
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,24 @@
+language: dart
+
+dart:
+ - dev
+ - stable
+ - 1.23.0
+
+dart_task:
+ - test
+
+matrix:
+ include:
+ - dart: dev
+ dart_task: dartfmt
+ - dart: dev
+ dart_task: dartanalyzer
+
+# Only building master means that we don't run two builds for each pull request.
+branches:
+ only: [master]
+
+cache:
+ directories:
+ - $HOME/.pub-cache
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..a10d4c5
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,2 @@
+analyzer:
+ strong-mode: true
diff --git a/pubspec.yaml b/pubspec.yaml
index bca7772..a9bfb23 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,11 +3,12 @@
author: Dart Team <misc@dartlang.org>
description: A shelf handler for proxying requests to another server.
homepage: https://github.com/dart-lang/shelf_proxy
+environment:
+ sdk: '>=1.23.0 <2.0.0'
dependencies:
http: '>=0.9.0 <0.12.0'
path: '>=1.0.0 <2.0.0'
shelf: '>=0.5.2 <0.8.0'
dev_dependencies:
browser: '>=0.10.0 <0.11.0'
- scheduled_test: '>=0.12.0 <0.13.0'
test: '>=0.12.0 <0.13.0'
diff --git a/test/shelf_proxy_test.dart b/test/shelf_proxy_test.dart
index de6f032..160d8e9 100644
--- a/test/shelf_proxy_test.dart
+++ b/test/shelf_proxy_test.dart
@@ -6,7 +6,7 @@
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
-import 'package:scheduled_test/scheduled_test.dart';
+import 'package:test/test.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_proxy/shelf_proxy.dart';
@@ -19,173 +19,138 @@
void main() {
group("forwarding", () {
- test("forwards request method", () {
- createProxy((request) {
+ test("forwards request method", () async {
+ await createProxy((request) {
expect(request.method, equals('DELETE'));
return new shelf.Response.ok(':)');
});
- schedule(() => http.delete(proxyUri));
+ await http.delete(proxyUri);
});
- test("forwards request headers", () {
- createProxy((request) {
+ test("forwards request headers", () async {
+ await createProxy((request) {
expect(request.headers, containsPair('foo', 'bar'));
expect(request.headers, containsPair('accept', '*/*'));
return new shelf.Response.ok(':)');
});
- get(headers: {'foo': 'bar', 'accept': '*/*'});
+ await get(headers: {'foo': 'bar', 'accept': '*/*'});
});
- test("forwards request body", () {
- createProxy((request) {
+ test("forwards request body", () async {
+ await createProxy((request) {
expect(request.readAsString(), completion(equals('hello, server')));
return new shelf.Response.ok(':)');
});
- schedule(() => http.post(proxyUri, body: 'hello, server'));
+ await http.post(proxyUri, body: 'hello, server');
});
- test("forwards response status", () {
- createProxy((request) {
+ test("forwards response status", () async {
+ await createProxy((request) {
return new shelf.Response(567);
});
- expect(
- get().then((response) {
- expect(response.statusCode, equals(567));
- }),
- completes);
+ var response = await get();
+ expect(response.statusCode, equals(567));
});
- test("forwards response headers", () {
- createProxy((request) {
+ test("forwards response headers", () async {
+ await createProxy((request) {
return new shelf.Response.ok(':)',
headers: {'foo': 'bar', 'accept': '*/*'});
});
- expect(
- get().then((response) {
- expect(response.headers, containsPair('foo', 'bar'));
- expect(response.headers, containsPair('accept', '*/*'));
- }),
- completes);
+ var response = await get();
+
+ expect(response.headers, containsPair('foo', 'bar'));
+ expect(response.headers, containsPair('accept', '*/*'));
});
- test("forwards response body", () {
- createProxy((request) {
+ test("forwards response body", () async {
+ await createProxy((request) {
return new shelf.Response.ok('hello, client');
});
- expect(schedule(() => http.read(proxyUri)),
- completion(equals('hello, client')));
+ expect(await http.read(proxyUri), equals('hello, client'));
});
- test("adjusts the Host header for the target server", () {
- createProxy((request) {
+ test("adjusts the Host header for the target server", () async {
+ await createProxy((request) {
expect(request.headers, containsPair('host', targetUri.authority));
return new shelf.Response.ok(':)');
});
- get();
+ await get();
});
});
group("via", () {
- test("adds a Via header to the request", () {
- createProxy((request) {
+ test("adds a Via header to the request", () async {
+ await createProxy((request) {
expect(request.headers, containsPair('via', '1.1 shelf_proxy'));
return new shelf.Response.ok(':)');
});
- get();
+ await get();
});
- test("adds to a request's existing Via header", () {
- createProxy((request) {
+ test("adds to a request's existing Via header", () async {
+ await createProxy((request) {
expect(request.headers,
containsPair('via', '1.0 something, 1.1 shelf_proxy'));
return new shelf.Response.ok(':)');
});
- get(headers: {'via': '1.0 something'});
+ await get(headers: {'via': '1.0 something'});
});
- test("adds a Via header to the response", () {
- createProxy((request) => new shelf.Response.ok(':)'));
+ test("adds a Via header to the response", () async {
+ await createProxy((request) => new shelf.Response.ok(':)'));
- expect(
- get().then((response) {
- expect(response.headers, containsPair('via', '1.1 shelf_proxy'));
- }),
- completes);
+ var response = await get();
+ expect(response.headers, containsPair('via', '1.1 shelf_proxy'));
});
- test("adds to a response's existing Via header", () {
- createProxy((request) {
+ test("adds to a response's existing Via header", () async {
+ await createProxy((request) {
return new shelf.Response.ok(':)', headers: {'via': '1.0 something'});
});
- expect(
- get().then((response) {
- expect(response.headers,
- containsPair('via', '1.0 something, 1.1 shelf_proxy'));
- }),
- completes);
- });
-
- test("adds to a response's existing Via header", () {
- createProxy((request) {
- return new shelf.Response.ok(':)', headers: {'via': '1.0 something'});
- });
-
- expect(
- get().then((response) {
- expect(response.headers,
- containsPair('via', '1.0 something, 1.1 shelf_proxy'));
- }),
- completes);
+ var response = await get();
+ expect(response.headers,
+ containsPair('via', '1.0 something, 1.1 shelf_proxy'));
});
});
group("redirects", () {
- test("doesn't modify a Location for a foreign server", () {
- createProxy((request) {
+ test("doesn't modify a Location for a foreign server", () async {
+ await createProxy((request) {
return new shelf.Response.found('http://dartlang.org');
});
- expect(
- get().then((response) {
- expect(response.headers,
- containsPair('location', 'http://dartlang.org'));
- }),
- completes);
+ var response = await get();
+ expect(response.headers, containsPair('location', 'http://dartlang.org'));
});
- test("relativizes a reachable root-relative Location", () {
- createProxy((request) {
+ test("relativizes a reachable root-relative Location", () async {
+ await createProxy((request) {
return new shelf.Response.found('/foo/bar');
}, targetPath: '/foo');
- expect(
- get().then((response) {
- expect(response.headers, containsPair('location', '/bar'));
- }),
- completes);
+ var response = await get();
+ expect(response.headers, containsPair('location', '/bar'));
});
- test("absolutizes an unreachable root-relative Location", () {
- createProxy((request) {
+ test("absolutizes an unreachable root-relative Location", () async {
+ await createProxy((request) {
return new shelf.Response.found('/baz');
}, targetPath: '/foo');
- expect(
- get().then((response) {
- expect(response.headers,
- containsPair('location', targetUri.resolve('/baz').toString()));
- }),
- completes);
+ var response = await get();
+ expect(response.headers,
+ containsPair('location', targetUri.resolve('/baz').toString()));
});
});
@@ -222,23 +187,21 @@
///
/// [targetPath] is the root-relative path on the target server to proxy to. It
/// defaults to `/`.
-void createProxy(shelf.Handler handler, {String targetPath}) {
+Future createProxy(shelf.Handler handler, {String targetPath}) async {
handler = expectAsync1(handler, reason: 'target server handler');
- schedule(() async {
- var targetServer = await shelf_io.serve(handler, 'localhost', 0);
- targetUri = Uri.parse('http://localhost:${targetServer.port}');
- if (targetPath != null) targetUri = targetUri.resolve(targetPath);
- var proxyServerHandler =
- expectAsync1(proxyHandler(targetUri), reason: 'proxy server handler');
+ var targetServer = await shelf_io.serve(handler, 'localhost', 0);
+ targetUri = Uri.parse('http://localhost:${targetServer.port}');
+ if (targetPath != null) targetUri = targetUri.resolve(targetPath);
+ var proxyServerHandler =
+ expectAsync1(proxyHandler(targetUri), reason: 'proxy server handler');
- var proxyServer = await shelf_io.serve(proxyServerHandler, 'localhost', 0);
- proxyUri = Uri.parse('http://localhost:${proxyServer.port}');
+ var proxyServer = await shelf_io.serve(proxyServerHandler, 'localhost', 0);
+ proxyUri = Uri.parse('http://localhost:${proxyServer.port}');
- currentSchedule.onComplete.schedule(() {
- proxyServer.close(force: true);
- targetServer.close(force: true);
- }, 'tear down servers');
- }, 'spin up servers');
+ addTearDown(() {
+ proxyServer.close(force: true);
+ targetServer.close(force: true);
+ });
}
/// Creates a [shelf.Handler] that's backed by a [MockClient] running
@@ -251,11 +214,9 @@
/// Schedules a GET request with [headers] to the proxy server.
Future<http.Response> get({Map<String, String> headers}) {
- return schedule(() {
- var uri = proxyUri;
- var request = new http.Request('GET', uri);
- if (headers != null) request.headers.addAll(headers);
- request.followRedirects = false;
- return request.send().then(http.Response.fromStream);
- }, 'GET proxy server');
+ var uri = proxyUri;
+ var request = new http.Request('GET', uri);
+ if (headers != null) request.headers.addAll(headers);
+ request.followRedirects = false;
+ return request.send().then(http.Response.fromStream);
}