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:convert'; | 7 import 'dart:convert'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 group("with transformed tests", () { | 79 group("with transformed tests", () { |
80 test("runs those tests in the VM", () { | 80 test("runs those tests in the VM", () { |
81 return startPub(['serve', '--port', '0'], workingDirectory: _sandbox) | 81 return startPub(['serve', '--port', '0'], workingDirectory: _sandbox) |
82 .then((process) { | 82 .then((process) { |
83 return _lines.bind(process.stdout) | 83 return _lines.bind(process.stdout) |
84 .firstWhere(_servingRegExp.hasMatch) | 84 .firstWhere(_servingRegExp.hasMatch) |
85 .then((line) { | 85 .then((line) { |
86 var match = _servingRegExp.firstMatch(line); | 86 var match = _servingRegExp.firstMatch(line); |
87 | 87 |
88 try { | 88 try { |
89 var result = runUnittest(['--pub-serve=${match[1]}'], | 89 var result = runTest(['--pub-serve=${match[1]}'], |
90 workingDirectory: _sandbox); | 90 workingDirectory: _sandbox); |
91 expect(result.exitCode, equals(0)); | 91 expect(result.exitCode, equals(0)); |
92 expect(result.stdout, contains('+1: All tests passed!')); | 92 expect(result.stdout, contains('+1: All tests passed!')); |
93 } finally { | 93 } finally { |
94 process.kill(); | 94 process.kill(); |
95 } | 95 } |
96 }); | 96 }); |
97 }); | 97 }); |
98 }); | 98 }); |
99 | 99 |
100 test("runs those tests on Chrome", () { | 100 test("runs those tests on Chrome", () { |
101 return startPub(['serve', '--port', '0'], | 101 return startPub(['serve', '--port', '0'], |
102 workingDirectory: _sandbox) | 102 workingDirectory: _sandbox) |
103 .then((process) { | 103 .then((process) { |
104 return _lines.bind(process.stdout) | 104 return _lines.bind(process.stdout) |
105 .firstWhere(_servingRegExp.hasMatch) | 105 .firstWhere(_servingRegExp.hasMatch) |
106 .then((line) { | 106 .then((line) { |
107 var match = _servingRegExp.firstMatch(line); | 107 var match = _servingRegExp.firstMatch(line); |
108 | 108 |
109 try { | 109 try { |
110 var result = runUnittest( | 110 var result = runTest( |
111 ['--pub-serve=${match[1]}', '-p', 'chrome'], | 111 ['--pub-serve=${match[1]}', '-p', 'chrome'], |
112 workingDirectory: _sandbox); | 112 workingDirectory: _sandbox); |
113 expect(result.exitCode, equals(0)); | 113 expect(result.exitCode, equals(0)); |
114 expect(result.stdout, contains('+1: All tests passed!')); | 114 expect(result.stdout, contains('+1: All tests passed!')); |
115 } finally { | 115 } finally { |
116 process.kill(); | 116 process.kill(); |
117 } | 117 } |
118 }); | 118 }); |
119 }); | 119 }); |
120 }); | 120 }); |
121 | 121 |
122 test("runs those tests on content shell", () { | 122 test("runs those tests on content shell", () { |
123 return startPub(['serve', '--port', '0'], | 123 return startPub(['serve', '--port', '0'], |
124 workingDirectory: _sandbox) | 124 workingDirectory: _sandbox) |
125 .then((process) { | 125 .then((process) { |
126 return _lines.bind(process.stdout) | 126 return _lines.bind(process.stdout) |
127 .firstWhere(_servingRegExp.hasMatch) | 127 .firstWhere(_servingRegExp.hasMatch) |
128 .then((line) { | 128 .then((line) { |
129 var match = _servingRegExp.firstMatch(line); | 129 var match = _servingRegExp.firstMatch(line); |
130 | 130 |
131 try { | 131 try { |
132 var result = runUnittest( | 132 var result = runTest( |
133 ['--pub-serve=${match[1]}', '-p', 'content-shell'], | 133 ['--pub-serve=${match[1]}', '-p', 'content-shell'], |
134 workingDirectory: _sandbox); | 134 workingDirectory: _sandbox); |
135 expect(result.exitCode, equals(0)); | 135 expect(result.exitCode, equals(0)); |
136 expect(result.stdout, contains('+1: All tests passed!')); | 136 expect(result.stdout, contains('+1: All tests passed!')); |
137 } finally { | 137 } finally { |
138 process.kill(); | 138 process.kill(); |
139 } | 139 } |
140 }); | 140 }); |
141 }); | 141 }); |
142 }); | 142 }); |
143 | 143 |
144 test("gracefully handles pub serve running on the wrong directory for " | 144 test("gracefully handles pub serve running on the wrong directory for " |
145 "VM tests", () { | 145 "VM tests", () { |
146 new Directory(p.join(_sandbox, "web")).createSync(); | 146 new Directory(p.join(_sandbox, "web")).createSync(); |
147 | 147 |
148 return startPub(['serve', '--port', '0', 'web'], | 148 return startPub(['serve', '--port', '0', 'web'], |
149 workingDirectory: _sandbox) | 149 workingDirectory: _sandbox) |
150 .then((process) { | 150 .then((process) { |
151 return _lines.bind(process.stdout) | 151 return _lines.bind(process.stdout) |
152 .firstWhere(_servingRegExp.hasMatch) | 152 .firstWhere(_servingRegExp.hasMatch) |
153 .then((line) { | 153 .then((line) { |
154 var match = _servingRegExp.firstMatch(line); | 154 var match = _servingRegExp.firstMatch(line); |
155 | 155 |
156 try { | 156 try { |
157 var result = runUnittest(['--pub-serve=${match[1]}'], | 157 var result = runTest(['--pub-serve=${match[1]}'], |
158 workingDirectory: _sandbox); | 158 workingDirectory: _sandbox); |
159 expect(result.stdout, allOf([ | 159 expect(result.stdout, allOf([ |
160 contains('-1: load error'), | 160 contains('-1: load error'), |
161 contains('Failed to load "test/my_test.dart":'), | 161 contains('Failed to load "test/my_test.dart":'), |
162 contains('404 Not Found'), | 162 contains('404 Not Found'), |
163 contains('Make sure "pub serve" is serving the test/ directory.') | 163 contains('Make sure "pub serve" is serving the test/ directory.') |
164 ])); | 164 ])); |
165 expect(result.exitCode, equals(1)); | 165 expect(result.exitCode, equals(1)); |
166 } finally { | 166 } finally { |
167 process.kill(); | 167 process.kill(); |
168 } | 168 } |
169 }); | 169 }); |
170 }); | 170 }); |
171 }); | 171 }); |
172 | 172 |
173 test("gracefully handles pub serve running on the wrong directory for " | 173 test("gracefully handles pub serve running on the wrong directory for " |
174 "browser tests", () { | 174 "browser tests", () { |
175 new Directory(p.join(_sandbox, "web")).createSync(); | 175 new Directory(p.join(_sandbox, "web")).createSync(); |
176 | 176 |
177 return startPub(['serve', '--port', '0', 'web'], | 177 return startPub(['serve', '--port', '0', 'web'], |
178 workingDirectory: _sandbox) | 178 workingDirectory: _sandbox) |
179 .then((process) { | 179 .then((process) { |
180 return _lines.bind(process.stdout) | 180 return _lines.bind(process.stdout) |
181 .firstWhere(_servingRegExp.hasMatch) | 181 .firstWhere(_servingRegExp.hasMatch) |
182 .then((line) { | 182 .then((line) { |
183 var match = _servingRegExp.firstMatch(line); | 183 var match = _servingRegExp.firstMatch(line); |
184 | 184 |
185 try { | 185 try { |
186 var result = runUnittest( | 186 var result = runTest( |
187 ['--pub-serve=${match[1]}', '-p', 'chrome'], | 187 ['--pub-serve=${match[1]}', '-p', 'chrome'], |
188 workingDirectory: _sandbox); | 188 workingDirectory: _sandbox); |
189 expect(result.stdout, allOf([ | 189 expect(result.stdout, allOf([ |
190 contains('-1: load error'), | 190 contains('-1: load error'), |
191 contains('Failed to load "test/my_test.dart":'), | 191 contains('Failed to load "test/my_test.dart":'), |
192 contains('404 Not Found'), | 192 contains('404 Not Found'), |
193 contains('Make sure "pub serve" is serving the test/ directory.') | 193 contains('Make sure "pub serve" is serving the test/ directory.') |
194 ])); | 194 ])); |
195 expect(result.exitCode, equals(1)); | 195 expect(result.exitCode, equals(1)); |
196 } finally { | 196 } finally { |
(...skipping 13 matching lines...) Expand all Loading... |
210 | 210 |
211 return startPub(['serve', '--port', '0'], | 211 return startPub(['serve', '--port', '0'], |
212 workingDirectory: _sandbox) | 212 workingDirectory: _sandbox) |
213 .then((process) { | 213 .then((process) { |
214 return _lines.bind(process.stdout) | 214 return _lines.bind(process.stdout) |
215 .firstWhere(_servingRegExp.hasMatch) | 215 .firstWhere(_servingRegExp.hasMatch) |
216 .then((line) { | 216 .then((line) { |
217 var match = _servingRegExp.firstMatch(line); | 217 var match = _servingRegExp.firstMatch(line); |
218 | 218 |
219 try { | 219 try { |
220 var result = runUnittest(['--pub-serve=${match[1]}'], | 220 var result = runTest(['--pub-serve=${match[1]}'], |
221 workingDirectory: _sandbox); | 221 workingDirectory: _sandbox); |
222 expect(result.exitCode, equals(exit_codes.data)); | 222 expect(result.exitCode, equals(exit_codes.data)); |
223 expect(result.stderr, equals(''' | 223 expect(result.stderr, equals(''' |
224 When using --pub-serve, you must include the "test/pub_serve" transformer in | 224 When using --pub-serve, you must include the "test/pub_serve" transformer in |
225 your pubspec: | 225 your pubspec: |
226 | 226 |
227 transformers: | 227 transformers: |
228 - test/pub_serve: | 228 - test/pub_serve: |
229 \$include: test/**_test.dart | 229 \$include: test/**_test.dart |
230 ''')); | 230 ''')); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 test("on Chrome", () { | 265 test("on Chrome", () { |
266 return startPub(['serve', '--port', '0'], | 266 return startPub(['serve', '--port', '0'], |
267 workingDirectory: _sandbox) | 267 workingDirectory: _sandbox) |
268 .then((process) { | 268 .then((process) { |
269 return _lines.bind(process.stdout) | 269 return _lines.bind(process.stdout) |
270 .firstWhere(_servingRegExp.hasMatch) | 270 .firstWhere(_servingRegExp.hasMatch) |
271 .then((line) { | 271 .then((line) { |
272 var match = _servingRegExp.firstMatch(line); | 272 var match = _servingRegExp.firstMatch(line); |
273 | 273 |
274 try { | 274 try { |
275 var result = runUnittest( | 275 var result = runTest( |
276 ['--pub-serve=${match[1]}', '-p', 'chrome'], | 276 ['--pub-serve=${match[1]}', '-p', 'chrome'], |
277 workingDirectory: _sandbox); | 277 workingDirectory: _sandbox); |
278 expect(result.exitCode, equals(0)); | 278 expect(result.exitCode, equals(0)); |
279 expect(result.stdout, contains('+1: All tests passed!')); | 279 expect(result.stdout, contains('+1: All tests passed!')); |
280 } finally { | 280 } finally { |
281 process.kill(); | 281 process.kill(); |
282 } | 282 } |
283 }); | 283 }); |
284 }); | 284 }); |
285 }); | 285 }); |
286 | 286 |
287 test("on content shell", () { | 287 test("on content shell", () { |
288 return startPub(['serve', '--port', '0'], | 288 return startPub(['serve', '--port', '0'], |
289 workingDirectory: _sandbox) | 289 workingDirectory: _sandbox) |
290 .then((process) { | 290 .then((process) { |
291 return _lines.bind(process.stdout) | 291 return _lines.bind(process.stdout) |
292 .firstWhere(_servingRegExp.hasMatch) | 292 .firstWhere(_servingRegExp.hasMatch) |
293 .then((line) { | 293 .then((line) { |
294 var match = _servingRegExp.firstMatch(line); | 294 var match = _servingRegExp.firstMatch(line); |
295 | 295 |
296 try { | 296 try { |
297 var result = runUnittest( | 297 var result = runTest( |
298 ['--pub-serve=${match[1]}', '-p', 'content-shell'], | 298 ['--pub-serve=${match[1]}', '-p', 'content-shell'], |
299 workingDirectory: _sandbox); | 299 workingDirectory: _sandbox); |
300 expect(result.exitCode, equals(0)); | 300 expect(result.exitCode, equals(0)); |
301 expect(result.stdout, contains('+1: All tests passed!')); | 301 expect(result.stdout, contains('+1: All tests passed!')); |
302 } finally { | 302 } finally { |
303 process.kill(); | 303 process.kill(); |
304 } | 304 } |
305 }); | 305 }); |
306 }); | 306 }); |
307 }); | 307 }); |
308 }); | 308 }); |
309 | 309 |
310 test("gracefully handles pub serve not running for VM tests", () { | 310 test("gracefully handles pub serve not running for VM tests", () { |
311 var result = runUnittest(['--pub-serve=54321'], | 311 var result = runTest(['--pub-serve=54321'], |
312 workingDirectory: _sandbox); | 312 workingDirectory: _sandbox); |
313 expect(result.stdout, allOf([ | 313 expect(result.stdout, allOf([ |
314 contains('-1: load error'), | 314 contains('-1: load error'), |
315 contains(''' | 315 contains(''' |
316 Failed to load "test/my_test.dart": | 316 Failed to load "test/my_test.dart": |
317 Error getting http://localhost:54321/my_test.dart.vm_test.dart: Connection ref
used | 317 Error getting http://localhost:54321/my_test.dart.vm_test.dart: Connection ref
used |
318 Make sure "pub serve" is running.''') | 318 Make sure "pub serve" is running.''') |
319 ])); | 319 ])); |
320 expect(result.exitCode, equals(1)); | 320 expect(result.exitCode, equals(1)); |
321 }); | 321 }); |
322 | 322 |
323 test("gracefully handles pub serve not running for browser tests", () { | 323 test("gracefully handles pub serve not running for browser tests", () { |
324 var result = runUnittest(['--pub-serve=54321', '-p', 'chrome'], | 324 var result = runTest(['--pub-serve=54321', '-p', 'chrome'], |
325 workingDirectory: _sandbox); | 325 workingDirectory: _sandbox); |
326 expect(result.stdout, allOf([ | 326 expect(result.stdout, allOf([ |
327 contains('-1: load error'), | 327 contains('-1: load error'), |
328 contains('Failed to load "test/my_test.dart":'), | 328 contains('Failed to load "test/my_test.dart":'), |
329 contains('Error getting http://localhost:54321/my_test.dart.browser_test' | 329 contains('Error getting http://localhost:54321/my_test.dart.browser_test' |
330 '.dart.js: Connection refused (errno '), | 330 '.dart.js: Connection refused (errno '), |
331 contains('Make sure "pub serve" is running.') | 331 contains('Make sure "pub serve" is running.') |
332 ])); | 332 ])); |
333 expect(result.exitCode, equals(1)); | 333 expect(result.exitCode, equals(1)); |
334 }); | 334 }); |
335 | 335 |
336 test("gracefully handles a test file not being in test/", () { | 336 test("gracefully handles a test file not being in test/", () { |
337 new File(p.join(_sandbox, 'test/my_test.dart')) | 337 new File(p.join(_sandbox, 'test/my_test.dart')) |
338 .copySync(p.join(_sandbox, 'my_test.dart')); | 338 .copySync(p.join(_sandbox, 'my_test.dart')); |
339 | 339 |
340 var result = runUnittest(['--pub-serve=54321', 'my_test.dart'], | 340 var result = runTest(['--pub-serve=54321', 'my_test.dart'], |
341 workingDirectory: _sandbox); | 341 workingDirectory: _sandbox); |
342 expect(result.stdout, allOf([ | 342 expect(result.stdout, allOf([ |
343 contains('-1: load error'), | 343 contains('-1: load error'), |
344 contains( | 344 contains( |
345 'Failed to load "my_test.dart": When using "pub serve", all test ' | 345 'Failed to load "my_test.dart": When using "pub serve", all test ' |
346 'files must be in test/.\n') | 346 'files must be in test/.\n') |
347 ])); | 347 ])); |
348 expect(result.exitCode, equals(1)); | 348 expect(result.exitCode, equals(1)); |
349 }); | 349 }); |
350 } | 350 } |
OLD | NEW |