@ama-sdk/core 12.1.10 → 12.1.11
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/cjs/clients/api-angular-client.js +13 -18
- package/cjs/clients/api-fetch-client.js +16 -21
- package/cjs/fwk/api.helpers.js +11 -11
- package/cjs/fwk/date.js +5 -5
- package/cjs/fwk/errors.js +7 -7
- package/cjs/fwk/mocks/alf-mock-adapter.js +58 -60
- package/cjs/fwk/mocks/base-mock-adapter.js +15 -19
- package/cjs/fwk/mocks/helpers.js +3 -3
- package/cjs/fwk/param-serialization.js +6 -6
- package/cjs/fwk/reviver.js +4 -4
- package/cjs/plugins/abort/abort.spec.js +83 -81
- package/cjs/plugins/additional-params/additional-params.request.js +18 -25
- package/cjs/plugins/additional-params/additional-params.spec.js +194 -186
- package/cjs/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
- package/cjs/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
- package/cjs/plugins/api-key/api-key.request.js +12 -19
- package/cjs/plugins/api-key/api-key.spec.js +50 -50
- package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +25 -36
- package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
- package/cjs/plugins/client-facts/client-facts.request.js +18 -25
- package/cjs/plugins/client-facts/client-facts.spec.js +218 -208
- package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
- package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
- package/cjs/plugins/custom-info/custom-info.spec.js +90 -90
- package/cjs/plugins/fetch-cache/fetch-cache.spec.js +100 -98
- package/cjs/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
- package/cjs/plugins/json-token/json-token.spec.js +109 -107
- package/cjs/plugins/keepalive/keepalive.request.js +7 -12
- package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +11 -23
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
- package/cjs/plugins/mock-intercept/mock-intercept.angular.js +94 -100
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/cjs/plugins/mock-intercept/mock-intercept.interface.js +3 -3
- package/cjs/plugins/mock-intercept/mock-intercept.request.js +12 -19
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +245 -237
- package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/cjs/plugins/pii-tokenizer/pii-tokenizer.request.js +19 -27
- package/cjs/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
- package/cjs/plugins/raw-response-info/raw-response-info.spec.js +67 -67
- package/cjs/plugins/retry/retry.fetch.js +18 -27
- package/cjs/plugins/retry/retry.spec.js +233 -225
- package/cjs/plugins/reviver/reviver.spec.js +88 -86
- package/cjs/plugins/session-id/session-id.spec.js +98 -94
- package/cjs/plugins/si-token/si-token.spec.js +27 -29
- package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
- package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
- package/cjs/plugins/timeout/timeout.fetch.js +16 -22
- package/cjs/plugins/timeout/timeout.spec.js +211 -205
- package/cjs/plugins/url-rewrite/url-rewrite.request.js +9 -16
- package/cjs/plugins/url-rewrite/url-rewrite.spec.js +48 -48
- package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
- package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
- package/cjs/utils/crypto.js +15 -27
- package/cjs/utils/generic-api.js +9 -14
- package/cjs/utils/json-token.js +19 -26
- package/cjs/utils/json-token.spec.js +495 -497
- package/cjs/utils/mime-types.js +3 -3
- package/esm2015/clients/api-angular-client.js +13 -18
- package/esm2015/clients/api-fetch-client.js +16 -21
- package/esm2015/fwk/mocks/alf-mock-adapter.js +58 -60
- package/esm2015/fwk/mocks/base-mock-adapter.js +15 -19
- package/esm2015/plugins/abort/abort.spec.js +83 -81
- package/esm2015/plugins/additional-params/additional-params.request.js +15 -22
- package/esm2015/plugins/additional-params/additional-params.spec.js +194 -186
- package/esm2015/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
- package/esm2015/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
- package/esm2015/plugins/api-key/api-key.request.js +12 -19
- package/esm2015/plugins/api-key/api-key.spec.js +50 -50
- package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +21 -32
- package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
- package/esm2015/plugins/client-facts/client-facts.request.js +15 -22
- package/esm2015/plugins/client-facts/client-facts.spec.js +218 -208
- package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
- package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
- package/esm2015/plugins/custom-info/custom-info.spec.js +90 -90
- package/esm2015/plugins/fetch-cache/fetch-cache.spec.js +100 -98
- package/esm2015/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
- package/esm2015/plugins/json-token/json-token.spec.js +109 -107
- package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
- package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +8 -20
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
- package/esm2015/plugins/mock-intercept/mock-intercept.angular.js +94 -100
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
- package/esm2015/plugins/mock-intercept/mock-intercept.request.js +12 -19
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +245 -237
- package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
- package/esm2015/plugins/pii-tokenizer/pii-tokenizer.request.js +15 -23
- package/esm2015/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
- package/esm2015/plugins/raw-response-info/raw-response-info.spec.js +67 -67
- package/esm2015/plugins/retry/retry.fetch.js +18 -27
- package/esm2015/plugins/retry/retry.spec.js +233 -225
- package/esm2015/plugins/reviver/reviver.spec.js +88 -86
- package/esm2015/plugins/session-id/session-id.spec.js +98 -94
- package/esm2015/plugins/si-token/si-token.spec.js +27 -29
- package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
- package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
- package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
- package/esm2015/plugins/timeout/timeout.spec.js +211 -205
- package/esm2015/plugins/url-rewrite/url-rewrite.request.js +9 -16
- package/esm2015/plugins/url-rewrite/url-rewrite.spec.js +48 -48
- package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
- package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
- package/esm2015/utils/crypto.js +8 -20
- package/esm2015/utils/generic-api.js +9 -14
- package/esm2015/utils/json-token.js +10 -17
- package/esm2015/utils/json-token.spec.js +495 -497
- package/package.json +6 -6
|
@@ -49,7 +49,7 @@ function _define_property(obj, key, value) {
|
|
|
49
49
|
return obj;
|
|
50
50
|
}
|
|
51
51
|
function _ts_generator(thisArg, body) {
|
|
52
|
-
var f, y, t,
|
|
52
|
+
var f, y, t, _ = {
|
|
53
53
|
label: 0,
|
|
54
54
|
sent: function() {
|
|
55
55
|
if (t[0] & 1) throw t[1];
|
|
@@ -57,12 +57,8 @@ function _ts_generator(thisArg, body) {
|
|
|
57
57
|
},
|
|
58
58
|
trys: [],
|
|
59
59
|
ops: []
|
|
60
|
-
};
|
|
61
|
-
return g = {
|
|
62
|
-
next: verb(0),
|
|
63
|
-
"throw": verb(1),
|
|
64
|
-
"return": verb(2)
|
|
65
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
60
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
61
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
66
62
|
return this;
|
|
67
63
|
}), g;
|
|
68
64
|
function verb(n) {
|
|
@@ -75,7 +71,7 @@ function _ts_generator(thisArg, body) {
|
|
|
75
71
|
}
|
|
76
72
|
function step(op) {
|
|
77
73
|
if (f) throw new TypeError("Generator is already executing.");
|
|
78
|
-
while(_)try {
|
|
74
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
79
75
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
80
76
|
if (y = 0, t) op = [
|
|
81
77
|
op[0] & 2,
|
|
@@ -173,114 +169,120 @@ describe('Mock intercept', function() {
|
|
|
173
169
|
return jest.clearAllMocks();
|
|
174
170
|
});
|
|
175
171
|
describe('request plugin', function() {
|
|
176
|
-
it('should do nothing if disabled is true',
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
172
|
+
it('should do nothing if disabled is true', function() {
|
|
173
|
+
return _async_to_generator(function() {
|
|
174
|
+
var plugin, originalRequest, loaded;
|
|
175
|
+
return _ts_generator(this, function(_state) {
|
|
176
|
+
switch(_state.label){
|
|
177
|
+
case 0:
|
|
178
|
+
plugin = new _mockinterceptrequest.MockInterceptRequest({
|
|
179
|
+
disabled: true,
|
|
180
|
+
adapter: testMockAdapter
|
|
181
|
+
});
|
|
182
|
+
originalRequest = {
|
|
183
|
+
method: 'get',
|
|
184
|
+
headers: new Headers({
|
|
185
|
+
test: 'true'
|
|
186
|
+
}),
|
|
187
|
+
basePath: 'myurl'
|
|
188
|
+
};
|
|
189
|
+
loaded = plugin.load();
|
|
190
|
+
return [
|
|
191
|
+
4,
|
|
192
|
+
loaded.transform(originalRequest)
|
|
193
|
+
];
|
|
194
|
+
case 1:
|
|
195
|
+
expect.apply(void 0, [
|
|
196
|
+
_state.sent()
|
|
197
|
+
]).toEqual(originalRequest);
|
|
198
|
+
expect(initializeSpy).toHaveBeenCalled();
|
|
199
|
+
return [
|
|
200
|
+
2
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
})();
|
|
205
|
+
});
|
|
206
|
+
it('should not stringify provided api', function() {
|
|
207
|
+
return _async_to_generator(function() {
|
|
208
|
+
var plugin, loaded, originalRequest;
|
|
209
|
+
return _ts_generator(this, function(_state) {
|
|
210
|
+
switch(_state.label){
|
|
211
|
+
case 0:
|
|
212
|
+
plugin = new _mockinterceptrequest.MockInterceptRequest({
|
|
213
|
+
disabled: false,
|
|
214
|
+
adapter: testMockAdapter
|
|
215
|
+
});
|
|
216
|
+
loaded = plugin.load();
|
|
217
|
+
originalRequest = {
|
|
218
|
+
method: 'get',
|
|
219
|
+
headers: new Headers({
|
|
220
|
+
test: 'true'
|
|
221
|
+
}),
|
|
222
|
+
basePath: 'myurl',
|
|
223
|
+
api: 'should not exist'
|
|
224
|
+
};
|
|
225
|
+
return [
|
|
226
|
+
4,
|
|
227
|
+
loaded.transform(originalRequest)
|
|
228
|
+
];
|
|
229
|
+
case 1:
|
|
230
|
+
_state.sent();
|
|
231
|
+
expect(originalRequest.headers.has(_mockinterceptinterface.CUSTOM_MOCK_REQUEST_HEADER)).toBe(true);
|
|
232
|
+
expect(Object.keys(JSON.parse(originalRequest.headers.get(_mockinterceptinterface.CUSTOM_MOCK_REQUEST_HEADER)))).not.toContainEqual('api');
|
|
233
|
+
return [
|
|
234
|
+
2
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
})();
|
|
239
|
+
});
|
|
240
|
+
it('should intercept the request', function() {
|
|
241
|
+
return _async_to_generator(function() {
|
|
242
|
+
var plugin, originalRequest, loaded, transformed, res, text;
|
|
243
|
+
return _ts_generator(this, function(_state) {
|
|
244
|
+
switch(_state.label){
|
|
245
|
+
case 0:
|
|
246
|
+
// Disabled because Blob URL is not supported on NodeJS
|
|
247
|
+
plugin = new _mockinterceptrequest.MockInterceptRequest({
|
|
248
|
+
adapter: testMockAdapter
|
|
249
|
+
});
|
|
250
|
+
originalRequest = {
|
|
251
|
+
headers: new Headers({
|
|
252
|
+
test: 'true'
|
|
253
|
+
}),
|
|
254
|
+
basePath: 'myurl',
|
|
255
|
+
method: 'PATCH'
|
|
256
|
+
};
|
|
257
|
+
loaded = plugin.load();
|
|
258
|
+
return [
|
|
259
|
+
4,
|
|
260
|
+
loaded.transform(originalRequest)
|
|
261
|
+
];
|
|
262
|
+
case 1:
|
|
263
|
+
transformed = _state.sent();
|
|
264
|
+
return [
|
|
265
|
+
4,
|
|
266
|
+
fetch(transformed.basePath, transformed)
|
|
267
|
+
];
|
|
268
|
+
case 2:
|
|
269
|
+
res = _state.sent();
|
|
270
|
+
return [
|
|
271
|
+
4,
|
|
272
|
+
res.text()
|
|
273
|
+
];
|
|
274
|
+
case 3:
|
|
275
|
+
text = _state.sent();
|
|
276
|
+
expect(getMockSpy).toHaveBeenCalled();
|
|
277
|
+
expect(text).toBe(JSON.stringify(testMock.mockData));
|
|
278
|
+
expect(initializeSpy).toHaveBeenCalled();
|
|
279
|
+
return [
|
|
280
|
+
2
|
|
281
|
+
];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
})();
|
|
285
|
+
});
|
|
284
286
|
});
|
|
285
287
|
describe('fetch plugin', function() {
|
|
286
288
|
describe('when using an initialization function', function() {
|
|
@@ -297,148 +299,154 @@ describe('Mock intercept', function() {
|
|
|
297
299
|
adapter: asyncMockAdapter
|
|
298
300
|
});
|
|
299
301
|
});
|
|
300
|
-
it('should call initialize fn',
|
|
301
|
-
|
|
302
|
+
it('should call initialize fn', function() {
|
|
303
|
+
return _async_to_generator(function() {
|
|
304
|
+
var loadedPlugin, testData;
|
|
305
|
+
return _ts_generator(this, function(_state) {
|
|
306
|
+
switch(_state.label){
|
|
307
|
+
case 0:
|
|
308
|
+
loadedPlugin = plugin.load({
|
|
309
|
+
fetchPlugins: [],
|
|
310
|
+
url: 'myurl',
|
|
311
|
+
apiClient: apiClient,
|
|
312
|
+
options: {
|
|
313
|
+
headers: new Headers(_define_property({}, _mockinterceptinterface.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
testData = {
|
|
317
|
+
test: true
|
|
318
|
+
};
|
|
319
|
+
return [
|
|
320
|
+
4,
|
|
321
|
+
loadedPlugin.transform(Promise.resolve(testData))
|
|
322
|
+
];
|
|
323
|
+
case 1:
|
|
324
|
+
_state.sent();
|
|
325
|
+
expect(initializeSpy).toHaveBeenCalled();
|
|
326
|
+
expect(getMockSpy).not.toHaveBeenCalled();
|
|
327
|
+
expect(getLatestMockSpy).toHaveBeenCalledWith('testOperation');
|
|
328
|
+
return [
|
|
329
|
+
2
|
|
330
|
+
];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
})();
|
|
334
|
+
});
|
|
335
|
+
it('should throw if there is no request plugin', function() {
|
|
336
|
+
var config = {
|
|
337
|
+
fetchPlugins: [],
|
|
338
|
+
url: 'myurl',
|
|
339
|
+
apiClient: {
|
|
340
|
+
options: {
|
|
341
|
+
requestPlugins: []
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
options: {
|
|
345
|
+
headers: new Headers(_define_property({}, _mockinterceptinterface.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
expect(function() {
|
|
349
|
+
return plugin.load(config);
|
|
350
|
+
}).toThrow();
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
describe('with delay', function() {
|
|
355
|
+
it('should delay the response of the specific number', function() {
|
|
356
|
+
return _async_to_generator(function() {
|
|
357
|
+
var plugin, loadedPlugin, callback, run;
|
|
302
358
|
return _ts_generator(this, function(_state) {
|
|
303
359
|
switch(_state.label){
|
|
304
360
|
case 0:
|
|
361
|
+
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
362
|
+
adapter: testMockAdapter,
|
|
363
|
+
delayTiming: 700
|
|
364
|
+
});
|
|
305
365
|
loadedPlugin = plugin.load({
|
|
306
366
|
fetchPlugins: [],
|
|
307
|
-
url: '
|
|
367
|
+
url: '',
|
|
308
368
|
apiClient: apiClient,
|
|
309
369
|
options: {
|
|
310
370
|
headers: new Headers(_define_property({}, _mockinterceptinterface.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
311
371
|
}
|
|
312
372
|
});
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
};
|
|
373
|
+
callback = jest.fn();
|
|
374
|
+
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
316
375
|
return [
|
|
317
376
|
4,
|
|
318
|
-
|
|
377
|
+
jest.advanceTimersByTimeAsync(699)
|
|
319
378
|
];
|
|
320
379
|
case 1:
|
|
321
380
|
_state.sent();
|
|
322
|
-
expect(
|
|
323
|
-
|
|
324
|
-
|
|
381
|
+
expect(callback).not.toHaveBeenCalled();
|
|
382
|
+
return [
|
|
383
|
+
4,
|
|
384
|
+
jest.advanceTimersByTimeAsync(1)
|
|
385
|
+
];
|
|
386
|
+
case 2:
|
|
387
|
+
_state.sent();
|
|
388
|
+
expect(callback).toHaveBeenCalled();
|
|
389
|
+
return [
|
|
390
|
+
4,
|
|
391
|
+
run
|
|
392
|
+
];
|
|
393
|
+
case 3:
|
|
394
|
+
_state.sent();
|
|
325
395
|
return [
|
|
326
396
|
2
|
|
327
397
|
];
|
|
328
398
|
}
|
|
329
399
|
});
|
|
330
|
-
}));
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
400
|
+
})();
|
|
401
|
+
});
|
|
402
|
+
it('should delay the response based on callback', function() {
|
|
403
|
+
return _async_to_generator(function() {
|
|
404
|
+
var plugin, loadedPlugin, callback, run;
|
|
405
|
+
return _ts_generator(this, function(_state) {
|
|
406
|
+
switch(_state.label){
|
|
407
|
+
case 0:
|
|
408
|
+
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
409
|
+
adapter: testMockAdapter,
|
|
410
|
+
delayTiming: function() {
|
|
411
|
+
return 800;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
loadedPlugin = plugin.load({
|
|
415
|
+
fetchPlugins: [],
|
|
416
|
+
url: '',
|
|
417
|
+
apiClient: apiClient,
|
|
418
|
+
options: {
|
|
419
|
+
headers: new Headers(_define_property({}, _mockinterceptinterface.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
callback = jest.fn();
|
|
423
|
+
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
424
|
+
return [
|
|
425
|
+
4,
|
|
426
|
+
jest.advanceTimersByTimeAsync(799)
|
|
427
|
+
];
|
|
428
|
+
case 1:
|
|
429
|
+
_state.sent();
|
|
430
|
+
expect(callback).not.toHaveBeenCalled();
|
|
431
|
+
return [
|
|
432
|
+
4,
|
|
433
|
+
jest.advanceTimersByTimeAsync(1)
|
|
434
|
+
];
|
|
435
|
+
case 2:
|
|
436
|
+
_state.sent();
|
|
437
|
+
expect(callback).toHaveBeenCalled();
|
|
438
|
+
return [
|
|
439
|
+
4,
|
|
440
|
+
run
|
|
441
|
+
];
|
|
442
|
+
case 3:
|
|
443
|
+
_state.sent();
|
|
444
|
+
return [
|
|
445
|
+
2
|
|
446
|
+
];
|
|
342
447
|
}
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
return plugin.load(config);
|
|
346
|
-
}).toThrow();
|
|
347
|
-
});
|
|
448
|
+
});
|
|
449
|
+
})();
|
|
348
450
|
});
|
|
349
451
|
});
|
|
350
|
-
describe('with delay', function() {
|
|
351
|
-
it('should delay the response of the specific number', /*#__PURE__*/ _async_to_generator(function() {
|
|
352
|
-
var plugin, loadedPlugin, callback, run;
|
|
353
|
-
return _ts_generator(this, function(_state) {
|
|
354
|
-
switch(_state.label){
|
|
355
|
-
case 0:
|
|
356
|
-
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
357
|
-
adapter: testMockAdapter,
|
|
358
|
-
delayTiming: 700
|
|
359
|
-
});
|
|
360
|
-
loadedPlugin = plugin.load({
|
|
361
|
-
fetchPlugins: [],
|
|
362
|
-
url: '',
|
|
363
|
-
apiClient: apiClient,
|
|
364
|
-
options: {
|
|
365
|
-
headers: new Headers(_define_property({}, _mockinterceptinterface.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
callback = jest.fn();
|
|
369
|
-
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
370
|
-
return [
|
|
371
|
-
4,
|
|
372
|
-
jest.advanceTimersByTimeAsync(699)
|
|
373
|
-
];
|
|
374
|
-
case 1:
|
|
375
|
-
_state.sent();
|
|
376
|
-
expect(callback).not.toHaveBeenCalled();
|
|
377
|
-
return [
|
|
378
|
-
4,
|
|
379
|
-
jest.advanceTimersByTimeAsync(1)
|
|
380
|
-
];
|
|
381
|
-
case 2:
|
|
382
|
-
_state.sent();
|
|
383
|
-
expect(callback).toHaveBeenCalled();
|
|
384
|
-
return [
|
|
385
|
-
4,
|
|
386
|
-
run
|
|
387
|
-
];
|
|
388
|
-
case 3:
|
|
389
|
-
_state.sent();
|
|
390
|
-
return [
|
|
391
|
-
2
|
|
392
|
-
];
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
}));
|
|
396
|
-
it('should delay the response based on callback', /*#__PURE__*/ _async_to_generator(function() {
|
|
397
|
-
var plugin, loadedPlugin, callback, run;
|
|
398
|
-
return _ts_generator(this, function(_state) {
|
|
399
|
-
switch(_state.label){
|
|
400
|
-
case 0:
|
|
401
|
-
plugin = new _mockinterceptfetch.MockInterceptFetch({
|
|
402
|
-
adapter: testMockAdapter,
|
|
403
|
-
delayTiming: function() {
|
|
404
|
-
return 800;
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
loadedPlugin = plugin.load({
|
|
408
|
-
fetchPlugins: [],
|
|
409
|
-
url: '',
|
|
410
|
-
apiClient: apiClient,
|
|
411
|
-
options: {
|
|
412
|
-
headers: new Headers(_define_property({}, _mockinterceptinterface.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
callback = jest.fn();
|
|
416
|
-
run = loadedPlugin.transform(Promise.resolve({})).then(callback);
|
|
417
|
-
return [
|
|
418
|
-
4,
|
|
419
|
-
jest.advanceTimersByTimeAsync(799)
|
|
420
|
-
];
|
|
421
|
-
case 1:
|
|
422
|
-
_state.sent();
|
|
423
|
-
expect(callback).not.toHaveBeenCalled();
|
|
424
|
-
return [
|
|
425
|
-
4,
|
|
426
|
-
jest.advanceTimersByTimeAsync(1)
|
|
427
|
-
];
|
|
428
|
-
case 2:
|
|
429
|
-
_state.sent();
|
|
430
|
-
expect(callback).toHaveBeenCalled();
|
|
431
|
-
return [
|
|
432
|
-
4,
|
|
433
|
-
run
|
|
434
|
-
];
|
|
435
|
-
case 3:
|
|
436
|
-
_state.sent();
|
|
437
|
-
return [
|
|
438
|
-
2
|
|
439
|
-
];
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
}));
|
|
443
|
-
});
|
|
444
452
|
});
|
|
@@ -117,7 +117,7 @@ function _object_spread_props(target, source) {
|
|
|
117
117
|
return target;
|
|
118
118
|
}
|
|
119
119
|
function _ts_generator(thisArg, body) {
|
|
120
|
-
var f, y, t,
|
|
120
|
+
var f, y, t, _ = {
|
|
121
121
|
label: 0,
|
|
122
122
|
sent: function() {
|
|
123
123
|
if (t[0] & 1) throw t[1];
|
|
@@ -125,12 +125,8 @@ function _ts_generator(thisArg, body) {
|
|
|
125
125
|
},
|
|
126
126
|
trys: [],
|
|
127
127
|
ops: []
|
|
128
|
-
};
|
|
129
|
-
return g = {
|
|
130
|
-
next: verb(0),
|
|
131
|
-
"throw": verb(1),
|
|
132
|
-
"return": verb(2)
|
|
133
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
128
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
129
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
134
130
|
return this;
|
|
135
131
|
}), g;
|
|
136
132
|
function verb(n) {
|
|
@@ -143,7 +139,7 @@ function _ts_generator(thisArg, body) {
|
|
|
143
139
|
}
|
|
144
140
|
function step(op) {
|
|
145
141
|
if (f) throw new TypeError("Generator is already executing.");
|
|
146
|
-
while(_)try {
|
|
142
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
147
143
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
148
144
|
if (y = 0, t) op = [
|
|
149
145
|
op[0] & 2,
|
|
@@ -329,13 +325,13 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
|
329
325
|
value: /** @inheritDoc */ function load(context) {
|
|
330
326
|
var _this = this;
|
|
331
327
|
return {
|
|
332
|
-
transform:
|
|
333
|
-
|
|
328
|
+
transform: function(fetchCall) {
|
|
329
|
+
return _async_to_generator(function() {
|
|
334
330
|
var markId, response, exception;
|
|
335
331
|
return _ts_generator(this, function(_state) {
|
|
336
332
|
switch(_state.label){
|
|
337
333
|
case 0:
|
|
338
|
-
markId =
|
|
334
|
+
markId = this.openMark(context.url, context.options);
|
|
339
335
|
_state.label = 1;
|
|
340
336
|
case 1:
|
|
341
337
|
_state.trys.push([
|
|
@@ -350,7 +346,7 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
|
350
346
|
];
|
|
351
347
|
case 2:
|
|
352
348
|
response = _state.sent();
|
|
353
|
-
|
|
349
|
+
this.closeMark(markId, response);
|
|
354
350
|
return [
|
|
355
351
|
2,
|
|
356
352
|
response
|
|
@@ -358,7 +354,7 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
|
358
354
|
case 3:
|
|
359
355
|
exception = _state.sent();
|
|
360
356
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access -- type is explicitly `any`
|
|
361
|
-
|
|
357
|
+
this.closeMarkWithError(markId, _instanceof(exception, Error) ? exception : new Error(exception.toString()));
|
|
362
358
|
throw exception;
|
|
363
359
|
case 4:
|
|
364
360
|
return [
|
|
@@ -366,11 +362,8 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
|
366
362
|
];
|
|
367
363
|
}
|
|
368
364
|
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
return _ref.apply(this, arguments);
|
|
372
|
-
};
|
|
373
|
-
}()
|
|
365
|
+
}).call(_this);
|
|
366
|
+
}
|
|
374
367
|
};
|
|
375
368
|
}
|
|
376
369
|
}
|