Merge pull request #1085 from davisjam/PrettyPrintTests

test: pretty test output
This commit is contained in:
Josh Bruce 2018-02-26 17:31:15 -05:00 committed by GitHub
commit f53dd11d9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

41
test/index.js vendored
View File

@ -110,8 +110,13 @@ function runTests(engine, options) {
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
filename = filenames[i]; filename = filenames[i];
file = files[filename]; file = files[filename];
success = testFile(engine, file, filename, i + 1);
if (success) { var before = process.hrtime();
success = testFile(engine, file, filename, i + 1); // TODO Can't testFile throw?
var elapsed = process.hrtime(before);
var tookLessThanOneSec = (elapsed[0] === 0);
if (success && tookLessThanOneSec) {
succeeded++; succeeded++;
} else { } else {
failed++; failed++;
@ -143,6 +148,10 @@ function testFile(engine, file, filename, index) {
delete marked._original; delete marked._original;
} }
console.log('#%d. Test %s.', index, filename);
var before = process.hrtime();
if (opts.length) { if (opts.length) {
marked._original = marked.defaults; marked._original = marked.defaults;
marked.defaults = {}; marked.defaults = {};
@ -156,12 +165,23 @@ function testFile(engine, file, filename, index) {
}); });
} }
var threw = false;
var exceptionToThrow = null;
try { try {
text = engine(file.text).replace(/\s/g, ''); text = engine(file.text).replace(/\s/g, '');
html = file.html.replace(/\s/g, ''); html = file.html.replace(/\s/g, '');
} catch (e) { } catch (e) {
console.log('%s failed.', filename); threw = true;
throw e; exceptionToThrow = e;
}
var elapsed = process.hrtime(before);
var prettyElapsed = 'in ' + prettyElapsedTime(elapsed) + ' seconds';
// TODO Why do we throw this?
if (threw) {
console.log(' failed ' + prettyElapsed);
throw exceptionToThrow;
} }
l = html.length; l = html.length;
@ -177,7 +197,7 @@ function testFile(engine, file, filename, index) {
Math.min(j + 30, l)); Math.min(j + 30, l));
console.log( console.log(
'\n#%d. %s failed at offset %d. Near: "%s".\n', '\n#%d. %s failed at offset %d ' + prettyElapsed + '. Near: "%s".\n',
index, filename, j, text); index, filename, j, text);
console.log('\nGot:\n%s\n', text.trim() || text); console.log('\nGot:\n%s\n', text.trim() || text);
@ -187,8 +207,8 @@ function testFile(engine, file, filename, index) {
} }
} }
console.log('#%d. %s completed.', index, filename); console.log(' passed ' + prettyElapsed);
return true return true;
} }
/** /**
@ -581,3 +601,10 @@ if (!module.parent) {
exports.bench = bench; exports.bench = bench;
module.exports = exports; module.exports = exports;
} }
// returns time to millisecond granularity
function prettyElapsedTime(hrtimeElapsed) {
var seconds = hrtimeElapsed[0];
var fracInMs = Math.round(hrtimeElapsed[1] / 1e6);
return seconds + '.' + fracInMs;
}