Skip to content

Commit

Permalink
update run-spec for node 4
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed May 4, 2019
1 parent 99d1fd0 commit b1174c2
Showing 1 changed file with 61 additions and 11 deletions.
72 changes: 61 additions & 11 deletions test/specs/run-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
'use strict';

function node4Polyfills() {
// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
if (!String.prototype.padEnd) {
// eslint-disable-next-line no-extend-native
String.prototype.padEnd = function padEnd(targetLength, padString) {
targetLength = targetLength >> 0; // floor if number or convert non-number to 0;
padString = String((typeof padString !== 'undefined' ? padString : ' '));
if (this.length > targetLength) {
return String(this);
} else {
targetLength = targetLength - this.length;
if (targetLength > padString.length) {
padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed
}
return String(this) + padString.slice(0, targetLength);
}
};
}

// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
if (!String.prototype.padStart) {
// eslint-disable-next-line no-extend-native
String.prototype.padStart = function padStart(targetLength, padString) {
targetLength = targetLength >> 0; // truncate if number, or convert non-number to 0;
padString = String(typeof padString !== 'undefined' ? padString : ' ');
if (this.length >= targetLength) {
return String(this);
} else {
targetLength = targetLength - this.length;
if (targetLength > padString.length) {
padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed
}
return padString.slice(0, targetLength) + String(this);
}
};
}
}

function outputCompletionTable(title, specs, longestName, maxSpecs) {
const maxSpecsLen = ('' + maxSpecs).length;
const spaces = maxSpecsLen * 2 + longestName + 11;
console.log('-'.padEnd(spaces + 4, '-'));
console.log(`| ${title.padStart(Math.ceil((spaces + title.length) / 2)).padEnd(spaces)} |`);
console.log(`| ${' '.padEnd(spaces)} |`);
for (const section in specs) {
console.log(`| ${section.padEnd(longestName)} ${('' + specs[section].pass).padStart(maxSpecsLen)} of ${('' + specs[section].total).padStart(maxSpecsLen)} ${(100 * specs[section].pass / specs[section].total).toFixed().padStart(4)}% |`);
}
console.log('-'.padEnd(spaces + 4, '-'));
console.log();
}

function runSpecs(title, file, options) {
options = options || {};
const json = require(file);
let longestName = 0;
let maxSpecs = 0;
Expand All @@ -20,19 +76,13 @@ function runSpecs(title, file, options) {
return obj;
}, {});

outputCompletionTable(title, specs, longestName, maxSpecs);

describe(title, () => {
const maxSpecsLen = ('' + maxSpecs).length;
const spaces = maxSpecsLen * 2 + longestName + 11;
console.log('-'.padEnd(spaces + 4, '-'));
console.log(`| ${title.padStart(Math.ceil((spaces + title.length) / 2)).padEnd(spaces)} |`);
console.log(`| ${' '.padEnd(spaces)} |`);
Object.keys(specs).forEach(section => {
console.log(`| ${section.padEnd(longestName)} ${('' + specs[section].pass).padStart(maxSpecsLen)} of ${('' + specs[section].total).padStart(maxSpecsLen)} ${(100 * specs[section].pass / specs[section].total).toFixed().padStart(4)}% |`);
describe(section, () => {
specs[section].specs.forEach((spec) => {
if (options) {
spec.options = Object.assign({}, options, (spec.options || {}));
}
spec.options = Object.assign({}, options, (spec.options || {}));
(spec.only ? fit : it)('should ' + (spec.shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, () => {
if (spec.shouldFail) {
expect(spec).not.toRender(spec.html);
Expand All @@ -43,10 +93,10 @@ function runSpecs(title, file, options) {
});
});
});
console.log('-'.padEnd(spaces + 4, '-'));
console.log();
});
};

node4Polyfills();

runSpecs('GFM 0.29', './gfm/gfm.0.29.json', {gfm: true});
runSpecs('CommonMark 0.29', './commonmark/commonmark.0.29.json', {headerIds: false});

0 comments on commit b1174c2

Please sign in to comment.