OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:async/async.dart'; | 9 import 'package:async/async.dart'; |
10 import 'package:http_multi_server/http_multi_server.dart'; | 10 import 'package:http_multi_server/http_multi_server.dart'; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 _compilers = new CompilerPool(config) { | 117 _compilers = new CompilerPool(config) { |
118 var cascade = new shelf.Cascade() | 118 var cascade = new shelf.Cascade() |
119 .add(_webSocketHandler.handler); | 119 .add(_webSocketHandler.handler); |
120 | 120 |
121 if (_config.pubServeUrl == null) { | 121 if (_config.pubServeUrl == null) { |
122 cascade = cascade | 122 cascade = cascade |
123 .add(_createPackagesHandler()) | 123 .add(_createPackagesHandler()) |
124 .add(_jsHandler.handler) | 124 .add(_jsHandler.handler) |
125 .add(createStaticHandler(_root)) | 125 .add(createStaticHandler(_root)) |
126 .add(_wrapperHandler); | 126 .add(_wrapperHandler); |
| 127 |
| 128 if (config.precompiledPath != null) { |
| 129 cascade = cascade.add(createStaticHandler(config.precompiledPath)); |
| 130 } |
127 } | 131 } |
128 | 132 |
129 var pipeline = new shelf.Pipeline() | 133 var pipeline = new shelf.Pipeline() |
130 .addMiddleware(nestingMiddleware(_secret)) | 134 .addMiddleware(nestingMiddleware(_secret)) |
131 .addHandler(cascade.handler); | 135 .addHandler(cascade.handler); |
132 | 136 |
133 _server.mount(pipeline); | 137 _server.mount(pipeline); |
134 } | 138 } |
135 | 139 |
136 /// Returns a handler that serves the contents of the "packages/" directory | 140 /// Returns a handler that serves the contents of the "packages/" directory |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 dartUrl = _config.pubServeUrl.resolve( | 239 dartUrl = _config.pubServeUrl.resolve( |
236 "$suitePrefix.html.polymer.bootstrap.dart.browser_test.dart"); | 240 "$suitePrefix.html.polymer.bootstrap.dart.browser_test.dart"); |
237 } else { | 241 } else { |
238 dartUrl = _config.pubServeUrl.resolve( | 242 dartUrl = _config.pubServeUrl.resolve( |
239 '$suitePrefix.dart.browser_test.dart'); | 243 '$suitePrefix.dart.browser_test.dart'); |
240 } | 244 } |
241 | 245 |
242 await _pubServeSuite(path, dartUrl, browser); | 246 await _pubServeSuite(path, dartUrl, browser); |
243 suiteUrl = _config.pubServeUrl.resolveUri(p.toUri('$suitePrefix.html')); | 247 suiteUrl = _config.pubServeUrl.resolveUri(p.toUri('$suitePrefix.html')); |
244 } else { | 248 } else { |
245 if (browser.isJS) await _compileSuite(path); | 249 if (browser.isJS && !_precompiled(path)) await _compileSuite(path); |
246 if (_closed) return null; | 250 if (_closed) return null; |
247 suiteUrl = url.resolveUri(p.toUri( | 251 suiteUrl = url.resolveUri(p.toUri( |
248 p.withoutExtension(p.relative(path, from: _root)) + ".html")); | 252 p.withoutExtension(p.relative(path, from: _root)) + ".html")); |
249 } | 253 } |
250 | 254 |
251 if (_closed) return null; | 255 if (_closed) return null; |
252 | 256 |
253 // TODO(nweiz): Don't start the browser until all the suites are compiled. | 257 // TODO(nweiz): Don't start the browser until all the suites are compiled. |
254 var browserManager = await _browserManagerFor(browser); | 258 var browserManager = await _browserManagerFor(browser); |
255 if (_closed) return null; | 259 if (_closed) return null; |
256 | 260 |
257 var suite = await browserManager.load(path, suiteUrl, metadata, | 261 var suite = await browserManager.load(path, suiteUrl, metadata, |
258 mapper: browser.isJS ? _mappers[path] : null); | 262 mapper: browser.isJS ? _mappers[path] : null); |
259 if (_closed) return null; | 263 if (_closed) return null; |
260 return suite; | 264 return suite; |
261 } | 265 } |
262 | 266 |
| 267 /// Returns whether the test at [path] has precompiled JS available underneath |
| 268 /// `_config.precompiledPath`. |
| 269 bool _precompiled(String path) { |
| 270 if (_config.precompiledPath == null) return false; |
| 271 var jsPath = |
| 272 p.join(_config.precompiledPath, p.relative(path, from: _root)) + |
| 273 ".browser_test.dart.js"; |
| 274 print("does $jsPath exist? ${new File(jsPath).existsSync()}"); |
| 275 return new File(jsPath).existsSync(); |
| 276 } |
| 277 |
263 StreamChannel loadChannel(String path, TestPlatform platform) => | 278 StreamChannel loadChannel(String path, TestPlatform platform) => |
264 throw new UnimplementedError(); | 279 throw new UnimplementedError(); |
265 | 280 |
266 /// Loads a test suite at [path] from the `pub serve` URL [dartUrl]. | 281 /// Loads a test suite at [path] from the `pub serve` URL [dartUrl]. |
267 /// | 282 /// |
268 /// This ensures that only one suite is loaded at a time, and that any errors | 283 /// This ensures that only one suite is loaded at a time, and that any errors |
269 /// are exposed as [LoadException]s. | 284 /// are exposed as [LoadException]s. |
270 Future _pubServeSuite(String path, Uri dartUrl, TestPlatform browser) { | 285 Future _pubServeSuite(String path, Uri dartUrl, TestPlatform browser) { |
271 return _pubServePool.withResource(() async { | 286 return _pubServePool.withResource(() async { |
272 var timer = new Timer(new Duration(seconds: 1), () { | 287 var timer = new Timer(new Duration(seconds: 1), () { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 await Future.wait(futures); | 438 await Future.wait(futures); |
424 | 439 |
425 if (_config.pubServeUrl == null) { | 440 if (_config.pubServeUrl == null) { |
426 new Directory(_compiledDir).deleteSync(recursive: true); | 441 new Directory(_compiledDir).deleteSync(recursive: true); |
427 } else { | 442 } else { |
428 _http.close(); | 443 _http.close(); |
429 } | 444 } |
430 }); | 445 }); |
431 final _closeMemo = new AsyncMemoizer(); | 446 final _closeMemo = new AsyncMemoizer(); |
432 } | 447 } |
OLD | NEW |