Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: pretty test output #1085

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ function runTests(engine, options) {
for (i = 0; i < len; i++) {
filename = filenames[i];
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++;
} else {
failed++;
Expand Down Expand Up @@ -143,6 +148,10 @@ function testFile(engine, file, filename, index) {
delete marked._original;
}

console.log('#%d. Test %s.', index, filename);

var before = process.hrtime();

if (opts.length) {
marked._original = marked.defaults;
marked.defaults = {};
Expand All @@ -156,13 +165,24 @@ function testFile(engine, file, filename, index) {
});
}

var threw = false;
var exceptionToThrow = null;
try {
text = engine(file.text).replace(/\s/g, '');
html = file.html.replace(/\s/g, '');
} catch (e) {
console.log('%s failed.', filename);
throw e;
threw = true;
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;

Expand All @@ -177,7 +197,7 @@ function testFile(engine, file, filename, index) {
Math.min(j + 30, l));

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);

console.log('\nGot:\n%s\n', text.trim() || text);
Expand All @@ -187,8 +207,8 @@ function testFile(engine, file, filename, index) {
}
}

console.log('#%d. %s completed.', index, filename);
return true
console.log(' passed ' + prettyElapsed);
return true;
}

/**
Expand Down Expand Up @@ -581,3 +601,10 @@ if (!module.parent) {
exports.bench = bench;
module.exports = exports;
}

// returns time to millisecond granularity
function prettyElapsedTime(hrtimeElapsed) {
var seconds = hrtimeElapsed[0];
var fracInMs = Math.round(hrtimeElapsed[1] / 1e6);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how hard up we are for the ms instead of seconds. Can we go to the second or third floating point??

0.001

return seconds + '.' + fracInMs;
}