r104691 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104690‎ | r104691 | r104692 >
Date:15:20, 30 November 2011
Author:hashar
Status:deferred (Comments)
Tags:
Comment:
add colors to visual editor parser testing

TODO: add an option to switch color scheme for light/dark backgrounds
Modified paths:
  • /trunk/extensions/VisualEditor/tests/parser/README (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -16,6 +16,7 @@
1717 var fs = require('fs'),
1818 path = require('path'),
1919 jsDiff = require('diff'),
 20+ colors = require('colors'),
2021 HTML5 = require('html5').HTML5;
2122
2223 // @fixme wrap more or this setup in a common module
@@ -197,9 +198,9 @@
198199
199200 function printTitle() {
200201 console.log('=====================================================');
201 - console.log('FAILED: ' + item.title);
 202+ console.log('FAILED'.red + ': ' + item.title.yellow);
202203 console.log(item.comments.join('\n'));
203 - console.log("INPUT:");
 204+ console.log("INPUT".cyan + ":");
204205 console.log(item.input + "\n");
205206 }
206207
@@ -242,28 +243,42 @@
243244 if ( normalizedOut !== normalizedExpected ) {
244245 printTitle();
245246 failOutputTests++;
246 - console.log('RAW EXPECTED:');
 247+ console.log('RAW EXPECTED'.cyan + ':');
247248 console.log(item.result + "\n");
248249
249 - console.log('RAW RENDERED:');
 250+ console.log('RAW RENDERED'.cyan + ':');
250251 console.log(formatHTML(out) + "\n");
251252
252253 var a = formatHTML(normalizedExpected);
253254
254 - console.log('NORMALIZED EXPECTED:');
 255+ console.log('NORMALIZED EXPECTED'.magenta + ':');
255256 console.log(a + "\n");
256257
257258 var b = formatHTML(normalizedOut);
258259
259 - console.log('NORMALIZED RENDERED:')
 260+ console.log('NORMALIZED RENDERED'.magenta + ':')
260261 console.log(formatHTML(normalizeOut(out)) + "\n");
261262 var patch = jsDiff.createPatch('wikitext.txt', a, b, 'before', 'after');
262263
263 - console.log('DIFF:');
264 - console.log(patch.replace(/^[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n/, ''));
 264+ console.log('DIFF'.cyan +': ');
 265+
 266+ var colored_diff = patch.split( '\n' ).map( function(line) {
 267+ // Add some colors to diff output
 268+ switch( line.charAt(0) ) {
 269+ case '-':
 270+ return line.red;
 271+ case '+':
 272+ return line.blue;
 273+ default:
 274+ return line;
 275+ }
 276+ }).join( "\n" );
 277+ //patch.replace(/^[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n/, '')
 278+
 279+ console.log( colored_diff );
265280 } else {
266281 passedTests++;
267 - console.log( 'PASSED: ' + item.title );
 282+ console.log( 'PASSED'.green + ': ' + item.title.yellow );
268283 }
269284 }
270285 });
Index: trunk/extensions/VisualEditor/tests/parser/README
@@ -3,6 +3,7 @@
44 Batch-testing tools loading the parsing code into node.js, and going through a MediaWiki XML export dump to run round-trip tests over it. Currently not much will succeed as there's bad handling of newlines. ;)
55
66 Need npm modules:
 7+* colors
78 * html5
89 * jquery
910 * jsdom

Comments

#Comment by Hashar (talk | contribs)   15:21, 30 November 2011

I forgot to mention it requires the "colors" npm module though it is mentioned in the README.

Status & tagging log