Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
const assert = require('assert');
const kleur = require('kleur');
const testCases = new Set();
module.exports = function test(title, testCase) {
testCases.add([title, testCase]);
};
process.nextTick(run);
function run() {
const failed = [];
for (const [title, testCase] of testCases) {
try {
testCase(assert);
} catch (err) {
const message = `Test \`${kleur.yellow(title)}\` threw:\n\n${kleur.red(
err.message,
)}`;
failed.push(message);
}
}
const { length: failedCases } = failed;
const passedCases = testCases.size - failedCases;
failed.forEach(err => console.error(err));
console.log(
`${kleur.green(`${passedCases} test passed.`)}\n${kleur.red(
`${failedCases} test failed.`,
)}`,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.