Skip to content

Commit 7cb2d8f

Browse files
committed
lazy require nock
1 parent 9379688 commit 7cb2d8f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/helpers.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
const fs = require('fs');
44
const path = require('path');
5-
const nock = require('nock');
65
const { URL } = require('url');
76
const JSONfn = require('json-fn');
87
const FastBoot = require('fastboot');
98
const bodyParser = require('body-parser');
109
const { deprecate } = require('util');
1110

11+
let _nock;
12+
function getNock() {
13+
if (!_nock) {
14+
_nock = require('nock');
15+
}
16+
return _nock;
17+
}
18+
1219
function createMockRequest(app) {
1320
app.post(
1421
'/__mock-request',
1522
bodyParser.json({ limit: '50mb' }),
1623
(req, res) => {
1724
const requestOrigin = req.body.origin || req.headers.origin;
18-
let mock = nock(requestOrigin)
25+
let mock = getNock()(requestOrigin)
1926
.persist()
2027
.intercept(req.body.path, req.body.method)
2128
.reply(
@@ -31,7 +38,7 @@ function createMockRequest(app) {
3138

3239
function createCleanUpMocks(app) {
3340
app.use('/__cleanup-mocks', (req, res) => {
34-
nock.cleanAll();
41+
getNock().cleanAll();
3542

3643
res.json({ ok: true });
3744
});

0 commit comments

Comments
 (0)