From 302e1519b3b53b70a5476ad3b350f1f213c67be4 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 30 Nov 2011 15:20:46 +0000 Subject: [PATCH] add colors to visual editor parser testing TODO: add an option to switch color scheme for light/dark backgrounds --- tests/parser/README | 1 + tests/parser/parserTests.js | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/tests/parser/README b/tests/parser/README index a5f1b51259..e56f1f9649 100644 --- a/tests/parser/README +++ b/tests/parser/README @@ -3,6 +3,7 @@ Work in progress. :) 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. ;) Need npm modules: +* colors * html5 * jquery * jsdom diff --git a/tests/parser/parserTests.js b/tests/parser/parserTests.js index 31018f1e01..e4bebbf1d1 100644 --- a/tests/parser/parserTests.js +++ b/tests/parser/parserTests.js @@ -16,6 +16,7 @@ var fs = require('fs'), path = require('path'), jsDiff = require('diff'), + colors = require('colors'), HTML5 = require('html5').HTML5; // @fixme wrap more or this setup in a common module @@ -197,9 +198,9 @@ function processTest(item) { function printTitle() { console.log('====================================================='); - console.log('FAILED: ' + item.title); + console.log('FAILED'.red + ': ' + item.title.yellow); console.log(item.comments.join('\n')); - console.log("INPUT:"); + console.log("INPUT".cyan + ":"); console.log(item.input + "\n"); } @@ -242,28 +243,42 @@ function processTest(item) { if ( normalizedOut !== normalizedExpected ) { printTitle(); failOutputTests++; - console.log('RAW EXPECTED:'); + console.log('RAW EXPECTED'.cyan + ':'); console.log(item.result + "\n"); - console.log('RAW RENDERED:'); + console.log('RAW RENDERED'.cyan + ':'); console.log(formatHTML(out) + "\n"); var a = formatHTML(normalizedExpected); - console.log('NORMALIZED EXPECTED:'); + console.log('NORMALIZED EXPECTED'.magenta + ':'); console.log(a + "\n"); var b = formatHTML(normalizedOut); - console.log('NORMALIZED RENDERED:') + console.log('NORMALIZED RENDERED'.magenta + ':') console.log(formatHTML(normalizeOut(out)) + "\n"); var patch = jsDiff.createPatch('wikitext.txt', a, b, 'before', 'after'); - console.log('DIFF:'); - console.log(patch.replace(/^[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n/, '')); + console.log('DIFF'.cyan +': '); + + var colored_diff = patch.split( '\n' ).map( function(line) { + // Add some colors to diff output + switch( line.charAt(0) ) { + case '-': + return line.red; + case '+': + return line.blue; + default: + return line; + } + }).join( "\n" ); + //patch.replace(/^[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n/, '') + + console.log( colored_diff ); } else { passedTests++; - console.log( 'PASSED: ' + item.title ); + console.log( 'PASSED'.green + ': ' + item.title.yellow ); } } });