| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 }); | 66 }); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 """); | 69 """); |
| 70 | 70 |
| 71 var pubGetResult = runPub(['get'], workingDirectory: _sandbox); | 71 var pubGetResult = runPub(['get'], workingDirectory: _sandbox); |
| 72 expect(pubGetResult.exitCode, equals(0)); | 72 expect(pubGetResult.exitCode, equals(0)); |
| 73 }); | 73 }); |
| 74 | 74 |
| 75 tearDown(() { | 75 tearDown(() { |
| 76 // On Windows, there's no way to shut down the actual "pub serve" process. |
| 77 // Killing the process we start will just kill the batch file wrapper (issue |
| 78 // 23304), not the underlying "pub serve" process. Since that process has |
| 79 // locks on files in the sandbox, we can't delete the sandbox on Windows |
| 80 // without errors. |
| 81 if (Platform.isWindows) return; |
| 82 |
| 76 new Directory(_sandbox).deleteSync(recursive: true); | 83 new Directory(_sandbox).deleteSync(recursive: true); |
| 77 }); | 84 }); |
| 78 | 85 |
| 79 group("with transformed tests", () { | 86 group("with transformed tests", () { |
| 80 test("runs those tests in the VM", () { | 87 test("runs those tests in the VM", () { |
| 81 return startPub(['serve', '--port', '0'], workingDirectory: _sandbox) | 88 return startPub(['serve', '--port', '0'], workingDirectory: _sandbox) |
| 82 .then((process) { | 89 .then((process) { |
| 83 return _lines.bind(process.stdout) | 90 return _lines.bind(process.stdout) |
| 84 .firstWhere(_servingRegExp.hasMatch) | 91 .firstWhere(_servingRegExp.hasMatch) |
| 85 .then((line) { | 92 .then((line) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return _lines.bind(process.stdout) | 158 return _lines.bind(process.stdout) |
| 152 .firstWhere(_servingRegExp.hasMatch) | 159 .firstWhere(_servingRegExp.hasMatch) |
| 153 .then((line) { | 160 .then((line) { |
| 154 var match = _servingRegExp.firstMatch(line); | 161 var match = _servingRegExp.firstMatch(line); |
| 155 | 162 |
| 156 try { | 163 try { |
| 157 var result = runTest(['--pub-serve=${match[1]}'], | 164 var result = runTest(['--pub-serve=${match[1]}'], |
| 158 workingDirectory: _sandbox); | 165 workingDirectory: _sandbox); |
| 159 expect(result.stdout, allOf([ | 166 expect(result.stdout, allOf([ |
| 160 contains('-1: load error'), | 167 contains('-1: load error'), |
| 161 contains('Failed to load "test/my_test.dart":'), | 168 contains('Failed to load "${p.join("test", "my_test.dart")}":'), |
| 162 contains('404 Not Found'), | 169 contains('404 Not Found'), |
| 163 contains('Make sure "pub serve" is serving the test/ directory.') | 170 contains('Make sure "pub serve" is serving the test/ directory.') |
| 164 ])); | 171 ])); |
| 165 expect(result.exitCode, equals(1)); | 172 expect(result.exitCode, equals(1)); |
| 166 } finally { | 173 } finally { |
| 167 process.kill(); | 174 process.kill(); |
| 168 } | 175 } |
| 169 }); | 176 }); |
| 170 }); | 177 }); |
| 171 }); | 178 }); |
| 172 | 179 |
| 173 test("gracefully handles pub serve running on the wrong directory for " | 180 test("gracefully handles pub serve running on the wrong directory for " |
| 174 "browser tests", () { | 181 "browser tests", () { |
| 175 new Directory(p.join(_sandbox, "web")).createSync(); | 182 new Directory(p.join(_sandbox, "web")).createSync(); |
| 176 | 183 |
| 177 return startPub(['serve', '--port', '0', 'web'], | 184 return startPub(['serve', '--port', '0', 'web'], |
| 178 workingDirectory: _sandbox) | 185 workingDirectory: _sandbox) |
| 179 .then((process) { | 186 .then((process) { |
| 180 return _lines.bind(process.stdout) | 187 return _lines.bind(process.stdout) |
| 181 .firstWhere(_servingRegExp.hasMatch) | 188 .firstWhere(_servingRegExp.hasMatch) |
| 182 .then((line) { | 189 .then((line) { |
| 183 var match = _servingRegExp.firstMatch(line); | 190 var match = _servingRegExp.firstMatch(line); |
| 184 | 191 |
| 185 try { | 192 try { |
| 186 var result = runTest( | 193 var result = runTest( |
| 187 ['--pub-serve=${match[1]}', '-p', 'chrome'], | 194 ['--pub-serve=${match[1]}', '-p', 'chrome'], |
| 188 workingDirectory: _sandbox); | 195 workingDirectory: _sandbox); |
| 189 expect(result.stdout, allOf([ | 196 expect(result.stdout, allOf([ |
| 190 contains('-1: load error'), | 197 contains('-1: load error'), |
| 191 contains('Failed to load "test/my_test.dart":'), | 198 contains('Failed to load "${p.join("test", "my_test.dart")}":'), |
| 192 contains('404 Not Found'), | 199 contains('404 Not Found'), |
| 193 contains('Make sure "pub serve" is serving the test/ directory.') | 200 contains('Make sure "pub serve" is serving the test/ directory.') |
| 194 ])); | 201 ])); |
| 195 expect(result.exitCode, equals(1)); | 202 expect(result.exitCode, equals(1)); |
| 196 } finally { | 203 } finally { |
| 197 process.kill(); | 204 process.kill(); |
| 198 } | 205 } |
| 199 }); | 206 }); |
| 200 }); | 207 }); |
| 201 }); | 208 }); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 }); | 313 }); |
| 307 }); | 314 }); |
| 308 }); | 315 }); |
| 309 | 316 |
| 310 test("gracefully handles pub serve not running for VM tests", () { | 317 test("gracefully handles pub serve not running for VM tests", () { |
| 311 var result = runTest(['--pub-serve=54321'], | 318 var result = runTest(['--pub-serve=54321'], |
| 312 workingDirectory: _sandbox); | 319 workingDirectory: _sandbox); |
| 313 expect(result.stdout, allOf([ | 320 expect(result.stdout, allOf([ |
| 314 contains('-1: load error'), | 321 contains('-1: load error'), |
| 315 contains(''' | 322 contains(''' |
| 316 Failed to load "test/my_test.dart": | 323 Failed to load "${p.join("test", "my_test.dart")}": |
| 317 Error getting http://localhost:54321/my_test.dart.vm_test.dart: Connection ref
used | 324 Error getting http://localhost:54321/my_test.dart.vm_test.dart: Connection ref
used |
| 318 Make sure "pub serve" is running.''') | 325 Make sure "pub serve" is running.''') |
| 319 ])); | 326 ])); |
| 320 expect(result.exitCode, equals(1)); | 327 expect(result.exitCode, equals(1)); |
| 321 }); | 328 }); |
| 322 | 329 |
| 323 test("gracefully handles pub serve not running for browser tests", () { | 330 test("gracefully handles pub serve not running for browser tests", () { |
| 324 var result = runTest(['--pub-serve=54321', '-p', 'chrome'], | 331 var result = runTest(['--pub-serve=54321', '-p', 'chrome'], |
| 325 workingDirectory: _sandbox); | 332 workingDirectory: _sandbox); |
| 333 var message = Platform.isWindows |
| 334 ? 'The remote computer refused the network connection.' |
| 335 : 'Connection refused (errno '; |
| 336 |
| 326 expect(result.stdout, allOf([ | 337 expect(result.stdout, allOf([ |
| 327 contains('-1: load error'), | 338 contains('-1: load error'), |
| 328 contains('Failed to load "test/my_test.dart":'), | 339 contains('Failed to load "${p.join("test", "my_test.dart")}":'), |
| 329 contains('Error getting http://localhost:54321/my_test.dart.browser_test' | 340 contains('Error getting http://localhost:54321/my_test.dart.browser_test' |
| 330 '.dart.js: Connection refused (errno '), | 341 '.dart.js: $message'), |
| 331 contains('Make sure "pub serve" is running.') | 342 contains('Make sure "pub serve" is running.') |
| 332 ])); | 343 ])); |
| 333 expect(result.exitCode, equals(1)); | 344 expect(result.exitCode, equals(1)); |
| 334 }); | 345 }); |
| 335 | 346 |
| 336 test("gracefully handles a test file not being in test/", () { | 347 test("gracefully handles a test file not being in test/", () { |
| 337 new File(p.join(_sandbox, 'test/my_test.dart')) | 348 new File(p.join(_sandbox, 'test/my_test.dart')) |
| 338 .copySync(p.join(_sandbox, 'my_test.dart')); | 349 .copySync(p.join(_sandbox, 'my_test.dart')); |
| 339 | 350 |
| 340 var result = runTest(['--pub-serve=54321', 'my_test.dart'], | 351 var result = runTest(['--pub-serve=54321', 'my_test.dart'], |
| 341 workingDirectory: _sandbox); | 352 workingDirectory: _sandbox); |
| 342 expect(result.stdout, allOf([ | 353 expect(result.stdout, allOf([ |
| 343 contains('-1: load error'), | 354 contains('-1: load error'), |
| 344 contains( | 355 contains( |
| 345 'Failed to load "my_test.dart": When using "pub serve", all test ' | 356 'Failed to load "my_test.dart": When using "pub serve", all test ' |
| 346 'files must be in test/.\n') | 357 'files must be in test/.\n') |
| 347 ])); | 358 ])); |
| 348 expect(result.exitCode, equals(1)); | 359 expect(result.exitCode, equals(1)); |
| 349 }); | 360 }); |
| 350 } | 361 } |
| OLD | NEW |