Comparing version 1.0.2 to 1.1.0
@@ -7,5 +7,2 @@ #! /usr/bin/env node | ||
.map((x) => require('path').resolve(x)) | ||
.forEach((testfile) => { | ||
process.stdout.write(`${testfile}\n`); | ||
return require(testfile); | ||
}); | ||
.forEach((testfile) => require(testfile)); |
@@ -1,1 +0,1 @@ | ||
export function test(name: string, assertion?: Function | Promise<void>): Promise<void>; | ||
export function test(description: string, assertion?: Function | Promise<void>): Promise<void>; |
27
index.js
/** | ||
* test function for `bft` | ||
* | ||
* @param {string} name - name of test | ||
* @param {string} description - description of test | ||
* @param {function|Promise<void>} [assertion] - test code | ||
*/ | ||
module.exports.test = async (name, assertion = null) => { | ||
module.exports.test = async (description, assertion = null) => { | ||
const log = (txt) => { | ||
@@ -12,12 +12,23 @@ return process.stdout.write( | ||
? txt | ||
.replace(/^PASSED/, '\x1b[32mPASSED\x1b[39m') | ||
.replace(/^FAILED/, '\x1b[31mFAILED\x1b[39m') | ||
.replace(/^SKIPPED/, '\x1b[2mSKIPPED\x1b[0m') | ||
.replace(/^PASSED/, '\x1b[32mPASSED\x1b[0m') | ||
.replace(/^FAILED/, '\x1b[31mFAILED\x1b[0m') | ||
.replace(/^SKIPPED/, '\x1b[33mSKIPPED\x1b[0m') | ||
: txt | ||
); | ||
}; | ||
const [, , caller] = new Error().stack.split('at '); | ||
const [, filename] = caller.match(/\((.*)\)/); | ||
const origin = | ||
process.stdout.hasColors && process.stdout.hasColors() === true | ||
? `\x1b[2m${filename}\x1b[0m` | ||
: filename; | ||
const name = | ||
process.stdout.hasColors && process.stdout.hasColors() === true | ||
? `\x1b[1m${description}\x1b[0m` | ||
: description; | ||
setImmediate(async () => { | ||
try { | ||
if (assertion === null) { | ||
log(`SKIPPED\t${name}`); | ||
log(`SKIPPED\t${name} << ${origin}`); | ||
return; | ||
@@ -29,5 +40,5 @@ } | ||
log(`PASSED\t${name}`); | ||
log(`PASSED\t${name} << ${origin}`); | ||
} catch (err) { | ||
log(`FAILED\t${name}`); | ||
log(`FAILED\t${name} << ${origin}`); | ||
const lines = err.stack | ||
@@ -34,0 +45,0 @@ .split('\n') |
{ | ||
"name": "bft", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "bloat-free-testrunner", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3887
56