| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 * A simple unit test library for running tests in a browser. | 6 * A simple unit test library for running tests in a browser. |
| 7 * | 7 * |
| 8 * Provides enhanced HTML output with collapsible group headers | 8 * Provides enhanced HTML output with collapsible group headers |
| 9 * and other at-a-glance information about the test results. | 9 * and other at-a-glance information about the test results. |
| 10 */ | 10 */ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 void onStart() { | 45 void onStart() { |
| 46 window.postMessage('unittest-suite-wait-for-done', '*'); | 46 window.postMessage('unittest-suite-wait-for-done', '*'); |
| 47 // Listen for uncaught errors. | 47 // Listen for uncaught errors. |
| 48 window.on.error.add(_onErrorClosure); | 48 window.on.error.add(_onErrorClosure); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void onTestResult(TestCase testCase) {} | 51 void onTestResult(TestCase testCase) {} |
| 52 | 52 |
| 53 void onDone(int passed, int failed, int errors, List<TestCase> results) { | 53 void onDone(int passed, int failed, int errors, List<TestCase> results, |
| 54 String uncaughtError) { |
| 54 window.on.error.remove(_onErrorClosure); | 55 window.on.error.remove(_onErrorClosure); |
| 55 | 56 |
| 56 _showInteractiveResultsInPage(passed, failed, errors, results, | 57 _showInteractiveResultsInPage(passed, failed, errors, results, |
| 57 _isLayoutTest); | 58 _isLayoutTest, uncaughtError); |
| 58 | 59 |
| 59 window.postMessage('unittest-suite-done', '*'); | 60 window.postMessage('unittest-suite-done', '*'); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void _showInteractiveResultsInPage(int passed, int failed, int errors, | 63 void _showInteractiveResultsInPage(int passed, int failed, int errors, |
| 63 List<TestCase> results, bool isLayoutTest){ | 64 List<TestCase> results, bool isLayoutTest, String uncaughtError) { |
| 64 if (isLayoutTest && passed == results.length) { | 65 if (isLayoutTest && passed == results.length) { |
| 65 document.body.innerHTML = "PASS"; | 66 document.body.innerHTML = "PASS"; |
| 66 } else { | 67 } else { |
| 67 // changed the StringBuffer to an Element fragment | 68 // changed the StringBuffer to an Element fragment |
| 68 Element te = new Element.html('<div class="unittest-table"></div>'); | 69 Element te = new Element.html('<div class="unittest-table"></div>'); |
| 69 | 70 |
| 70 te.elements.add(new Element.html(passed == results.length | 71 te.elements.add(new Element.html(passed == results.length |
| 71 ? "<div class='unittest-overall unittest-pass'>PASS</div>" | 72 ? "<div class='unittest-overall unittest-pass'>PASS</div>" |
| 72 : "<div class='unittest-overall unittest-fail'>FAIL</div>")); | 73 : "<div class='unittest-overall unittest-fail'>FAIL</div>")); |
| 73 | 74 |
| 74 // moved summary to the top since web browsers | 75 // moved summary to the top since web browsers |
| 75 // don't auto-scroll to the bottom like consoles typically do. | 76 // don't auto-scroll to the bottom like consoles typically do. |
| 76 if (passed == results.length) { | 77 if (passed == results.length && uncaughtError == null) { |
| 77 te.elements.add(new Element.html(""" | 78 te.elements.add(new Element.html(""" |
| 78 <div class='unittest-pass'>All ${passed} tests passed</div>""")); | 79 <div class='unittest-pass'>All ${passed} tests passed</div>""")); |
| 79 } else { | 80 } else { |
| 80 | 81 |
| 82 if (uncaughtError != null) { |
| 83 te.elements.add(new Element.html(""" |
| 84 <div class='unittest-summary'> |
| 85 <span class='unittest-error'>Uncaught error: $uncaughtError</span> |
| 86 </div>""")); |
| 87 } |
| 88 |
| 81 te.elements.add(new Element.html(""" | 89 te.elements.add(new Element.html(""" |
| 82 <div class='unittest-summary'> | 90 <div class='unittest-summary'> |
| 83 <span class='unittest-pass'>Total ${passed} passed</span>, | 91 <span class='unittest-pass'>Total ${passed} passed</span>, |
| 84 <span class='unittest-fail'>${failed} failed</span>, | 92 <span class='unittest-fail'>${failed} failed</span>, |
| 85 <span class='unittest-error'>${errors} errors</span> | 93 <span class='unittest-error'> |
| 86 </div>""")); | 94 ${errors + (uncaughtError == null ? 0 : 1)} errors</span> |
| 95 </div>""")); |
| 87 } | 96 } |
| 88 | 97 |
| 89 te.elements.add(new Element.html(""" | 98 te.elements.add(new Element.html(""" |
| 90 <div><button id='btnCollapseAll'>Collapse All</button></div> | 99 <div><button id='btnCollapseAll'>Collapse All</button></div> |
| 91 """)); | 100 """)); |
| 92 | 101 |
| 93 // handle the click event for the collapse all button | 102 // handle the click event for the collapse all button |
| 94 te.query('#btnCollapseAll').on.click.add((_){ | 103 te.query('#btnCollapseAll').on.click.add((_){ |
| 95 document | 104 document |
| 96 .queryAll('.unittest-row') | 105 .queryAll('.unittest-row') |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 .unittest-row-description | 363 .unittest-row-description |
| 355 { | 364 { |
| 356 } | 365 } |
| 357 | 366 |
| 358 '''; | 367 '''; |
| 359 } | 368 } |
| 360 | 369 |
| 361 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { | 370 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { |
| 362 configure(new HtmlEnhancedConfiguration(isLayoutTest)); | 371 configure(new HtmlEnhancedConfiguration(isLayoutTest)); |
| 363 } | 372 } |
| OLD | NEW |