UNPKG

poku

Version:

🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.

68 lines (67 loc) 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.describe = void 0; exports.describeBase = describeBase; const node_process_1 = require("process"); const poku_js_1 = require("../../configs/poku.js"); const callback_js_1 = require("../../parsers/callback.js"); const get_arg_js_1 = require("../../parsers/get-arg.js"); const modifiers_js_1 = require("./modifiers.js"); async function describeBase(arg1, arg2) { let title; let cb; let options; const { reporter } = poku_js_1.GLOBAL; if (typeof arg1 === 'string') { title = arg1; if (typeof arg2 === 'function') cb = arg2; else options = arg2; } else if (typeof arg1 === 'function') { cb = arg1; options = arg2; } const hasCB = typeof cb === 'function'; if (title) { if (hasCB) reporter.onDescribeStart({ title }); else reporter.onDescribeAsTitle(title, options); } if (!hasCB) return; 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 (!title) return; const duration = end[0] * 1e3 + end[1] / 1e6; reporter.onDescribeEnd({ title, duration }); poku_js_1.GLOBAL.runAsOnly = false; } async function describeCore(messageOrCb, cbOrOptions) { if (typeof messageOrCb === 'string' && typeof cbOrOptions !== 'function') return describeBase(messageOrCb, cbOrOptions); if (get_arg_js_1.hasOnly) { const hasItOnly = (0, callback_js_1.checkOnly)(typeof messageOrCb === 'function' ? messageOrCb : cbOrOptions); if (!hasItOnly) return; if (typeof messageOrCb === 'string' && typeof cbOrOptions === 'function') return describeBase(messageOrCb, cbOrOptions); if (typeof messageOrCb === 'function') return describeBase(messageOrCb); } if (typeof messageOrCb === 'string' && typeof cbOrOptions === 'function') return describeBase(messageOrCb, cbOrOptions); if (typeof messageOrCb === 'function') return describeBase(messageOrCb); } exports.describe = Object.assign(describeCore, { todo: modifiers_js_1.todo, skip: modifiers_js_1.skip, only: modifiers_js_1.onlyDescribe, });