| 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 library test.runner.browser.phantom_js; | 5 library test.runner.browser.phantom_js; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; |
| 8 import 'dart:io'; | 9 import 'dart:io'; |
| 9 | 10 |
| 10 import 'package:path/path.dart' as p; | 11 import 'package:path/path.dart' as p; |
| 12 import 'package:stack_trace/stack_trace.dart'; |
| 11 | 13 |
| 12 import '../../util/exit_codes.dart' as exit_codes; | 14 import '../../util/exit_codes.dart' as exit_codes; |
| 13 import '../../util/io.dart'; | 15 import '../../util/io.dart'; |
| 16 import '../../utils.dart'; |
| 14 import '../application_exception.dart'; | 17 import '../application_exception.dart'; |
| 15 import 'browser.dart'; | 18 import 'browser.dart'; |
| 16 | 19 |
| 17 /// The PhantomJS script that opens the host page. | 20 /// The PhantomJS script that opens the host page. |
| 18 final _script = """ | 21 final _script = """ |
| 19 var system = require('system'); | 22 var system = require('system'); |
| 20 var page = require('webpage').create(); | 23 var page = require('webpage').create(); |
| 21 | 24 |
| 22 // PhantomJS versions older than 2.0.0 don't support the latest WebSocket spec. | 25 // PhantomJS versions older than 2.0.0 don't support the latest WebSocket spec. |
| 23 if (phantom.version.major < 2) phantom.exit(${exit_codes.protocol}); | 26 if (phantom.version.major < 2) phantom.exit(${exit_codes.protocol}); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 _process = process; | 78 _process = process; |
| 76 _onProcessStartedCompleter.complete(); | 79 _onProcessStartedCompleter.complete(); |
| 77 | 80 |
| 78 return _process.exitCode; | 81 return _process.exitCode; |
| 79 }); | 82 }); |
| 80 }).then((exitCode) { | 83 }).then((exitCode) { |
| 81 if (exitCode == exit_codes.protocol) { | 84 if (exitCode == exit_codes.protocol) { |
| 82 throw new ApplicationException( | 85 throw new ApplicationException( |
| 83 "Only PhantomJS version 2.0.0 or greater is supported."); | 86 "Only PhantomJS version 2.0.0 or greater is supported."); |
| 84 } | 87 } |
| 85 if (exitCode != 0) throw "PhantomJS failed with exit code $exitCode."; | 88 |
| 86 }).then(_onExitCompleter.complete) | 89 if (exitCode == 0) return null; |
| 87 .catchError(_onExitCompleter.completeError); | 90 |
| 91 return UTF8.decodeStream(_process.stderr).then((error) { |
| 92 throw new ApplicationException( |
| 93 "PhantomJS failed with exit code $exitCode:\n$error"); |
| 94 }); |
| 95 }).then(_onExitCompleter.complete).catchError((error, stackTrace) { |
| 96 if (stackTrace == null) stackTrace = new Trace.current(); |
| 97 _onExitCompleter.completeError( |
| 98 new ApplicationException( |
| 99 "Failed to start PhantomJS: ${getErrorMessage(error)}."), |
| 100 stackTrace); |
| 101 }); |
| 88 } | 102 } |
| 89 | 103 |
| 90 Future close() { | 104 Future close() { |
| 91 _onProcessStarted.then((_) => _process.kill()); | 105 _onProcessStarted.then((_) => _process.kill()); |
| 92 | 106 |
| 93 // Swallow exceptions. The user should explicitly use [onExit] for these. | 107 // Swallow exceptions. The user should explicitly use [onExit] for these. |
| 94 return onExit.catchError((_) {}); | 108 return onExit.catchError((_) {}); |
| 95 } | 109 } |
| 96 } | 110 } |
| OLD | NEW |