UNPKG

1.2 kBJavaScriptView Raw
1'use strict'
2
3const back = require('./lib/back')
4const emitter = require('./lib/global_emitter')
5const {
6 activate,
7 isActive,
8 isDone,
9 pendingMocks,
10 activeMocks,
11 removeInterceptor,
12 disableNetConnect,
13 enableNetConnect,
14 removeAll,
15 abortPendingRequests,
16} = require('./lib/intercept')
17const recorder = require('./lib/recorder')
18const { Scope, load, loadDefs, define } = require('./lib/scope')
19
20module.exports = (basePath, options) => new Scope(basePath, options)
21
22Object.assign(module.exports, {
23 activate,
24 isActive,
25 isDone,
26 pendingMocks,
27 activeMocks,
28 removeInterceptor,
29 disableNetConnect,
30 enableNetConnect,
31 // TODO-12.x Historically `nock.cleanAll()` has returned the nock global.
32 // The other global methods do not do this, so it's not clear this was
33 // deliberate or is even helpful. This shim is included for backward
34 // compatibility and shoulud be replaced with an alias to `removeAll()`.
35 cleanAll() {
36 removeAll()
37 return module.exports
38 },
39 abortPendingRequests,
40 load,
41 loadDefs,
42 define,
43 emitter,
44 recorder: {
45 rec: recorder.record,
46 clear: recorder.clear,
47 play: recorder.outputs,
48 },
49 restore: recorder.restore,
50 back,
51})