UNPKG

poku

Version:

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

45 lines (43 loc) 2.15 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.onSigint = void 0; exports.poku = poku; const node_path_1 = require("path"); const node_process_1 = __importDefault(require("process")); const poku_js_1 = require("../../configs/poku.js"); const reporter_js_1 = require("../../services/reporter.js"); const run_tests_js_1 = require("../../services/run-tests.js"); const exit_js_1 = require("../helpers/exit.js"); const list_files_js_1 = require("../helpers/list-files.js"); const onSigint = () => node_process_1.default.stdout.write('\u001B[?25h'); exports.onSigint = onSigint; node_process_1.default.once('SIGINT', exports.onSigint); async function poku(targetPaths, configs) { if (configs) poku_js_1.GLOBAL.configs = { ...poku_js_1.GLOBAL.configs, ...configs }; poku_js_1.timespan.started = new Date(); const start = node_process_1.default.hrtime(); const paths = Array.prototype.concat(targetPaths); const showLogs = !poku_js_1.GLOBAL.configs.quiet; const { reporter: plugin } = poku_js_1.GLOBAL.configs; const { cwd } = poku_js_1.GLOBAL; const testFiles = (await Promise.all(paths.map((dir) => (0, list_files_js_1.listFiles)((0, node_path_1.join)(cwd, dir), poku_js_1.GLOBAL.configs)))).flat(1); if (typeof plugin === 'string' && plugin !== 'poku') poku_js_1.GLOBAL.reporter = reporter_js_1.reporter[plugin](); if (showLogs) poku_js_1.GLOBAL.reporter.onRunStart(); const result = await (0, run_tests_js_1.runTests)(testFiles); const code = result ? 0 : 1; const end = node_process_1.default.hrtime(start); const total = end[0] * 1e3 + end[1] / 1e6; poku_js_1.timespan.duration = total; poku_js_1.timespan.finished = new Date(); if (showLogs) poku_js_1.GLOBAL.reporter.onRunResult({ code, timespan: poku_js_1.timespan, results: poku_js_1.results }); if (poku_js_1.GLOBAL.configs.noExit) return code; (0, exit_js_1.exit)(code, poku_js_1.GLOBAL.configs.quiet); }