Index: test/runner/browser/firefox_test.dart |
diff --git a/test/runner/browser/firefox_test.dart b/test/runner/browser/firefox_test.dart |
index 4539641dfccddd650ced2e4787740ac8da26a36d..f123679b09f524c0d86d71457c90979e7adfe8d6 100644 |
--- a/test/runner/browser/firefox_test.dart |
+++ b/test/runner/browser/firefox_test.dart |
@@ -4,150 +4,47 @@ |
@TestOn("vm") |
-import 'dart:async'; |
-import 'dart:io'; |
- |
-import 'package:path/path.dart' as p; |
-import 'package:test/test.dart'; |
+import 'package:scheduled_test/descriptor.dart' as d; |
+import 'package:scheduled_test/scheduled_stream.dart'; |
+import 'package:scheduled_test/scheduled_test.dart'; |
import 'package:test/src/runner/browser/firefox.dart'; |
-import 'package:test/src/util/io.dart'; |
-import 'package:shelf/shelf.dart' as shelf; |
-import 'package:shelf/shelf_io.dart' as shelf_io; |
-import 'package:shelf_web_socket/shelf_web_socket.dart'; |
import '../../io.dart'; |
import '../../utils.dart'; |
- |
-String _sandbox; |
+import 'code_server.dart'; |
void main() { |
- setUp(() { |
- _sandbox = createTempDir(); |
- }); |
+ useSandbox(); |
- tearDown(() { |
- new Directory(_sandbox).deleteSync(recursive: true); |
- }); |
+ test("starts Firefox with the given URL", () { |
+ var server = new CodeServer(); |
- group("running JavaScript", () { |
- // The JavaScript to serve in the server. We use actual JavaScript here to |
- // avoid the pain of compiling to JS in a test |
- var javaScript; |
- |
- var servePage = (request) { |
- var path = request.url.path; |
- |
- // We support both shelf 0.5.x and 0.6.x. The former has a leading "/" |
- // here, the latter does not. |
- if (path.startsWith("/")) path = path.substring(1); |
- |
- if (path.isEmpty) { |
- return new shelf.Response.ok(""" |
-<!doctype html> |
-<html> |
-<head> |
- <script src="index.js"></script> |
-</head> |
-</html> |
-""", headers: {'content-type': 'text/html'}); |
- } else if (path == "index.js") { |
- return new shelf.Response.ok(javaScript, |
- headers: {'content-type': 'application/javascript'}); |
- } else { |
- return new shelf.Response.notFound(null); |
- } |
- }; |
- |
- var server; |
- var webSockets; |
- setUp(() async { |
- var webSocketsController = new StreamController(); |
- webSockets = webSocketsController.stream; |
- |
- server = await shelf_io.serve( |
- new shelf.Cascade() |
- .add(webSocketHandler(webSocketsController.add)) |
- .add(servePage).handler, |
- 'localhost', 0); |
+ schedule(() async { |
+ var firefox = new Firefox(await server.url); |
+ currentSchedule.onComplete.schedule(() async => (await firefox).close()); |
}); |
- tearDown(() { |
- if (server != null) server.close(); |
- |
- javaScript = null; |
- server = null; |
- webSockets = null; |
- }); |
- |
- test("starts Firefox with the given URL", () async { |
- javaScript = ''' |
+ server.handleJavaScript(''' |
var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); |
webSocket.addEventListener("open", function() { |
webSocket.send("loaded!"); |
}); |
-'''; |
- var firefox = new Firefox(baseUrlForAddress(server.address, server.port)); |
- |
- try { |
- var message = await (await webSockets.first).first; |
- expect(message, equals("loaded!")); |
- } finally { |
- firefox.close(); |
- } |
- }); |
+'''); |
- test("doesn't preserve state across runs", () { |
- javaScript = ''' |
-localStorage.setItem("data", "value"); |
+ var webSocket = server.handleWebSocket(); |
-var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); |
-webSocket.addEventListener("open", function() { |
- webSocket.send("done"); |
-}); |
-'''; |
- var firefox = new Firefox(baseUrlForAddress(server.address, server.port)); |
- |
- var first = true; |
- webSockets.listen(expectAsync((webSocket) { |
- if (first) { |
- // The first request will set local storage data. We can't kill the |
- // old firefox and start a new one until we're sure that that has |
- // finished. |
- webSocket.first.then((_) { |
- firefox.close(); |
- |
- javaScript = ''' |
-var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); |
-webSocket.addEventListener("open", function() { |
- webSocket.send(localStorage.getItem("data")); |
-}); |
-'''; |
- firefox = new Firefox(baseUrlForAddress(server.address, server.port)); |
- first = false; |
- }); |
- } else { |
- // The second request will return the local storage data. This should |
- // be null, indicating that no data was saved between runs. |
- expect( |
- webSocket.first |
- .then((message) => expect(message, equals('null'))) |
- .whenComplete(firefox.close), |
- completes); |
- } |
- }, count: 2)); |
+ schedule(() async { |
+ expect(await (await webSocket).first, equals("loaded!")); |
}); |
}); |
test("a process can be killed synchronously after it's started", () async { |
- var server = await shelf_io.serve( |
- expectAsync((_) {}, count: 0), 'localhost', 0); |
+ var server = new CodeServer(); |
- try { |
- var firefox = new Firefox(baseUrlForAddress(server.address, server.port)); |
+ schedule(() async { |
+ var firefox = new Firefox(await server.url); |
await firefox.close(); |
- } finally { |
- server.close(); |
- } |
+ }); |
}); |
test("reports an error in onExit", () { |
@@ -157,45 +54,31 @@ webSocket.addEventListener("open", function() { |
"Failed to run Firefox: $noSuchFileMessage")))); |
}); |
- group("can run successful tests", () { |
- setUp(() { |
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
+ test("can run successful tests", () { |
+ d.file("test.dart", """ |
import 'package:test/test.dart'; |
void main() { |
test("success", () {}); |
} |
-"""); |
- }); |
+""").create(); |
- test("itself", () { |
- var result = _runTest(["-p", "firefox", "test.dart"]); |
- expect(result.exitCode, equals(0)); |
- }); |
- |
- test("alongside another browser", () { |
- var result = _runTest(["-p", "firefox", "-p", "chrome", "test.dart"]); |
- |
- // Only one browser should compile the code. |
- expect(result.stdout.contains("[Chrome] compiling"), |
- isNot(result.stdout.contains("[Firefox] compiling"))); |
- expect(result.exitCode, equals(0)); |
- }); |
+ var test = runTest(["-p", "firefox", "test.dart"]); |
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
+ test.shouldExit(0); |
}); |
test("can run failing tests", () { |
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
+ d.file("test.dart", """ |
import 'package:test/test.dart'; |
void main() { |
test("failure", () => throw new TestFailure("oh no")); |
} |
-"""); |
+""").create(); |
- var result = _runTest(["-p", "firefox", "test.dart"]); |
- expect(result.exitCode, equals(1)); |
+ var test = runTest(["-p", "firefox", "test.dart"]); |
+ test.stdout.expect(consumeThrough(contains("-1: Some tests failed."))); |
+ test.shouldExit(1); |
}); |
} |
- |
-ProcessResult _runTest(List<String> args) => |
- runTest(args, workingDirectory: _sandbox); |