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 class _Message { | 29 class _Message { |
27 static const START = 'start'; | 30 static const START = 'start'; |
28 static const LOG = 'log'; | 31 static const LOG = 'log'; |
29 static const STACK = 'stack'; | 32 static const STACK = 'stack'; |
30 static const PASS = 'pass'; | 33 static const PASS = 'pass'; |
31 static const FAIL = 'fail'; | 34 static const FAIL = 'fail'; |
32 static const ERROR = 'error'; | 35 static const ERROR = 'error'; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 elapsed = -1; | 148 elapsed = -1; |
146 } else { | 149 } else { |
147 DateTime end = new DateTime.now(); | 150 DateTime end = new DateTime.now(); |
148 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; | 151 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; |
149 } | 152 } |
150 _parentWindow.postMessage( | 153 _parentWindow.postMessage( |
151 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); | 154 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); |
152 } | 155 } |
153 | 156 |
154 /** | 157 /** |
155 * Get the elapsed time for the test, anbd post the test result | 158 * Get the elapsed time for the test, and post the test result back to the |
156 * back to the parent window. If the test failed due to an exception | 159 * parent window. If the test failed due to an exception the stack is posted |
157 * the stack is posted back too (before the test result). | 160 * back too (before the test result). |
158 */ | 161 */ |
159 void onTestResult(TestCase testCase) { | 162 void onTestResult(TestCase testCase) { |
160 super.onTestResult(testCase); | 163 super.onTestResult(testCase); |
161 DateTime end = new DateTime.now(); | 164 DateTime end = new DateTime.now(); |
162 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; | 165 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; |
163 if (testCase.stackTrace != null) { | 166 if (testCase.stackTrace != null) { |
| 167 var message = json.stringify(testCase.stackTrace.frames.map((frame) { |
| 168 return <String>{ |
| 169 "uri": frame.uri.toString(), |
| 170 "line": frame.line, |
| 171 "column": frame.column, |
| 172 "member": frame.member |
| 173 }; |
| 174 }).toList()); |
164 _parentWindow.postMessage( | 175 _parentWindow.postMessage( |
165 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*'); | 176 _Message.text(_Message.STACK, elapsed, message), '*'); |
166 } | 177 } |
167 _parentWindow.postMessage( | 178 _parentWindow.postMessage( |
168 _Message.text(testCase.result, elapsed, testCase.message), '*'); | 179 _Message.text(testCase.result, elapsed, testCase.message), '*'); |
169 } | 180 } |
170 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 181 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
171 String uncaughtError) { | 182 String uncaughtError) { |
172 } | 183 } |
173 | 184 |
174 void onDone(bool success) { | 185 void onDone(bool success) { |
175 _uninstallErrorHandler(); | 186 _uninstallErrorHandler(); |
176 } | 187 } |
177 } | 188 } |
178 | 189 |
179 /** | 190 /** |
180 * The parent configuration runs in the top-level window; it wraps the tests | 191 * The parent configuration runs in the top-level window; it wraps the tests |
181 * in new functions that create child IFrames and run the real tests. | 192 * in new functions that create child IFrames and run the real tests. |
182 */ | 193 */ |
183 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { | 194 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
184 final Map<int,DateTime> _testStarts; | 195 final Map<int,DateTime> _testStarts; |
185 | 196 |
186 | 197 |
187 /** The stack that was posted back from the child, if any. */ | 198 /** The stack that was posted back from the child, if any. */ |
188 String _stack; | 199 Trace _stack; |
189 | 200 |
190 int _testTime; | 201 int _testTime; |
191 /** | 202 /** |
192 * Whether or not we have already wrapped the TestCase test functions | 203 * Whether or not we have already wrapped the TestCase test functions |
193 * in new closures that instead create an IFrame and get it to run the | 204 * in new closures that instead create an IFrame and get it to run the |
194 * test. | 205 * test. |
195 */ | 206 */ |
196 bool _doneWrap = false; | 207 bool _doneWrap = false; |
197 | 208 |
198 StreamSubscription _messageSubscription; | 209 StreamSubscription _messageSubscription; |
(...skipping 27 matching lines...) Expand all Loading... |
226 void _handleMessage(MessageEvent e) { | 237 void _handleMessage(MessageEvent e) { |
227 // Get the result, do any logging, then do a pass/fail. | 238 // Get the result, do any logging, then do a pass/fail. |
228 var msg = new _Message.fromString(e.data); | 239 var msg = new _Message.fromString(e.data); |
229 | 240 |
230 if(msg == null) { | 241 if(msg == null) { |
231 return; | 242 return; |
232 } | 243 } |
233 if (msg.messageType == _Message.LOG) { | 244 if (msg.messageType == _Message.LOG) { |
234 logMessage(e.data); | 245 logMessage(e.data); |
235 } else if (msg.messageType == _Message.STACK) { | 246 } else if (msg.messageType == _Message.STACK) { |
236 _stack = msg.body; | 247 _stack = new Trace(json.parse(msg.body).map((frame) { |
| 248 return new Frame( |
| 249 Uri.parse(frame['uri']), |
| 250 frame['line'], |
| 251 frame['column'], |
| 252 frame['member']); |
| 253 })); |
237 } else { | 254 } else { |
238 _testTime = msg.elapsed; | 255 _testTime = msg.elapsed; |
239 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete')); | 256 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete')); |
240 if (msg.messageType == _Message.PASS) { | 257 if (msg.messageType == _Message.PASS) { |
241 currentTestCase.pass(); | 258 currentTestCase.pass(); |
242 } else if (msg.messageType == _Message.FAIL) { | 259 } else if (msg.messageType == _Message.FAIL) { |
243 currentTestCase.fail(msg.body, _stack); | 260 currentTestCase.fail(msg.body, _stack); |
244 } else if (msg.messageType == _Message.ERROR) { | 261 } else if (msg.messageType == _Message.ERROR) { |
245 currentTestCase.error(msg.body, _stack); | 262 currentTestCase.error(msg.body, _stack); |
246 } | 263 } |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 ul, menu, dir { | 700 ul, menu, dir { |
684 display: block; | 701 display: block; |
685 list-style-type: disc; | 702 list-style-type: disc; |
686 -webkit-margin-before: 1em; | 703 -webkit-margin-before: 1em; |
687 -webkit-margin-after: 1em; | 704 -webkit-margin-after: 1em; |
688 -webkit-margin-start: 0px; | 705 -webkit-margin-start: 0px; |
689 -webkit-margin-end: 0px; | 706 -webkit-margin-end: 0px; |
690 -webkit-padding-start: 40px; | 707 -webkit-padding-start: 40px; |
691 } | 708 } |
692 """; | 709 """; |
OLD | NEW |