UNPKG

poku

Version:

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

74 lines (73 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.afterEach = exports.beforeEach = void 0; const each_js_1 = require("../../configs/each.js"); /** * Handle **global states** and **external** services before each `test` or `it`. * * --- * * ```ts * import { beforeEach } from 'poku'; * * const before = beforeEach(() => { * * }; * * before.pause(); * before.continue(); * before.reset(); * ``` */ const beforeEach = (callback, options) => { options?.immediate && callback(); each_js_1.each.before.cb = () => { if (each_js_1.each.before.status) return callback(); }; const pause = () => { each_js_1.each.before.status = false; }; const continueFunc = () => { each_js_1.each.before.status = true; }; const reset = () => { each_js_1.each.before.cb = undefined; }; return { pause, continue: continueFunc, reset }; }; exports.beforeEach = beforeEach; /** * Handle **global states** and **external** services after each `test` or `it`. * * --- * * ```ts * import { afterEach } from 'poku'; * * const after = afterEach(() => { * * }; * * after.pause(); * after.continue(); * after.reset(); * ``` */ const afterEach = (callback) => { each_js_1.each.after.cb = () => { if (each_js_1.each.after.status) return callback(); }; const pause = () => { each_js_1.each.after.status = false; }; const continueFunc = () => { each_js_1.each.after.status = true; }; const reset = () => { each_js_1.each.after.cb = undefined; }; return { pause, continue: continueFunc, reset }; }; exports.afterEach = afterEach;