poku
Version:
🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.
49 lines (48 loc) • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.afterEach = exports.beforeEach = void 0;
const poku_js_1 = require("../configs/poku.js");
const write_js_1 = require("../services/write.js");
const format_js_1 = require("./format.js");
const eachCore = async (type, fileRelative) => {
const { configs } = poku_js_1.GLOBAL;
if (typeof configs?.[type] !== 'function')
return true;
const cb = configs[type];
const showLogs = !configs.quiet;
const cbName = cb.name !== type ? cb.name : 'anonymous function';
showLogs &&
(0, write_js_1.log)(` ${(0, format_js_1.format)('◯').dim().info()} ${(0, format_js_1.format)(`${type}: ${cbName}`)
.dim()
.italic()}`);
try {
await cb();
return true;
}
catch (error) {
if (showLogs) {
(0, write_js_1.log)((0, format_js_1.format)(` ✘ ${type} callback failed ${(0, format_js_1.format)(`› ${cbName}`).dim()}`)
.fail()
.bold());
(0, write_js_1.log)((0, format_js_1.format)(` ├─ Who's trying to run this ${type}?`).fail());
(0, write_js_1.log)((0, format_js_1.format)(` │ └─ ${(0, format_js_1.format)(fileRelative).fail().underline()}`).fail());
if (error instanceof Error) {
(0, write_js_1.log)((0, format_js_1.format)(' ├─ Message:').fail());
(0, write_js_1.log)((0, format_js_1.format)(` │ └─ ${error.message}`).fail());
}
}
return false;
}
};
const beforeEach = (fileRelative) => {
if (poku_js_1.GLOBAL.configs.beforeEach)
return eachCore('beforeEach', fileRelative);
return true;
};
exports.beforeEach = beforeEach;
const afterEach = (fileRelative) => {
if (poku_js_1.GLOBAL.configs.afterEach)
return eachCore('afterEach', fileRelative);
return true;
};
exports.afterEach = afterEach;