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 library unittest_html_config; | 8 library unittest_html_config; |
9 | 9 |
10 import 'dart:html'; | 10 import 'dart:html'; |
11 import 'unittest.dart'; | 11 import 'unittest.dart'; |
12 | 12 |
13 /** Creates a table showing tests results in HTML. */ | 13 /** Creates a table showing tests results in HTML. */ |
14 void _showResultsInPage(int passed, int failed, int errors, | 14 void _showResultsInPage(int passed, int failed, int errors, |
15 List<TestCase> results, bool isLayoutTest, String uncaughtError) { | 15 List<TestCase> results, bool isLayoutTest, String uncaughtError) { |
16 if (isLayoutTest && (passed == results.length) && uncaughtError == null) { | 16 if (isLayoutTest && (passed == results.length) && uncaughtError == null) { |
17 document.body.innerHTML = "PASS"; | 17 document.body.innerHtml = "PASS"; |
18 } else { | 18 } else { |
19 var newBody = new StringBuffer(); | 19 var newBody = new StringBuffer(); |
20 newBody.add("<table class='unittest-table'><tbody>"); | 20 newBody.add("<table class='unittest-table'><tbody>"); |
21 newBody.add(passed == results.length && uncaughtError == null | 21 newBody.add(passed == results.length && uncaughtError == null |
22 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" | 22 ? "<tr><td colspan='3' class='unittest-pass'>PASS</td></tr>" |
23 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); | 23 : "<tr><td colspan='3' class='unittest-fail'>FAIL</td></tr>"); |
24 | 24 |
25 for (final test_ in results) { | 25 for (final test_ in results) { |
26 newBody.add(_toHtml(test_)); | 26 newBody.add(_toHtml(test_)); |
27 } | 27 } |
(...skipping 14 matching lines...) Expand all Loading... |
42 } else { | 42 } else { |
43 newBody.add(""" | 43 newBody.add(""" |
44 <tr><td colspan='3'>Total | 44 <tr><td colspan='3'>Total |
45 <span class='unittest-pass'>${passed} passed</span>, | 45 <span class='unittest-pass'>${passed} passed</span>, |
46 <span class='unittest-fail'>${failed} failed</span> | 46 <span class='unittest-fail'>${failed} failed</span> |
47 <span class='unittest-error'> | 47 <span class='unittest-error'> |
48 ${errors + (uncaughtError == null ? 0 : 1)} errors</span> | 48 ${errors + (uncaughtError == null ? 0 : 1)} errors</span> |
49 </td></tr>"""); | 49 </td></tr>"""); |
50 } | 50 } |
51 newBody.add("</tbody></table>"); | 51 newBody.add("</tbody></table>"); |
52 document.body.innerHTML = newBody.toString(); | 52 document.body.innerHtml = newBody.toString(); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 String _toHtml(TestCase test_) { | 56 String _toHtml(TestCase test_) { |
57 if (!test_.isComplete) { | 57 if (!test_.isComplete) { |
58 return ''' | 58 return ''' |
59 <tr> | 59 <tr> |
60 <td>${test_.id}</td> | 60 <td>${test_.id}</td> |
61 <td class="unittest-error">NO STATUS</td> | 61 <td class="unittest-error">NO STATUS</td> |
62 <td>Test did not complete</td> | 62 <td>Test did not complete</td> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 _uninstallHandlers(); | 139 _uninstallHandlers(); |
140 _showResultsInPage(passed, failed, errors, results, _isLayoutTest, | 140 _showResultsInPage(passed, failed, errors, results, _isLayoutTest, |
141 uncaughtError); | 141 uncaughtError); |
142 window.postMessage('unittest-suite-done', '*'); | 142 window.postMessage('unittest-suite-done', '*'); |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 void useHtmlConfiguration([bool isLayoutTest = false]) { | 146 void useHtmlConfiguration([bool isLayoutTest = false]) { |
147 configure(new HtmlConfiguration(isLayoutTest)); | 147 configure(new HtmlConfiguration(isLayoutTest)); |
148 } | 148 } |
OLD | NEW |