poku
Version:
🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.
71 lines (70 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.it = void 0;
exports.itBase = itBase;
const node_process_1 = require("process");
const each_js_1 = require("../../../configs/each.js");
const indentation_js_1 = require("../../../configs/indentation.js");
const poku_js_1 = require("../../../configs/poku.js");
const get_arg_js_1 = require("../../../parsers/get-arg.js");
const modifiers_js_1 = require("../modifiers.js");
async function itBase(...args) {
try {
let title;
let cb;
if (typeof args[0] === 'string') {
title = args[0];
cb = args[1];
}
else
cb = args[0];
poku_js_1.GLOBAL.reporter.onItStart({ title });
if (typeof each_js_1.each.before.cb === 'function') {
const beforeResult = each_js_1.each.before.cb();
if (beforeResult instanceof Promise)
await beforeResult;
}
const start = (0, node_process_1.hrtime)();
const resultCb = cb();
if (resultCb instanceof Promise)
await resultCb;
const end = (0, node_process_1.hrtime)(start);
if (typeof each_js_1.each.after.cb === 'function') {
const afterResult = each_js_1.each.after.cb();
if (afterResult instanceof Promise)
await afterResult;
}
if (!title)
return;
const duration = end[0] * 1e3 + end[1] / 1e6;
poku_js_1.GLOBAL.reporter.onItEnd({ title, duration });
}
catch (error) {
indentation_js_1.indentation.hasItOrTest = false;
if (typeof each_js_1.each.after.cb === 'function') {
const afterResult = each_js_1.each.after.cb();
if (afterResult instanceof Promise)
await afterResult;
}
throw error;
}
}
async function itCore(titleOrCb, cb) {
if (get_arg_js_1.hasOnly) {
if (!poku_js_1.GLOBAL.runAsOnly)
return;
if (typeof titleOrCb === 'string' && typeof cb === 'function')
return itBase(titleOrCb, cb);
if (typeof titleOrCb === 'function')
return itBase(titleOrCb);
}
if (typeof titleOrCb === 'string' && cb)
return itBase(titleOrCb, cb);
if (typeof titleOrCb === 'function')
return itBase(titleOrCb);
}
exports.it = Object.assign(itCore, {
todo: modifiers_js_1.todo,
skip: modifiers_js_1.skip,
only: modifiers_js_1.onlyIt,
});