| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * This configuration can be used to rerun selected tests, as well | 6 * This configuration can be used to rerun selected tests, as well |
| 7 * as see diagnostic output from tests. It runs each test in its own | 7 * as see diagnostic output from tests. It runs each test in its own |
| 8 * IFrame, so the configuration consists of two parts - a 'parent' | 8 * IFrame, so the configuration consists of two parts - a 'parent' |
| 9 * config that manages all the tests, and a 'child' config for the | 9 * config that manages all the tests, and a 'child' config for the |
| 10 * IFrame that runs the individual tests. | 10 * IFrame that runs the individual tests. |
| 11 * | 11 * |
| 12 * Note: this unit test configuration will not work with the debugger (the tests | 12 * Note: this unit test configuration will not work with the debugger (the tests |
| 13 * are executed in a separate IFrame). | 13 * are executed in a separate IFrame). |
| 14 */ | 14 */ |
| 15 library unittest_interactive_html_config; | 15 library unittest_interactive_html_config; |
| 16 | 16 |
| 17 // TODO(gram) - add options for: remove IFrame on done/keep | 17 // TODO(gram) - add options for: remove IFrame on done/keep |
| 18 // IFrame for failed tests/keep IFrame for all tests. | 18 // IFrame for failed tests/keep IFrame for all tests. |
| 19 | 19 |
| 20 import 'dart:html'; | 20 import 'dart:html'; |
| 21 import 'dart:async'; | 21 import 'dart:async'; |
| 22 import 'dart:math'; | 22 import 'dart:math'; |
| 23 |
| 24 import 'package:stack_trace/stack_trace.dart'; |
| 25 |
| 23 import 'unittest.dart'; | 26 import 'unittest.dart'; |
| 24 | 27 |
| 25 /** The messages exchanged between parent and child. */ | 28 /** The messages exchanged between parent and child. */ |
| 26 | 29 |
| 27 class _Message { | 30 class _Message { |
| 28 static const START = 'start'; | 31 static const START = 'start'; |
| 29 static const LOG = 'log'; | 32 static const LOG = 'log'; |
| 30 static const STACK = 'stack'; | 33 static const STACK = 'stack'; |
| 31 static const PASS = 'pass'; | 34 static const PASS = 'pass'; |
| 32 static const FAIL = 'fail'; | 35 static const FAIL = 'fail'; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 elapsed = -1; | 143 elapsed = -1; |
| 141 } else { | 144 } else { |
| 142 DateTime end = new DateTime.now(); | 145 DateTime end = new DateTime.now(); |
| 143 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; | 146 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; |
| 144 } | 147 } |
| 145 parentWindow.postMessage( | 148 parentWindow.postMessage( |
| 146 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); | 149 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); |
| 147 } | 150 } |
| 148 | 151 |
| 149 /** | 152 /** |
| 150 * Get the elapsed time for the test, anbd post the test result | 153 * Get the elapsed time for the test, and post the test result back to the |
| 151 * back to the parent window. If the test failed due to an exception | 154 * parent window. If the test failed due to an exception the stack is posted |
| 152 * the stack is posted back too (before the test result). | 155 * back too (before the test result). |
| 153 */ | 156 */ |
| 154 void onTestResult(TestCase testCase) { | 157 void onTestResult(TestCase testCase) { |
| 155 super.onTestResult(testCase); | 158 super.onTestResult(testCase); |
| 156 DateTime end = new DateTime.now(); | 159 DateTime end = new DateTime.now(); |
| 157 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; | 160 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; |
| 158 if (testCase.stackTrace != null) { | 161 if (testCase.stackTrace != null) { |
| 162 var message = json.stringify(testCase.stackTrace.frames.map((frame) { |
| 163 return <String>{ |
| 164 "uri": frame.uri.toString(), |
| 165 "line": frame.line, |
| 166 "column": frame.column, |
| 167 "member": frame.member |
| 168 }; |
| 169 }).toList()); |
| 159 parentWindow.postMessage( | 170 parentWindow.postMessage( |
| 160 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*'); | 171 _Message.text(_Message.STACK, elapsed, message), '*'); |
| 161 } | 172 } |
| 162 parentWindow.postMessage( | 173 parentWindow.postMessage( |
| 163 _Message.text(testCase.result, elapsed, testCase.message), '*'); | 174 _Message.text(testCase.result, elapsed, testCase.message), '*'); |
| 164 } | 175 } |
| 165 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 176 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
| 166 String uncaughtError) { | 177 String uncaughtError) { |
| 167 } | 178 } |
| 168 | 179 |
| 169 void onDone(bool success) { | 180 void onDone(bool success) { |
| 170 _uninstallErrorHandler(); | 181 _uninstallErrorHandler(); |
| 171 } | 182 } |
| 172 } | 183 } |
| 173 | 184 |
| 174 /** | 185 /** |
| 175 * The parent configuration runs in the top-level window; it wraps the tests | 186 * The parent configuration runs in the top-level window; it wraps the tests |
| 176 * in new functions that create child IFrames and run the real tests. | 187 * in new functions that create child IFrames and run the real tests. |
| 177 */ | 188 */ |
| 178 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { | 189 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| 179 Map<int,DateTime> _testStarts; | 190 Map<int,DateTime> _testStarts; |
| 180 | 191 |
| 181 | 192 |
| 182 /** The stack that was posted back from the child, if any. */ | 193 /** The stack that was posted back from the child, if any. */ |
| 183 String _stack; | 194 Trace _stack; |
| 184 | 195 |
| 185 int _testTime; | 196 int _testTime; |
| 186 /** | 197 /** |
| 187 * Whether or not we have already wrapped the TestCase test functions | 198 * Whether or not we have already wrapped the TestCase test functions |
| 188 * in new closures that instead create an IFrame and get it to run the | 199 * in new closures that instead create an IFrame and get it to run the |
| 189 * test. | 200 * test. |
| 190 */ | 201 */ |
| 191 bool _doneWrap = false; | 202 bool _doneWrap = false; |
| 192 | 203 |
| 193 StreamSubscription _messageSubscription; | 204 StreamSubscription _messageSubscription; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 217 }); | 228 }); |
| 218 }; | 229 }; |
| 219 } | 230 } |
| 220 | 231 |
| 221 void _handleMessage(MessageEvent e) { | 232 void _handleMessage(MessageEvent e) { |
| 222 // Get the result, do any logging, then do a pass/fail. | 233 // Get the result, do any logging, then do a pass/fail. |
| 223 var msg = new _Message.fromString(e.data); | 234 var msg = new _Message.fromString(e.data); |
| 224 if (msg.messageType == _Message.LOG) { | 235 if (msg.messageType == _Message.LOG) { |
| 225 logMessage(e.data); | 236 logMessage(e.data); |
| 226 } else if (msg.messageType == _Message.STACK) { | 237 } else if (msg.messageType == _Message.STACK) { |
| 227 _stack = msg.body; | 238 _stack = new Trace(json.parse(msg.body).map((frame) { |
| 239 return new Frame( |
| 240 Uri.parse(frame['uri']), |
| 241 frame['line'], |
| 242 frame['column'], |
| 243 frame['member']); |
| 244 })); |
| 228 } else { | 245 } else { |
| 229 _testTime = msg.elapsed; | 246 _testTime = msg.elapsed; |
| 230 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete')); | 247 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete')); |
| 231 if (msg.messageType == _Message.PASS) { | 248 if (msg.messageType == _Message.PASS) { |
| 232 currentTestCase.pass(); | 249 currentTestCase.pass(); |
| 233 } else if (msg.messageType == _Message.FAIL) { | 250 } else if (msg.messageType == _Message.FAIL) { |
| 234 currentTestCase.fail(msg.body, _stack); | 251 currentTestCase.fail(msg.body, _stack); |
| 235 } else if (msg.messageType == _Message.ERROR) { | 252 } else if (msg.messageType == _Message.ERROR) { |
| 236 currentTestCase.error(msg.body, _stack); | 253 currentTestCase.error(msg.body, _stack); |
| 237 } | 254 } |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 display: block; | 692 display: block; |
| 676 list-style-type: disc; | 693 list-style-type: disc; |
| 677 -webkit-margin-before: 1em; | 694 -webkit-margin-before: 1em; |
| 678 -webkit-margin-after: 1em; | 695 -webkit-margin-after: 1em; |
| 679 -webkit-margin-start: 0px; | 696 -webkit-margin-start: 0px; |
| 680 -webkit-margin-end: 0px; | 697 -webkit-margin-end: 0px; |
| 681 -webkit-padding-start: 40px; | 698 -webkit-padding-start: 40px; |
| 682 } | 699 } |
| 683 | 700 |
| 684 """; | 701 """; |
| OLD | NEW |