poku
Version:
🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.
45 lines (44 loc) • 1.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processAsyncAssert = exports.processAssert = void 0;
const node_assert_1 = require("assert");
const node_process_1 = __importDefault(require("process"));
const poku_js_1 = require("../configs/poku.js");
const assertProcessor = () => {
const { isPoku, reporter } = poku_js_1.GLOBAL;
const handleSuccess = ({ message }) => {
if (typeof message === 'string')
reporter.onAssertionSuccess({ message });
};
const handleError = (error, options) => {
node_process_1.default.exitCode = 1;
if (error instanceof node_assert_1.AssertionError)
reporter.onAssertionFailure({ assertOptions: options, error });
if (isPoku)
throw error;
};
const processAssert = (cb, options) => {
try {
cb();
handleSuccess(options);
}
catch (error) {
handleError(error, options);
}
};
const processAsyncAssert = async (cb, options) => {
try {
await cb();
handleSuccess(options);
}
catch (error) {
handleError(error, options);
}
};
return { processAssert, processAsyncAssert };
};
_a = assertProcessor(), exports.processAssert = _a.processAssert, exports.processAsyncAssert = _a.processAsyncAssert;