UNPKG

891 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.nock = void 0;
4function nock(host, options, cb) {
5 if (typeof options === 'function') {
6 cb = options;
7 options = {};
8 }
9 if (cb === undefined)
10 throw new Error('callback is undefined');
11 let nock;
12 try {
13 nock = require('nock');
14 }
15 catch (_a) {
16 return {
17 run() {
18 require('nock');
19 },
20 };
21 }
22 const intercepter = nock(host, options);
23 return {
24 async run(ctx) {
25 ctx.nock = ctx.nock || 0;
26 await cb(intercepter);
27 ctx.nock++;
28 },
29 finally(ctx) {
30 if (!ctx.error)
31 intercepter.done();
32 ctx.nock--;
33 if (ctx.nock === 0)
34 nock.cleanAll();
35 },
36 };
37}
38exports.nock = nock;