UNPKG

fancy-test

Version:

extendable utilities for testing

39 lines (38 loc) 891 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nock = void 0; function nock(host, options, cb) { if (typeof options === 'function') { cb = options; options = {}; } if (cb === undefined) throw new Error('callback is undefined'); let nock; try { nock = require('nock'); } catch (_a) { return { run() { require('nock'); }, }; } const intercepter = nock(host, options); return { async run(ctx) { ctx.nock = ctx.nock || 0; await cb(intercepter); ctx.nock++; }, finally(ctx) { if (!ctx.error) intercepter.done(); ctx.nock--; if (ctx.nock === 0) nock.cleanAll(); }, }; } exports.nock = nock;