UNPKG

nock

Version:

HTTP server mocking and expectations library for Node.js

110 lines (52 loc) • 3.06 kB
import back from './lib/back.js' import emitter from './lib/global_emitter.js' import { activate, isActive, isDone, isOn, pendingMocks, activeMocks, removeInterceptor, disableNetConnect, enableNetConnect, removeAll, abortPendingRequests, } from './lib/intercept.js' import * as recorder from './lib/recorder.js' import { Scope as ScopeClass, load, loadDefs, define } from './lib/scope.js' import { getGetRequestBody } from './lib/utils/node/index.js' function nock(basePath , options ) { return new ScopeClass(basePath, options) } nock.activate = activate nock.isActive = isActive nock.isDone = isDone nock.pendingMocks = pendingMocks nock.activeMocks = activeMocks nock.removeInterceptor = removeInterceptor nock.disableNetConnect = disableNetConnect nock.enableNetConnect = enableNetConnect nock.cleanAll = removeAll nock.abortPendingRequests = abortPendingRequests nock.load = load nock.loadDefs = loadDefs nock.define = define nock.emitter = emitter nock.recorder = { rec: recorder.record, clear: recorder.clear, play: recorder.outputs, } nock.restore = recorder.restore nock.back = back nock.getGetRequestBody = getGetRequestBody export default nock // Re-export types into the nock namespace so consumers can use nock.Scope, nock.Options, etc. // We always activate Nock on import, overriding the globals. // Setting the Back mode "activates" Nock by overriding the global entries in the `http/s` modules. // If Nock Back is configured, we need to honor that setting for backward compatibility, // otherwise we rely on Nock Back's default initializing side effect. if (isOn()) { back.setMode(process.env.NOCK_BACK_MODE || 'dryrun') }