Debian Codegraph @

debian/tests/test_modules/@tufjs/repo-mock/dist/mock.js

raw
1 "use strict";
2 var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4 };
5 Object.defineProperty(exports, "__esModule", { value: true });
6 exports.mock = mock;
7 const nock_1 = __importDefault(require("nock"));
8 // Sets-up nock-based mocking for the given handler
9 function mock(base, handler) {
10 (0, nock_1.default)(base).get(handler.path).reply(adapt(handler.fn));
11 }
12 // Adapts our HandlerFn to nock's NockHandler format
13 function adapt(handler) {
14 /* istanbul ignore next */
15 return () => {
16 const { statusCode, response, contentType } = handler();
17 return [
18 statusCode,
19 response,
20 { 'Content-Type': contentType || 'text/plain' },
21 ];
22 };
23 }