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