Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active November 22, 2019 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebReflection/00531a64bb7b846c9b78e059fc0441ff to your computer and use it in GitHub Desktop.
Save WebReflection/00531a64bb7b846c9b78e059fc0441ff to your computer and use it in GitHub Desktop.
tressa.js in a nutshell
/*! by @WebReflection & @daw985 */
// full module, compatible with node 0.8+ & browser
// https://github.com/WebReflection/tressa
// for sync tests
function test(condition, message) {
try {
console.assert.apply(console, arguments);
if (typeof message === 'string' && condition) {
console.log('✔ ' + message);
}
} catch(error) {
test.exitCode = 1;
console.error('✖ ' + error);
}
}
// for async tests
test.async = function (fn, timeout) {
var timer = setTimeout(
function () { test(false, 'timeout ' + fn); },
timeout || test.timeout
);
fn(function () { clearTimeout(timer); });
};
// default timeout
test.timeout = 10000;
// for node env only
try {
process.on('exit', function () {
process.exit(test.exitCode || 0);
});
module.exports = test;
} catch(browser) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment