| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 @TestOn("vm") | 5 @TestOn("vm") |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| 11 import 'package:test/src/runner/browser/chrome.dart'; | 11 import 'package:test/src/runner/browser/chrome.dart'; |
| 12 import 'package:test/src/util/io.dart'; | 12 import 'package:test/src/util/io.dart'; |
| 13 import 'package:shelf/shelf.dart' as shelf; | 13 import 'package:shelf/shelf.dart' as shelf; |
| 14 import 'package:shelf/shelf_io.dart' as shelf_io; | 14 import 'package:shelf/shelf_io.dart' as shelf_io; |
| 15 import 'package:shelf_web_socket/shelf_web_socket.dart'; | 15 import 'package:shelf_web_socket/shelf_web_socket.dart'; |
| 16 | 16 |
| 17 void main() { | 17 void main() { |
| 18 group("running JavaScript", () { | 18 group("running JavaScript", () { |
| 19 // The JavaScript to serve in the server. We use actual JavaScript here to | 19 // The JavaScript to serve in the server. We use actual JavaScript here to |
| 20 // avoid the pain of compiling to JS in a test | 20 // avoid the pain of compiling to JS in a test |
| 21 var javaScript; | 21 var javaScript; |
| 22 | 22 |
| 23 var servePage = (request) { | 23 var servePage = (request) { |
| 24 if (request.url.path == "/") { | 24 var path = request.url.path; |
| 25 |
| 26 // We support both shelf 0.5.x and 0.6.x. The former has a leading "/" |
| 27 // here, the latter does not. |
| 28 if (path.startsWith("/")) path = path.substring(1); |
| 29 |
| 30 if (path.isEmpty) { |
| 25 return new shelf.Response.ok(""" | 31 return new shelf.Response.ok(""" |
| 26 <!doctype html> | 32 <!doctype html> |
| 27 <html> | 33 <html> |
| 28 <head> | 34 <head> |
| 29 <script src="index.js"></script> | 35 <script src="index.js"></script> |
| 30 </head> | 36 </head> |
| 31 </html> | 37 </html> |
| 32 """, headers: {'content-type': 'text/html'}); | 38 """, headers: {'content-type': 'text/html'}); |
| 33 } else if (request.url.path == "/index.js") { | 39 } else if (path == "index.js") { |
| 34 return new shelf.Response.ok(javaScript, | 40 return new shelf.Response.ok(javaScript, |
| 35 headers: {'content-type': 'application/javascript'}); | 41 headers: {'content-type': 'application/javascript'}); |
| 36 } else { | 42 } else { |
| 37 return new shelf.Response.notFound(null); | 43 return new shelf.Response.notFound(null); |
| 38 } | 44 } |
| 39 }; | 45 }; |
| 40 | 46 |
| 41 var server; | 47 var server; |
| 42 var webSockets; | 48 var webSockets; |
| 43 setUp(() { | 49 setUp(() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return chrome.close().whenComplete(server.close); | 131 return chrome.close().whenComplete(server.close); |
| 126 }); | 132 }); |
| 127 }); | 133 }); |
| 128 | 134 |
| 129 test("reports an error in onExit", () { | 135 test("reports an error in onExit", () { |
| 130 var chrome = new Chrome("http://dart-lang.org", | 136 var chrome = new Chrome("http://dart-lang.org", |
| 131 executable: "_does_not_exist"); | 137 executable: "_does_not_exist"); |
| 132 expect(chrome.onExit, throwsA(new isInstanceOf<ProcessException>())); | 138 expect(chrome.onExit, throwsA(new isInstanceOf<ProcessException>())); |
| 133 }); | 139 }); |
| 134 } | 140 } |
| OLD | NEW |