Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: pkg/unittest/lib/html_config.dart

Issue 12824008: Making it easier to run individual HTML tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/unittest/lib/html_individual_config.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 newBody.write(""" 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.write("</tbody></table>"); 52 newBody.write("</tbody></table>");
53 document.body.innerHtml = newBody.toString(); 53 document.body.innerHtml = newBody.toString();
54
55 window.onHashChange.listen((_) {
56 window.location.reload();
57 });
54 } 58 }
55 } 59 }
56 60
57 String _toHtml(TestCase test_) { 61 String _toHtml(TestCase test_) {
58 if (!test_.isComplete) { 62 if (!test_.isComplete) {
59 return ''' 63 return '''
60 <tr> 64 <tr>
61 <td>${test_.id}</td> 65 <td>${test_.id}</td>
62 <td class="unittest-error">NO STATUS</td> 66 <td class="unittest-error">NO STATUS</td>
63 <td>Test did not complete</td> 67 <td>Test did not complete</td>
64 </tr>'''; 68 </tr>''';
65 } 69 }
66 70
67 var html = ''' 71 var html = '''
68 <tr> 72 <tr>
69 <td>${test_.id}</td> 73 <td>${test_.id}</td>
70 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td> 74 <td class="unittest-${test_.result}">${test_.result.toUpperCase()}</td>
71 <td>Expectation: ${test_.description}. ${_htmlEscape(test_.message)}</td > 75 <td>Expectation: <a href="#testFilter=${test_.description}">${test_.desc ription}</a>. ${_htmlEscape(test_.message)}</td>
72 </tr>'''; 76 </tr>''';
73 77
74 if (test_.stackTrace != null) { 78 if (test_.stackTrace != null) {
75 html = '$html<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrac e)}</pre></td></tr>'; 79 html = '$html<tr><td></td><td colspan="2"><pre>${_htmlEscape(test_.stackTrac e)}</pre></td></tr>';
76 } 80 }
77 81
78 return html; 82 return html;
79 } 83 }
80 84
81 //TODO(pquitslund): Move to a common lib 85 //TODO(pquitslund): Move to a common lib
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 if ('unittest-suite-external-error' == e.data) { 123 if ('unittest-suite-external-error' == e.data) {
120 handleExternalError('<unknown>', '(external error detected)'); 124 handleExternalError('<unknown>', '(external error detected)');
121 } 125 }
122 } 126 }
123 127
124 void onInit() { 128 void onInit() {
125 _installHandlers(); 129 _installHandlers();
126 window.postMessage('unittest-suite-wait-for-done', '*'); 130 window.postMessage('unittest-suite-wait-for-done', '*');
127 } 131 }
128 132
133 void onStart() {
134 // If the URL has a #testFilter=testName then filter tests to that.
135 // This is used to make it easy to run a single test- but is only intended
136 // for interactive debugging scenarios.
137 var hash = window.location.hash;
138 if (hash != null && hash.length > 1) {
139 var params = hash.substring(1).split('&');
140 for (var param in params) {
141 var parts = param.split('=');
142 if (parts.length == 2 && parts[0] == 'testFilter') {
143 filterTests('^${parts[1]}');
144 }
145 }
146 }
147 super.onStart();
148 }
149
129 void onSummary(int passed, int failed, int errors, List<TestCase> results, 150 void onSummary(int passed, int failed, int errors, List<TestCase> results,
130 String uncaughtError) { 151 String uncaughtError) {
131 _showResultsInPage(passed, failed, errors, results, _isLayoutTest, 152 _showResultsInPage(passed, failed, errors, results, _isLayoutTest,
132 uncaughtError); 153 uncaughtError);
133 } 154 }
134 155
135 void onDone(bool success) { 156 void onDone(bool success) {
136 _uninstallHandlers(); 157 _uninstallHandlers();
137 window.postMessage('unittest-suite-done', '*'); 158 window.postMessage('unittest-suite-done', '*');
138 } 159 }
139 } 160 }
140 161
141 void useHtmlConfiguration([bool isLayoutTest = false]) { 162 void useHtmlConfiguration([bool isLayoutTest = false]) {
142 if (config != null) return; 163 if (config != null) return;
143 configure(new HtmlConfiguration(isLayoutTest)); 164 configure(new HtmlConfiguration(isLayoutTest));
144 } 165 }
OLDNEW
« no previous file with comments | « no previous file | pkg/unittest/lib/html_individual_config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698