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

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

Issue 145403005: pkg/unittest: formatter spin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: review nits Created 6 years, 10 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 | « pkg/unittest/lib/html_config.dart ('k') | pkg/unittest/lib/interactive_html_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) 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 * 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 handleExternalError('<unknown>', '(external error detected)'); 61 handleExternalError('<unknown>', '(external error detected)');
62 } 62 }
63 } 63 }
64 64
65 void onInit() { 65 void onInit() {
66 _installHandlers(); 66 _installHandlers();
67 //initialize and load CSS 67 //initialize and load CSS
68 final String _CSSID = '_unittestcss_'; 68 final String _CSSID = '_unittestcss_';
69 69
70 var cssElement = document.head.query('#${_CSSID}'); 70 var cssElement = document.head.query('#${_CSSID}');
71 if (cssElement == null){ 71 if (cssElement == null) {
72 cssElement = new StyleElement(); 72 cssElement = new StyleElement();
73 cssElement.id = _CSSID; 73 cssElement.id = _CSSID;
74 document.head.append(cssElement); 74 document.head.append(cssElement);
75 } 75 }
76 76
77 cssElement.text = _htmlTestCSS; 77 cssElement.text = _htmlTestCSS;
78 window.postMessage('unittest-suite-wait-for-done', '*'); 78 window.postMessage('unittest-suite-wait-for-done', '*');
79 } 79 }
80 80
81 void onStart() { 81 void onStart() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 .replaceAll('unittest-row ', 'unittest-row-hidden ')); 141 .replaceAll('unittest-row ', 'unittest-row-hidden '));
142 }); 142 });
143 143
144 var previousGroup = ''; 144 var previousGroup = '';
145 var groupPassFail = true; 145 var groupPassFail = true;
146 final indentAmount = 50; 146 final indentAmount = 50;
147 147
148 // order by group and sort numerically within each group 148 // order by group and sort numerically within each group
149 var groupedBy = new LinkedHashMap<String, List<TestCase>>(); 149 var groupedBy = new LinkedHashMap<String, List<TestCase>>();
150 150
151 for (final t in results){ 151 for (final t in results) {
152 if (!groupedBy.containsKey(t.currentGroup)){ 152 if (!groupedBy.containsKey(t.currentGroup)) {
153 groupedBy[t.currentGroup] = new List<TestCase>(); 153 groupedBy[t.currentGroup] = new List<TestCase>();
154 } 154 }
155 155
156 groupedBy[t.currentGroup].add(t); 156 groupedBy[t.currentGroup].add(t);
157 } 157 }
158 158
159 // flatten the list again with tests ordered 159 // flatten the list again with tests ordered
160 List<TestCase> flattened = new List<TestCase>(); 160 List<TestCase> flattened = new List<TestCase>();
161 161
162 groupedBy 162 groupedBy
163 .values 163 .values
164 .forEach((tList){ 164 .forEach((tList){
165 tList.sort((tcA, tcB) => tcA.id - tcB.id); 165 tList.sort((tcA, tcB) => tcA.id - tcB.id);
166 flattened.addAll(tList); 166 flattened.addAll(tList);
167 } 167 }
168 ); 168 );
169 169
170 var nonAlphanumeric = new RegExp('[^a-z0-9A-Z]'); 170 var nonAlphanumeric = new RegExp('[^a-z0-9A-Z]');
171 171
172 // output group headers and test rows 172 // output group headers and test rows
173 for (final test_ in flattened) { 173 for (final test_ in flattened) {
174 174
175 // replace everything but numbers and letters from the group name with 175 // replace everything but numbers and letters from the group name with
176 // '_' so we can use in id and class properties. 176 // '_' so we can use in id and class properties.
177 var safeGroup = test_.currentGroup.replaceAll(nonAlphanumeric,'_'); 177 var safeGroup = test_.currentGroup.replaceAll(nonAlphanumeric, '_');
178 178
179 if (test_.currentGroup != previousGroup){ 179 if (test_.currentGroup != previousGroup) {
180 180
181 previousGroup = test_.currentGroup; 181 previousGroup = test_.currentGroup;
182 182
183 var testsInGroup = results 183 var testsInGroup = results
184 .where((TestCase t) => t.currentGroup == previousGroup) 184 .where((TestCase t) => t.currentGroup == previousGroup)
185 .toList(); 185 .toList();
186 var groupTotalTestCount = testsInGroup.length; 186 var groupTotalTestCount = testsInGroup.length;
187 var groupTestPassedCount = testsInGroup.where( 187 var groupTestPassedCount = testsInGroup.where(
188 (TestCase t) => t.result == 'pass').length; 188 (TestCase t) => t.result == 'pass').length;
189 groupPassFail = groupTotalTestCount == groupTestPassedCount; 189 groupPassFail = groupTotalTestCount == groupTestPassedCount;
(...skipping 11 matching lines...) Expand all
201 <div ${_isIE ? "style='display:inline-block' ": ""}> 201 <div ${_isIE ? "style='display:inline-block' ": ""}>
202 ${test_.currentGroup}</div> 202 ${test_.currentGroup}</div>
203 &nbsp; 203 &nbsp;
204 <div ${_isIE ? "style='display:inline-block' ": ""}> 204 <div ${_isIE ? "style='display:inline-block' ": ""}>
205 (${groupTestPassedCount}/${groupTotalTestCount})</div> 205 (${groupTestPassedCount}/${groupTotalTestCount})</div>
206 </div> 206 </div>
207 </div>""")); 207 </div>"""));
208 208
209 // 'safeGroup' could be empty 209 // 'safeGroup' could be empty
210 var grp = (safeGroup == '') ? null : te.query('#${safeGroup}'); 210 var grp = (safeGroup == '') ? null : te.query('#${safeGroup}');
211 if (grp != null){ 211 if (grp != null) {
212 grp.onClick.listen((_){ 212 grp.onClick.listen((_) {
213 var row = document.query('.unittest-row-${safeGroup}'); 213 var row = document.query('.unittest-row-${safeGroup}');
214 if (row.attributes['class'].contains('unittest-row ')){ 214 if (row.attributes['class'].contains('unittest-row ')){
215 document.queryAll('.unittest-row-${safeGroup}').forEach( 215 document.queryAll('.unittest-row-${safeGroup}').forEach(
216 (e) => e.attributes['class'] = e.attributes['class'] 216 (e) => e.attributes['class'] = e.attributes['class']
217 .replaceAll('unittest-row ', 'unittest-row-hidden ')); 217 .replaceAll('unittest-row ', 'unittest-row-hidden '));
218 }else{ 218 }else{
219 document.queryAll('.unittest-row-${safeGroup}').forEach( 219 document.queryAll('.unittest-row-${safeGroup}').forEach(
220 (e) => e.attributes['class'] = e.attributes['class'] 220 (e) => e.attributes['class'] = e.attributes['class']
221 .replaceAll('unittest-row-hidden', 'unittest-row')); 221 .replaceAll('unittest-row-hidden', 'unittest-row'));
222 } 222 }
(...skipping 25 matching lines...) Expand all
248 $status</div> 248 $status</div>
249 <div ${_isIE ? "style='display:inline-block' ": ""} 249 <div ${_isIE ? "style='display:inline-block' ": ""}
250 class='unittest-row-description'>$description</div> 250 class='unittest-row-description'>$description</div>
251 </div> 251 </div>
252 </div>''' 252 </div>'''
253 ) 253 )
254 ); 254 );
255 } 255 }
256 256
257 if (!test_.isComplete) { 257 if (!test_.isComplete) {
258 addRowElement('${test_.id}', 'NO STATUS', 'Test did not complete.'); 258 addRowElement('${test_.id}', 'NO STATUS', 'Test did not complete.');
259 return; 259 return;
260 } 260 }
261 261
262 addRowElement('${test_.id}', '${test_.result.toUpperCase()}', 262 addRowElement('${test_.id}', '${test_.result.toUpperCase()}',
263 '${test_.description}. ${HTML_ESCAPE.convert(test_.message)}'); 263 '${test_.description}. ${HTML_ESCAPE.convert(test_.message)}');
264 264
265 if (test_.stackTrace != null) { 265 if (test_.stackTrace != null) {
266 addRowElement('', '', 266 addRowElement('', '',
267 '<pre>${HTML_ESCAPE.convert(test_.stackTrace.toString())}</pre>'); 267 '<pre>${HTML_ESCAPE.convert(test_.stackTrace.toString())}</pre>');
268 } 268 }
269 } 269 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 '''; 411 ''';
412 } 412 }
413 413
414 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) { 414 void useHtmlEnhancedConfiguration([bool isLayoutTest = false]) {
415 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout; 415 unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonNotLayout;
416 } 416 }
417 417
418 final _singletonLayout = new HtmlEnhancedConfiguration(true); 418 final _singletonLayout = new HtmlEnhancedConfiguration(true);
419 final _singletonNotLayout = new HtmlEnhancedConfiguration(false); 419 final _singletonNotLayout = new HtmlEnhancedConfiguration(false);
OLDNEW
« no previous file with comments | « pkg/unittest/lib/html_config.dart ('k') | pkg/unittest/lib/interactive_html_config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698