Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: lib/src/runner/loader.dart

Issue 1076803003: Change the URL-space exposed by the browser server. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Changelog + pubspec Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 library test.runner.loader; 5 library test.runner.loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 10
(...skipping 14 matching lines...) Expand all
25 import 'vm/isolate_test.dart'; 25 import 'vm/isolate_test.dart';
26 26
27 /// A class for finding test files and loading them into a runnable form. 27 /// A class for finding test files and loading them into a runnable form.
28 class Loader { 28 class Loader {
29 /// All platforms for which tests should be loaded. 29 /// All platforms for which tests should be loaded.
30 final List<TestPlatform> _platforms; 30 final List<TestPlatform> _platforms;
31 31
32 /// Whether to enable colors for Dart compilation. 32 /// Whether to enable colors for Dart compilation.
33 final bool _color; 33 final bool _color;
34 34
35 /// The root directory that will be served for browser tests.
36 final String _root;
37
35 /// The package root to use for loading tests, or `null` to use the automatic 38 /// The package root to use for loading tests, or `null` to use the automatic
36 /// root. 39 /// root.
37 final String _packageRoot; 40 final String _packageRoot;
38 41
39 /// The URL for the `pub serve` instance to use to load tests. 42 /// The URL for the `pub serve` instance to use to load tests.
40 /// 43 ///
41 /// This is `null` if tests should be loaded from the filesystem. 44 /// This is `null` if tests should be loaded from the filesystem.
42 final Uri _pubServeUrl; 45 final Uri _pubServeUrl;
43 46
44 /// All isolates that have been spun up by the loader. 47 /// All isolates that have been spun up by the loader.
45 final _isolates = new Set<Isolate>(); 48 final _isolates = new Set<Isolate>();
46 49
47 /// The server that serves browser test pages. 50 /// The server that serves browser test pages.
48 /// 51 ///
49 /// This is lazily initialized the first time it's accessed. 52 /// This is lazily initialized the first time it's accessed.
50 Future<BrowserServer> get _browserServer { 53 Future<BrowserServer> get _browserServer {
51 if (_browserServerCompleter == null) { 54 if (_browserServerCompleter == null) {
52 _browserServerCompleter = new Completer(); 55 _browserServerCompleter = new Completer();
53 BrowserServer.start( 56 BrowserServer.start(
57 root: _root,
54 packageRoot: _packageRoot, 58 packageRoot: _packageRoot,
55 pubServeUrl: _pubServeUrl, 59 pubServeUrl: _pubServeUrl,
56 color: _color) 60 color: _color)
57 .then(_browserServerCompleter.complete) 61 .then(_browserServerCompleter.complete)
58 .catchError(_browserServerCompleter.completeError); 62 .catchError(_browserServerCompleter.completeError);
59 } 63 }
60 return _browserServerCompleter.future; 64 return _browserServerCompleter.future;
61 } 65 }
62 Completer<BrowserServer> _browserServerCompleter; 66 Completer<BrowserServer> _browserServerCompleter;
63 67
64 /// Creates a new loader. 68 /// Creates a new loader.
65 /// 69 ///
70 /// [root] is the root directory that will be served for browser tests. It
71 /// defaults to the working directory.
72 ///
66 /// If [packageRoot] is passed, it's used as the package root for all loaded 73 /// If [packageRoot] is passed, it's used as the package root for all loaded
67 /// tests. Otherwise, the `packages/` directories next to the test entrypoints 74 /// tests. Otherwise, the `packages/` directories next to the test entrypoints
68 /// will be used. 75 /// will be used.
69 /// 76 ///
70 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve` 77 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve`
71 /// instance at that URL rather than from the filesystem. 78 /// instance at that URL rather than from the filesystem.
72 /// 79 ///
73 /// If [color] is true, console colors will be used when compiling Dart. 80 /// If [color] is true, console colors will be used when compiling Dart.
74 Loader(Iterable<TestPlatform> platforms, {String packageRoot, 81 Loader(Iterable<TestPlatform> platforms, {String root, String packageRoot,
75 Uri pubServeUrl, bool color: false}) 82 Uri pubServeUrl, bool color: false})
76 : _platforms = platforms.toList(), 83 : _platforms = platforms.toList(),
77 _pubServeUrl = pubServeUrl, 84 _pubServeUrl = pubServeUrl,
85 _root = root == null ? p.current : root,
78 _packageRoot = packageRoot, 86 _packageRoot = packageRoot,
79 _color = color; 87 _color = color;
80 88
81 /// Loads all test suites in [dir]. 89 /// Loads all test suites in [dir].
82 /// 90 ///
83 /// This will load tests from files that end in "_test.dart". Any tests that 91 /// This will load tests from files that end in "_test.dart". Any tests that
84 /// fail to load will be emitted as [LoadException]s. 92 /// fail to load will be emitted as [LoadException]s.
85 Stream<Suite> loadDir(String dir) { 93 Stream<Suite> loadDir(String dir) {
86 return mergeStreams(new Directory(dir).listSync(recursive: true) 94 return mergeStreams(new Directory(dir).listSync(recursive: true)
87 .map((entry) { 95 .map((entry) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 browserServer.loadSuite(path, platform)); 155 browserServer.loadSuite(path, platform));
148 156
149 /// Load the test suite at [path] in VM isolate. 157 /// Load the test suite at [path] in VM isolate.
150 Future<Suite> _loadVmFile(String path) { 158 Future<Suite> _loadVmFile(String path) {
151 var packageRoot = packageRootFor(path, _packageRoot); 159 var packageRoot = packageRootFor(path, _packageRoot);
152 var receivePort = new ReceivePort(); 160 var receivePort = new ReceivePort();
153 161
154 return new Future.sync(() { 162 return new Future.sync(() {
155 if (_pubServeUrl != null) { 163 if (_pubServeUrl != null) {
156 var url = _pubServeUrl.resolve( 164 var url = _pubServeUrl.resolve(
157 p.withoutExtension(p.relative(path, from: 'test')) + 165 p.relative(path, from: 'test') + '.vm_test.dart');
158 '.vm_test.dart');
159 return Isolate.spawnUri(url, [], {'reply': receivePort.sendPort}) 166 return Isolate.spawnUri(url, [], {'reply': receivePort.sendPort})
160 .then((isolate) => new IsolateWrapper(isolate, () {})) 167 .then((isolate) => new IsolateWrapper(isolate, () {}))
161 .catchError((error, stackTrace) { 168 .catchError((error, stackTrace) {
162 if (error is! IsolateSpawnException) throw error; 169 if (error is! IsolateSpawnException) throw error;
163 170
164 if (error.message.contains("OS Error: Connection refused")) { 171 if (error.message.contains("OS Error: Connection refused")) {
165 throw new LoadException(path, 172 throw new LoadException(path,
166 "Error getting $url: Connection refused\n" 173 "Error getting $url: Connection refused\n"
167 'Make sure "pub serve" is running.'); 174 'Make sure "pub serve" is running.');
168 } else if (error.message.contains("404 Not Found")) { 175 } else if (error.message.contains("404 Not Found")) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 Future close() { 222 Future close() {
216 for (var isolate in _isolates) { 223 for (var isolate in _isolates) {
217 isolate.kill(); 224 isolate.kill();
218 } 225 }
219 _isolates.clear(); 226 _isolates.clear();
220 227
221 if (_browserServerCompleter == null) return new Future.value(); 228 if (_browserServerCompleter == null) return new Future.value();
222 return _browserServer.then((browserServer) => browserServer.close()); 229 return _browserServer.then((browserServer) => browserServer.close());
223 } 230 }
224 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698