Permalink
June 18, 2020 16:31
Newer
100644
53 lines (49 sloc)
1.24 KB
Ignoring revisions in .git-blame-ignore-revs.
1
'use strict'
2
3
const back = require('./lib/back')
4
const emitter = require('./lib/global_emitter')
5
const {
6
activate,
7
isActive,
8
isDone,
9
isOn,
10
pendingMocks,
11
activeMocks,
12
removeInterceptor,
13
disableNetConnect,
14
enableNetConnect,
15
removeAll,
16
abortPendingRequests,
17
} = require('./lib/intercept')
18
const recorder = require('./lib/recorder')
19
const { Scope, load, loadDefs, define } = require('./lib/scope')
20
21
module.exports = (basePath, options) => new Scope(basePath, options)
22
23
Object.assign(module.exports, {
24
activate,
25
isActive,
26
isDone,
27
pendingMocks,
28
activeMocks,
29
removeInterceptor,
30
disableNetConnect,
31
enableNetConnect,
32
cleanAll: removeAll,
33
abortPendingRequests,
34
load,
35
loadDefs,
36
define,
37
emitter,
38
recorder: {
39
rec: recorder.record,
40
clear: recorder.clear,
41
play: recorder.outputs,
42
},
43
restore: recorder.restore,
44
back,
45
})
46
47
// We always activate Nock on import, overriding the globals.
48
// Setting the Back mode "activates" Nock by overriding the global entries in the `http/s` modules.
49
// If Nock Back is configured, we need to honor that setting for backward compatibility,
50
// otherwise we rely on Nock Back's default initializing side effect.
51
if (isOn()) {
52
back.setMode(process.env.NOCK_BACK_MODE || 'dryrun')
53
}