@hyper-fetch/core 5.0.2 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -410,6 +410,7 @@ var Request = class {
410
410
  this.client = client;
411
411
  this.requestOptions = requestOptions;
412
412
  this.requestJSON = requestJSON;
413
+ this.isMockEnabled = false;
413
414
  this.setHeaders = (headers) => {
414
415
  return this.clone({ headers });
415
416
  };
@@ -495,11 +496,17 @@ var Request = class {
495
496
  };
496
497
  this.mockData = mockData;
497
498
  this.mock = mockGenerator(mockData);
499
+ this.isMockEnabled = true;
498
500
  return this;
499
501
  };
500
502
  this.removeMock = () => {
501
503
  this.mockData = null;
502
504
  this.mock = null;
505
+ this.isMockEnabled = false;
506
+ return this;
507
+ };
508
+ this.setEnableMocking = (isMockEnabled) => {
509
+ this.isMockEnabled = isMockEnabled;
503
510
  return this;
504
511
  };
505
512
  this.setDataMapper = (dataMapper) => {
@@ -655,6 +662,7 @@ var Request = class {
655
662
  cloned.requestMapper = this.requestMapper;
656
663
  cloned.mockData = this.mockData;
657
664
  cloned.mock = this.mock;
665
+ cloned.isMockEnabled = this.isMockEnabled;
658
666
  return cloned;
659
667
  }
660
668
  };
@@ -1242,13 +1250,17 @@ var mocker = (_0, _1) => __async(void 0, [_0, _1], function* (request, {
1242
1250
  onRequestStart,
1243
1251
  onSuccess
1244
1252
  }) {
1245
- var _a, _b;
1246
- const timeout = ((_a = request.requestOptions.options) == null ? void 0 : _a.timeout) || ((_b = request.options) == null ? void 0 : _b.timeout);
1247
1253
  const mock = request.mock.next();
1248
1254
  const result = mock.value instanceof Function ? yield mock.value(request) : mock.value;
1249
1255
  return new Promise((resolve) => {
1250
1256
  const { data, status = 200, success = true, extra, config } = result;
1251
- const { requestTime = 20, responseTime = 20, totalUploaded = 1, totalDownloaded = 1 } = config || {};
1257
+ const {
1258
+ requestTime = 20,
1259
+ responseTime = 20,
1260
+ totalUploaded = 1,
1261
+ totalDownloaded = 1,
1262
+ timeout = false
1263
+ } = config || {};
1252
1264
  createAbortListener(0, {}, () => {
1253
1265
  }, resolve);
1254
1266
  onBeforeRequest();
@@ -1496,7 +1508,7 @@ var getAdapterBindings = (req, requestId, systemErrorStatus, systemErrorExtra) =
1496
1508
  if (processingError) {
1497
1509
  return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
1498
1510
  }
1499
- if (req.mock) {
1511
+ if (req.mock && req.isMockEnabled) {
1500
1512
  return mocker(request, {
1501
1513
  onError,
1502
1514
  onResponseEnd,