@wutiange/log-listener-plugin 2.0.1 → 2.0.2-alpha.2
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/README.md +166 -163
- package/dist/index.cjs.js +7 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +34 -2
- package/dist/index.esm.js +5 -0
- package/dist/index.esm.js.map +1 -0
- package/index.ts +3 -3
- package/package.json +52 -59
- package/src/HTTPInterceptor.ts +340 -340
- package/src/Server.ts +174 -178
- package/src/__mocks__/react-native/Libraries/Blob/FileReader.js +44 -44
- package/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +39 -39
- package/src/__tests__/HTTPInterceptor.test.ts +322 -322
- package/src/__tests__/Server.test.ts +150 -150
- package/src/__tests__/utils.test.ts +114 -114
- package/src/common.ts +57 -57
- package/src/logPlugin.ts +238 -231
- package/src/logger.ts +15 -15
- package/src/utils.ts +135 -112
- package/LICENSE +0 -201
- package/dist/console.d.ts +0 -1
- package/dist/console.js +0 -20
- package/dist/console.js.map +0 -1
- package/dist/fetch.d.ts +0 -1
- package/dist/fetch.js +0 -48
- package/dist/fetch.js.map +0 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -1
- package/dist/src/HTTPInterceptor.d.ts +0 -50
- package/dist/src/HTTPInterceptor.js +0 -227
- package/dist/src/HTTPInterceptor.js.map +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.d.ts +0 -14
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js +0 -41
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js.map +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.d.ts +0 -17
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +0 -34
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js.map +0 -1
- package/dist/src/__tests__/HTTPInterceptor.test.d.ts +0 -9
- package/dist/src/__tests__/HTTPInterceptor.test.js +0 -281
- package/dist/src/__tests__/HTTPInterceptor.test.js.map +0 -1
- package/dist/src/__tests__/Server.test.d.ts +0 -1
- package/dist/src/__tests__/Server.test.js +0 -116
- package/dist/src/__tests__/Server.test.js.map +0 -1
- package/dist/src/__tests__/console.test.d.ts +0 -1
- package/dist/src/__tests__/console.test.js +0 -29
- package/dist/src/__tests__/console.test.js.map +0 -1
- package/dist/src/__tests__/utils.test.d.ts +0 -1
- package/dist/src/__tests__/utils.test.js +0 -112
- package/dist/src/__tests__/utils.test.js.map +0 -1
- package/dist/src/common.d.ts +0 -14
- package/dist/src/common.js +0 -54
- package/dist/src/common.js.map +0 -1
- package/dist/src/logPlugin.d.ts +0 -35
- package/dist/src/logPlugin.js +0 -188
- package/dist/src/logPlugin.js.map +0 -1
- package/dist/src/logger.d.ts +0 -6
- package/dist/src/logger.js +0 -16
- package/dist/src/logger.js.map +0 -1
- package/dist/src/server.d.ts +0 -21
- package/dist/src/server.js +0 -178
- package/dist/src/server.js.map +0 -1
- package/dist/src/utils.d.ts +0 -6
- package/dist/src/utils.js +0 -106
- package/dist/src/utils.js.map +0 -1
- package/tsconfig.json +0 -27
@@ -1,227 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.httpInterceptor = void 0;
|
16
|
-
const XHRInterceptor_1 = __importDefault(require("react-native/Libraries/Network/XHRInterceptor"));
|
17
|
-
const FileReader_1 = __importDefault(require("react-native/Libraries/Blob/FileReader"));
|
18
|
-
const utils_1 = require("./utils");
|
19
|
-
const logger_1 = __importDefault(require("./logger"));
|
20
|
-
const extractHost = (url) => {
|
21
|
-
var _a, _b;
|
22
|
-
const host = ((_b = (_a = url.split('//')[1]) === null || _a === void 0 ? void 0 : _a.split(':')[0]) === null || _b === void 0 ? void 0 : _b.split('/')[0]) || undefined;
|
23
|
-
return host;
|
24
|
-
};
|
25
|
-
const generateUniqueId = () => {
|
26
|
-
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
27
|
-
};
|
28
|
-
const parseResponseBlob = (response) => __awaiter(void 0, void 0, void 0, function* () {
|
29
|
-
const blobReader = new FileReader_1.default();
|
30
|
-
blobReader.readAsText(response);
|
31
|
-
return yield new Promise((resolve, reject) => {
|
32
|
-
const handleError = () => reject(blobReader.error);
|
33
|
-
blobReader.addEventListener('load', () => {
|
34
|
-
resolve(blobReader.result);
|
35
|
-
});
|
36
|
-
blobReader.addEventListener('error', handleError);
|
37
|
-
blobReader.addEventListener('abort', handleError);
|
38
|
-
});
|
39
|
-
});
|
40
|
-
const getResponseBody = (responseType, response) => __awaiter(void 0, void 0, void 0, function* () {
|
41
|
-
try {
|
42
|
-
if (responseType === 'blob' && response) {
|
43
|
-
return yield parseResponseBlob(response);
|
44
|
-
}
|
45
|
-
return response !== null && response !== void 0 ? response : null;
|
46
|
-
}
|
47
|
-
catch (error) {
|
48
|
-
logger_1.default.warn("getResponseBody---error---", error);
|
49
|
-
return null;
|
50
|
-
}
|
51
|
-
});
|
52
|
-
class HTTPInterceptor {
|
53
|
-
constructor() {
|
54
|
-
this.allRequests = new Map();
|
55
|
-
this.userListeners = [];
|
56
|
-
this.enabled = false;
|
57
|
-
this.addListener = (eventName, listener) => {
|
58
|
-
if (this.userListeners.find(([name, tempListener]) => name === eventName && tempListener === listener)) {
|
59
|
-
return;
|
60
|
-
}
|
61
|
-
this.userListeners.push([eventName, listener]);
|
62
|
-
return () => {
|
63
|
-
this.userListeners = this.userListeners.filter(([name, tempListener]) => name !== eventName || tempListener !== listener);
|
64
|
-
};
|
65
|
-
};
|
66
|
-
this.removeListener = (eventName, listener) => {
|
67
|
-
this.userListeners = this.userListeners.filter(([name, tempListener]) => name !== eventName || tempListener !== listener);
|
68
|
-
};
|
69
|
-
this.listenerHandle = (eventName, data) => {
|
70
|
-
this.userListeners.forEach((_a) => __awaiter(this, [_a], void 0, function* ([name, listener]) {
|
71
|
-
try {
|
72
|
-
if (name === eventName) {
|
73
|
-
yield listener(data);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
catch (error) {
|
77
|
-
console.warn(`eventName=${eventName}, error=${error === null || error === void 0 ? void 0 : error.message}`);
|
78
|
-
}
|
79
|
-
}));
|
80
|
-
};
|
81
|
-
this.openHandle = (method, url, xhr) => {
|
82
|
-
if (this.ignoredHosts) {
|
83
|
-
const host = extractHost(url);
|
84
|
-
if (host && this.ignoredHosts.has(host)) {
|
85
|
-
return;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
if (this.ignoredUrls && this.ignoredUrls.has(url)) {
|
89
|
-
return;
|
90
|
-
}
|
91
|
-
if (this.ignoredPatterns) {
|
92
|
-
if (this.ignoredPatterns.some(pattern => pattern.test(`${method} ${url}`))) {
|
93
|
-
return;
|
94
|
-
}
|
95
|
-
}
|
96
|
-
xhr.uniqueId = HTTPInterceptor._index + generateUniqueId();
|
97
|
-
const newRequest = {
|
98
|
-
id: xhr.uniqueId,
|
99
|
-
method,
|
100
|
-
url,
|
101
|
-
};
|
102
|
-
this.allRequests.set(xhr.uniqueId, newRequest);
|
103
|
-
this.listenerHandle('open', newRequest);
|
104
|
-
};
|
105
|
-
this.requestHeaderHandle = (header, value, xhr) => {
|
106
|
-
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
107
|
-
if (!currentRequest) {
|
108
|
-
return;
|
109
|
-
}
|
110
|
-
if (!currentRequest.requestHeaders) {
|
111
|
-
currentRequest.requestHeaders = {};
|
112
|
-
}
|
113
|
-
currentRequest.requestHeaders[header] = value;
|
114
|
-
this.listenerHandle('requestHeader', currentRequest);
|
115
|
-
};
|
116
|
-
this.headerReceivedHandle = (responseContentType, responseSize, responseHeaders, xhr) => {
|
117
|
-
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
118
|
-
if (!currentRequest) {
|
119
|
-
return;
|
120
|
-
}
|
121
|
-
currentRequest.responseContentType = responseContentType;
|
122
|
-
currentRequest.responseSize = responseSize;
|
123
|
-
currentRequest.responseHeaders = xhr.responseHeaders;
|
124
|
-
this.listenerHandle('headerReceived', currentRequest);
|
125
|
-
};
|
126
|
-
this.responseHandle = (status, timeout, response, responseURL, responseType, xhr) => __awaiter(this, void 0, void 0, function* () {
|
127
|
-
var _a;
|
128
|
-
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
129
|
-
if (!currentRequest) {
|
130
|
-
return;
|
131
|
-
}
|
132
|
-
currentRequest.endTime = Date.now();
|
133
|
-
currentRequest.status = status;
|
134
|
-
currentRequest.timeout = timeout;
|
135
|
-
currentRequest.responseData = yield getResponseBody(responseType, response);
|
136
|
-
currentRequest.responseURL = responseURL;
|
137
|
-
currentRequest.responseType = responseType;
|
138
|
-
currentRequest.duration =
|
139
|
-
currentRequest.endTime - ((_a = currentRequest.startTime) !== null && _a !== void 0 ? _a : 0);
|
140
|
-
this.listenerHandle('response', currentRequest);
|
141
|
-
this.allRequests.delete(xhr.uniqueId);
|
142
|
-
});
|
143
|
-
this.sendHandle = (data, xhr) => {
|
144
|
-
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
145
|
-
if (!currentRequest) {
|
146
|
-
return;
|
147
|
-
}
|
148
|
-
try {
|
149
|
-
if (data && typeof data === 'object' && data instanceof FormData) {
|
150
|
-
currentRequest.requestData = (0, utils_1.formDataToString)(data);
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
currentRequest.requestData = JSON.parse(data);
|
154
|
-
}
|
155
|
-
}
|
156
|
-
catch (error) {
|
157
|
-
currentRequest.requestData = null;
|
158
|
-
}
|
159
|
-
currentRequest.startTime = Date.now();
|
160
|
-
this.listenerHandle('send', currentRequest);
|
161
|
-
};
|
162
|
-
this.setIgnoredUrls = (ignoredUrls) => {
|
163
|
-
if (ignoredUrls === null || ignoredUrls === void 0 ? void 0 : ignoredUrls.length) {
|
164
|
-
if (!Array.isArray(ignoredUrls) ||
|
165
|
-
typeof ignoredUrls[0] !== 'string') {
|
166
|
-
console.warn('ignoredUrls must be an array of strings. The logger has not been started.');
|
167
|
-
return;
|
168
|
-
}
|
169
|
-
this.ignoredUrls = new Set(ignoredUrls);
|
170
|
-
}
|
171
|
-
};
|
172
|
-
this.enable = (options) => {
|
173
|
-
try {
|
174
|
-
if (this.enabled ||
|
175
|
-
(XHRInterceptor_1.default.isInterceptorEnabled() && !(options === null || options === void 0 ? void 0 : options.forceEnable))) {
|
176
|
-
if (!this.enabled) {
|
177
|
-
console.warn('network interceptor has not been enabled as another interceptor is already running (e.g. another debugging program). Use option `forceEnable: true` to override this behaviour.');
|
178
|
-
}
|
179
|
-
return;
|
180
|
-
}
|
181
|
-
if (options === null || options === void 0 ? void 0 : options.ignoredHosts) {
|
182
|
-
if (!Array.isArray(options.ignoredHosts) ||
|
183
|
-
typeof options.ignoredHosts[0] !== 'string') {
|
184
|
-
console.warn('ignoredHosts must be an array of strings. The logger has not been started.');
|
185
|
-
return;
|
186
|
-
}
|
187
|
-
this.ignoredHosts = new Set(options.ignoredHosts);
|
188
|
-
}
|
189
|
-
if (options === null || options === void 0 ? void 0 : options.ignoredPatterns) {
|
190
|
-
this.ignoredPatterns = options.ignoredPatterns;
|
191
|
-
}
|
192
|
-
this.setIgnoredUrls(options === null || options === void 0 ? void 0 : options.ignoredUrls);
|
193
|
-
XHRInterceptor_1.default.setOpenCallback(this.openHandle);
|
194
|
-
XHRInterceptor_1.default.setRequestHeaderCallback(this.requestHeaderHandle);
|
195
|
-
XHRInterceptor_1.default.setHeaderReceivedCallback(this.headerReceivedHandle);
|
196
|
-
XHRInterceptor_1.default.setSendCallback(this.sendHandle);
|
197
|
-
XHRInterceptor_1.default.setResponseCallback(this.responseHandle);
|
198
|
-
XHRInterceptor_1.default.enableInterception();
|
199
|
-
this.enabled = true;
|
200
|
-
}
|
201
|
-
catch (error) { }
|
202
|
-
};
|
203
|
-
this.disable = () => {
|
204
|
-
if (!this.enabled) {
|
205
|
-
return;
|
206
|
-
}
|
207
|
-
XHRInterceptor_1.default.disableInterception();
|
208
|
-
this.enabled = false;
|
209
|
-
};
|
210
|
-
this.reset = () => {
|
211
|
-
this.disable();
|
212
|
-
this.removeAllListener();
|
213
|
-
this.ignoredHosts = undefined;
|
214
|
-
this.ignoredUrls = undefined;
|
215
|
-
this.ignoredPatterns = undefined;
|
216
|
-
this.allRequests.clear();
|
217
|
-
};
|
218
|
-
}
|
219
|
-
removeAllListener() {
|
220
|
-
this.userListeners = [];
|
221
|
-
}
|
222
|
-
}
|
223
|
-
HTTPInterceptor._index = 0;
|
224
|
-
const SafeHTTPInterceptor = (0, utils_1.createClassWithErrorHandling)(HTTPInterceptor);
|
225
|
-
const httpInterceptor = new SafeHTTPInterceptor();
|
226
|
-
exports.httpInterceptor = httpInterceptor;
|
227
|
-
//# sourceMappingURL=HTTPInterceptor.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"HTTPInterceptor.js","sourceRoot":"","sources":["../../src/HTTPInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mGAA2E;AAC3E,wFAAoE;AAEpE,mCAAyE;AACzE,sDAA8B;AAqD9B,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE;;IAClC,MAAM,IAAI,GAAG,CAAA,MAAA,MAAA,GAAG,CAAC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AW,CAAC,KAAK,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;IA7LC,iBAAiB;QACf,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;;AAhDc,sBAAM,GAAG,CAAC,AAAJ,CAAK;AA6O5B,MAAM,mBAAmB,GAAG,IAAA,oCAA4B,EAAC,eAAe,CAAC,CAAA;AACzE,MAAM,eAAe,GAAG,IAAI,mBAAmB,EAAE,CAAC;AAGhD,0CAAe"}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
export = FileReader;
|
2
|
-
declare class FileReader {
|
3
|
-
static EMPTY: number;
|
4
|
-
static LOADING: number;
|
5
|
-
static DONE: number;
|
6
|
-
result: any;
|
7
|
-
error: any;
|
8
|
-
readyState: number;
|
9
|
-
addEventListener(event: any, callback: any): void;
|
10
|
-
removeEventListener(event: any, callback: any): void;
|
11
|
-
readAsText(blob: any): void;
|
12
|
-
readAsArrayBuffer(blob: any): void;
|
13
|
-
_read(blob: any, resultType: any): void;
|
14
|
-
}
|
@@ -1,41 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
class FileReader {
|
3
|
-
constructor() {
|
4
|
-
this.result = null;
|
5
|
-
this.error = null;
|
6
|
-
this.readyState = FileReader.EMPTY;
|
7
|
-
}
|
8
|
-
addEventListener(event, callback) {
|
9
|
-
this[`on${event}`] = callback;
|
10
|
-
}
|
11
|
-
removeEventListener(event, callback) {
|
12
|
-
if (this[`on${event}`] === callback) {
|
13
|
-
this[`on${event}`] = null;
|
14
|
-
}
|
15
|
-
}
|
16
|
-
readAsText(blob) {
|
17
|
-
this._read(blob, 'text');
|
18
|
-
}
|
19
|
-
readAsArrayBuffer(blob) {
|
20
|
-
this._read(blob, 'arraybuffer');
|
21
|
-
}
|
22
|
-
_read(blob, resultType) {
|
23
|
-
this.readyState = FileReader.LOADING;
|
24
|
-
setTimeout(() => {
|
25
|
-
this.readyState = FileReader.DONE;
|
26
|
-
if (resultType === 'text') {
|
27
|
-
this.result = blob.text();
|
28
|
-
}
|
29
|
-
else if (resultType === 'arraybuffer') {
|
30
|
-
this.result = new ArrayBuffer(0);
|
31
|
-
}
|
32
|
-
if (this.onload)
|
33
|
-
this.onload({ target: this });
|
34
|
-
}, 0);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
FileReader.EMPTY = 0;
|
38
|
-
FileReader.LOADING = 1;
|
39
|
-
FileReader.DONE = 2;
|
40
|
-
module.exports = FileReader;
|
41
|
-
//# sourceMappingURL=FileReader.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"FileReader.js","sourceRoot":"","sources":["../../../../../../src/__mocks__/react-native/Libraries/Blob/FileReader.js"],"names":[],"mappings":";AAAA,MAAM,UAAU;IACd;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC;IACrC,CAAC;IAMD,gBAAgB,CAAC,KAAK,EAAE,QAAQ;QAC9B,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC;IAChC,CAAC;IAED,mBAAmB,CAAC,KAAK,EAAE,QAAQ;QACjC,IAAI,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK,QAAQ,EAAE,CAAC;YACpC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,UAAU,CAAC,IAAI;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC;IAED,iBAAiB,CAAC,IAAI;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,IAAI,EAAE,UAAU;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC;QACrC,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC;YAClC,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;gBAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,CAAC;iBAAM,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;gBAExC,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;YACnC,CAAC;YACD,IAAI,IAAI,CAAC,MAAM;gBAAE,IAAI,CAAC,MAAM,CAAC,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;QAC/C,CAAC,EAAE,CAAC,CAAC,CAAC;IACR,CAAC;;AAlCM,gBAAK,GAAG,CAAC,CAAC;AACV,kBAAO,GAAG,CAAC,CAAC;AACZ,eAAI,GAAG,CAAC,CAAC;AAmClB,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
export = XHRInterceptor;
|
2
|
-
declare class XHRInterceptor {
|
3
|
-
static _isInterceptorEnabled: boolean;
|
4
|
-
static openCallback: any;
|
5
|
-
static requestHeaderCallback: any;
|
6
|
-
static headerReceivedCallback: any;
|
7
|
-
static sendCallback: any;
|
8
|
-
static responseCallback: any;
|
9
|
-
static setOpenCallback: jest.Mock<void, [callback?: any], any>;
|
10
|
-
static setRequestHeaderCallback: jest.Mock<void, [callback?: any], any>;
|
11
|
-
static setHeaderReceivedCallback: jest.Mock<void, [callback?: any], any>;
|
12
|
-
static setSendCallback: jest.Mock<void, [callback?: any], any>;
|
13
|
-
static setResponseCallback: jest.Mock<void, [callback?: any], any>;
|
14
|
-
static enableInterception: jest.Mock<void, [], any>;
|
15
|
-
static disableInterception: jest.Mock<void, [], any>;
|
16
|
-
static isInterceptorEnabled: jest.Mock<boolean, [], any>;
|
17
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
class XHRInterceptor {
|
3
|
-
}
|
4
|
-
XHRInterceptor._isInterceptorEnabled = false;
|
5
|
-
XHRInterceptor.openCallback = null;
|
6
|
-
XHRInterceptor.requestHeaderCallback = null;
|
7
|
-
XHRInterceptor.headerReceivedCallback = null;
|
8
|
-
XHRInterceptor.sendCallback = null;
|
9
|
-
XHRInterceptor.responseCallback = null;
|
10
|
-
XHRInterceptor.setOpenCallback = jest.fn((callback) => {
|
11
|
-
XHRInterceptor.openCallback = callback;
|
12
|
-
});
|
13
|
-
XHRInterceptor.setRequestHeaderCallback = jest.fn((callback) => {
|
14
|
-
XHRInterceptor.requestHeaderCallback = callback;
|
15
|
-
});
|
16
|
-
XHRInterceptor.setHeaderReceivedCallback = jest.fn((callback) => {
|
17
|
-
XHRInterceptor.headerReceivedCallback = callback;
|
18
|
-
});
|
19
|
-
XHRInterceptor.setSendCallback = jest.fn((callback) => {
|
20
|
-
XHRInterceptor.sendCallback = callback;
|
21
|
-
});
|
22
|
-
XHRInterceptor.setResponseCallback = jest.fn((callback) => {
|
23
|
-
XHRInterceptor.responseCallback = callback;
|
24
|
-
});
|
25
|
-
XHRInterceptor.enableInterception = jest.fn(() => {
|
26
|
-
XHRInterceptor._isInterceptorEnabled = true;
|
27
|
-
});
|
28
|
-
XHRInterceptor.disableInterception = jest.fn(() => {
|
29
|
-
XHRInterceptor._isInterceptorEnabled = false;
|
30
|
-
});
|
31
|
-
XHRInterceptor.isInterceptorEnabled = jest.fn(() => XHRInterceptor._isInterceptorEnabled);
|
32
|
-
;
|
33
|
-
module.exports = XHRInterceptor;
|
34
|
-
//# sourceMappingURL=XHRInterceptor.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"XHRInterceptor.js","sourceRoot":"","sources":["../../../../../../src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js"],"names":[],"mappings":";AAEA,MAAM,cAAc;;AACX,oCAAqB,GAAG,KAAK,CAAA;AAC7B,2BAAY,GAAG,IAAI,CAAA;AACnB,oCAAqB,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
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const HTTPInterceptor_1 = require("../HTTPInterceptor");
|
16
|
-
const XHRInterceptor_1 = __importDefault(require("react-native/Libraries/Network/XHRInterceptor"));
|
17
|
-
const utils_1 = require("../utils");
|
18
|
-
jest.mock('buffer', () => ({
|
19
|
-
Blob: jest.fn(),
|
20
|
-
}));
|
21
|
-
jest.mock('../utils', () => ({
|
22
|
-
createClassWithErrorHandling: jest.fn(Class => Class),
|
23
|
-
formDataToString: jest.fn(),
|
24
|
-
}));
|
25
|
-
class MockFormData {
|
26
|
-
constructor() {
|
27
|
-
this.data = {};
|
28
|
-
}
|
29
|
-
append(key, value) {
|
30
|
-
this.data[key] = value;
|
31
|
-
}
|
32
|
-
get(key) {
|
33
|
-
return this.data[key];
|
34
|
-
}
|
35
|
-
}
|
36
|
-
class MockBlob {
|
37
|
-
constructor(parts, options = {}) {
|
38
|
-
this.content = parts ? parts.join('') : '';
|
39
|
-
this.type = options.type || '';
|
40
|
-
}
|
41
|
-
text() {
|
42
|
-
return Promise.resolve(this.content);
|
43
|
-
}
|
44
|
-
arrayBuffer() {
|
45
|
-
return Promise.resolve(new ArrayBuffer(0));
|
46
|
-
}
|
47
|
-
}
|
48
|
-
beforeAll(() => {
|
49
|
-
global.FormData = MockFormData;
|
50
|
-
});
|
51
|
-
afterAll(() => {
|
52
|
-
delete global.FormData;
|
53
|
-
});
|
54
|
-
describe('HTTPInterceptor', () => {
|
55
|
-
beforeEach(() => {
|
56
|
-
jest.clearAllMocks();
|
57
|
-
console.warn = jest.fn();
|
58
|
-
HTTPInterceptor_1.httpInterceptor.reset();
|
59
|
-
XHRInterceptor_1.default.isInterceptorEnabled.mockReturnValue(false);
|
60
|
-
});
|
61
|
-
describe('enable', () => {
|
62
|
-
it('should enable interception', () => {
|
63
|
-
HTTPInterceptor_1.httpInterceptor.enable();
|
64
|
-
expect(XHRInterceptor_1.default.enableInterception).toHaveBeenCalled();
|
65
|
-
});
|
66
|
-
it('should not enable if already enabled', () => {
|
67
|
-
HTTPInterceptor_1.httpInterceptor.enable();
|
68
|
-
HTTPInterceptor_1.httpInterceptor.enable();
|
69
|
-
expect(XHRInterceptor_1.default.enableInterception).toHaveBeenCalledTimes(1);
|
70
|
-
});
|
71
|
-
it('should handle ignored hosts', () => {
|
72
|
-
HTTPInterceptor_1.httpInterceptor.enable({ ignoredHosts: ['example.com'] });
|
73
|
-
expect(XHRInterceptor_1.default.enableInterception).toHaveBeenCalled();
|
74
|
-
});
|
75
|
-
it('should handle ignored patterns', () => {
|
76
|
-
HTTPInterceptor_1.httpInterceptor.enable({ ignoredPatterns: [/^GET https:\/\/test\.com/] });
|
77
|
-
expect(XHRInterceptor_1.default.enableInterception).toHaveBeenCalled();
|
78
|
-
});
|
79
|
-
it('should handle ignored URLs', () => {
|
80
|
-
HTTPInterceptor_1.httpInterceptor.enable({ ignoredUrls: ['https://example.com/api'] });
|
81
|
-
expect(XHRInterceptor_1.default.enableInterception).toHaveBeenCalled();
|
82
|
-
});
|
83
|
-
it('should warn if another interceptor is running', () => {
|
84
|
-
XHRInterceptor_1.default.isInterceptorEnabled.mockReturnValue(true);
|
85
|
-
console.warn = jest.fn();
|
86
|
-
HTTPInterceptor_1.httpInterceptor.enable();
|
87
|
-
expect(console.warn).toHaveBeenCalled();
|
88
|
-
});
|
89
|
-
it('should force enable if specified', () => {
|
90
|
-
XHRInterceptor_1.default.isInterceptorEnabled.mockReturnValue(true);
|
91
|
-
HTTPInterceptor_1.httpInterceptor.enable({ forceEnable: true });
|
92
|
-
expect(XHRInterceptor_1.default.enableInterception).toHaveBeenCalled();
|
93
|
-
});
|
94
|
-
});
|
95
|
-
describe('disable', () => {
|
96
|
-
it('should disable interception', () => {
|
97
|
-
HTTPInterceptor_1.httpInterceptor.enable();
|
98
|
-
HTTPInterceptor_1.httpInterceptor.disable();
|
99
|
-
expect(XHRInterceptor_1.default.disableInterception).toHaveBeenCalled();
|
100
|
-
});
|
101
|
-
it('should not disable if not enabled', () => {
|
102
|
-
HTTPInterceptor_1.httpInterceptor.disable();
|
103
|
-
expect(XHRInterceptor_1.default.disableInterception).not.toHaveBeenCalled();
|
104
|
-
});
|
105
|
-
});
|
106
|
-
describe('listeners', () => {
|
107
|
-
it('should add and remove listeners', () => {
|
108
|
-
const listener = jest.fn();
|
109
|
-
const removeListener = HTTPInterceptor_1.httpInterceptor.addListener('open', listener);
|
110
|
-
expect(HTTPInterceptor_1.httpInterceptor['userListeners'].length).toBe(1);
|
111
|
-
removeListener();
|
112
|
-
expect(HTTPInterceptor_1.httpInterceptor['userListeners'].length).toBe(0);
|
113
|
-
});
|
114
|
-
it('should not add duplicate listeners', () => {
|
115
|
-
const listener = jest.fn();
|
116
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener);
|
117
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener);
|
118
|
-
expect(HTTPInterceptor_1.httpInterceptor['userListeners'].length).toBe(1);
|
119
|
-
});
|
120
|
-
it('should remove specific listener', () => {
|
121
|
-
const listener1 = jest.fn();
|
122
|
-
const listener2 = jest.fn();
|
123
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener1);
|
124
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener2);
|
125
|
-
HTTPInterceptor_1.httpInterceptor.removeListener('open', listener1);
|
126
|
-
expect(HTTPInterceptor_1.httpInterceptor['userListeners'].length).toBe(1);
|
127
|
-
expect(HTTPInterceptor_1.httpInterceptor['userListeners'][0][1]).toBe(listener2);
|
128
|
-
});
|
129
|
-
it('should remove all listeners', () => {
|
130
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', jest.fn());
|
131
|
-
HTTPInterceptor_1.httpInterceptor.addListener('send', jest.fn());
|
132
|
-
HTTPInterceptor_1.httpInterceptor.removeAllListener();
|
133
|
-
expect(HTTPInterceptor_1.httpInterceptor['userListeners'].length).toBe(0);
|
134
|
-
});
|
135
|
-
});
|
136
|
-
describe('request handling', () => {
|
137
|
-
let openCallback;
|
138
|
-
let requestHeaderCallback;
|
139
|
-
let headerReceivedCallback;
|
140
|
-
let sendCallback;
|
141
|
-
let responseCallback;
|
142
|
-
beforeEach(() => {
|
143
|
-
HTTPInterceptor_1.httpInterceptor.enable();
|
144
|
-
openCallback = XHRInterceptor_1.default.setOpenCallback.mock.calls[0][0];
|
145
|
-
requestHeaderCallback = XHRInterceptor_1.default.setRequestHeaderCallback.mock.calls[0][0];
|
146
|
-
headerReceivedCallback = XHRInterceptor_1.default.setHeaderReceivedCallback.mock.calls[0][0];
|
147
|
-
sendCallback = XHRInterceptor_1.default.setSendCallback.mock.calls[0][0];
|
148
|
-
responseCallback = XHRInterceptor_1.default.setResponseCallback.mock.calls[0][0];
|
149
|
-
});
|
150
|
-
it('should handle open event', () => {
|
151
|
-
const listener = jest.fn();
|
152
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener);
|
153
|
-
const xhr = {};
|
154
|
-
openCallback('GET', 'https://example.com', xhr);
|
155
|
-
expect(listener).toHaveBeenCalledWith(expect.objectContaining({
|
156
|
-
method: 'GET',
|
157
|
-
url: 'https://example.com',
|
158
|
-
}));
|
159
|
-
});
|
160
|
-
it('should handle request header event', () => {
|
161
|
-
const listener = jest.fn();
|
162
|
-
HTTPInterceptor_1.httpInterceptor.addListener('requestHeader', listener);
|
163
|
-
const xhr = {};
|
164
|
-
openCallback('GET', 'https://example.com', xhr);
|
165
|
-
requestHeaderCallback('Content-Type', 'application/json', xhr);
|
166
|
-
expect(listener).toHaveBeenCalledWith(expect.objectContaining({
|
167
|
-
requestHeaders: { 'Content-Type': 'application/json' },
|
168
|
-
}));
|
169
|
-
});
|
170
|
-
it('should handle header received event', () => {
|
171
|
-
const listener = jest.fn();
|
172
|
-
HTTPInterceptor_1.httpInterceptor.addListener('headerReceived', listener);
|
173
|
-
const xhr = {};
|
174
|
-
openCallback('GET', 'https://example.com', xhr);
|
175
|
-
xhr.responseHeaders = { 'Content-Type': 'application/json' };
|
176
|
-
headerReceivedCallback('application/json', 100, {}, xhr);
|
177
|
-
expect(listener).toHaveBeenCalledWith(expect.objectContaining({
|
178
|
-
responseContentType: 'application/json',
|
179
|
-
responseSize: 100,
|
180
|
-
responseHeaders: { 'Content-Type': 'application/json' },
|
181
|
-
}));
|
182
|
-
});
|
183
|
-
it('should handle send event with JSON data', () => {
|
184
|
-
const listener = jest.fn();
|
185
|
-
HTTPInterceptor_1.httpInterceptor.addListener('send', listener);
|
186
|
-
const xhr = {};
|
187
|
-
openCallback('POST', 'https://example.com', xhr);
|
188
|
-
sendCallback(JSON.stringify({ key: 'value' }), xhr);
|
189
|
-
expect(listener).toHaveBeenCalledWith(expect.objectContaining({
|
190
|
-
requestData: { key: 'value' },
|
191
|
-
}));
|
192
|
-
});
|
193
|
-
it('should handle send event with FormData', () => {
|
194
|
-
const listener = jest.fn();
|
195
|
-
HTTPInterceptor_1.httpInterceptor.addListener('send', listener);
|
196
|
-
const xhr = {};
|
197
|
-
openCallback('POST', 'https://example.com', xhr);
|
198
|
-
const formData = new FormData();
|
199
|
-
formData.append('key', 'value');
|
200
|
-
utils_1.formDataToString.mockReturnValue('key=value');
|
201
|
-
sendCallback(formData, xhr);
|
202
|
-
expect(listener).toHaveBeenCalledWith(expect.objectContaining({
|
203
|
-
requestData: 'key=value',
|
204
|
-
}));
|
205
|
-
});
|
206
|
-
it('should handle response event', () => __awaiter(void 0, void 0, void 0, function* () {
|
207
|
-
const listener = jest.fn();
|
208
|
-
HTTPInterceptor_1.httpInterceptor.addListener('response', listener);
|
209
|
-
const xhr = {};
|
210
|
-
openCallback('GET', 'https://example.com', xhr);
|
211
|
-
yield responseCallback(200, 1000, { data: 'response' }, 'https://example.com', 'json', xhr);
|
212
|
-
expect(listener).toHaveBeenCalledWith(expect.objectContaining({
|
213
|
-
status: 200,
|
214
|
-
timeout: 1000,
|
215
|
-
responseData: { data: 'response' },
|
216
|
-
responseURL: 'https://example.com',
|
217
|
-
responseType: 'json',
|
218
|
-
}));
|
219
|
-
}));
|
220
|
-
it('should handle response event with blob data', () => __awaiter(void 0, void 0, void 0, function* () {
|
221
|
-
const listener = jest.fn();
|
222
|
-
HTTPInterceptor_1.httpInterceptor.addListener('response', listener);
|
223
|
-
const xhr = {};
|
224
|
-
openCallback('GET', 'https://example.com', xhr);
|
225
|
-
const mockBlob = new MockBlob(['blob content']);
|
226
|
-
yield responseCallback(200, 1000, mockBlob, 'https://example.com', 'blob', xhr);
|
227
|
-
expect(listener).toHaveBeenCalledWith(expect.objectContaining({
|
228
|
-
responseData: 'blob content',
|
229
|
-
}));
|
230
|
-
}));
|
231
|
-
});
|
232
|
-
describe('error handling', () => {
|
233
|
-
beforeEach(() => {
|
234
|
-
HTTPInterceptor_1.httpInterceptor.enable();
|
235
|
-
});
|
236
|
-
it('should handle errors in listeners', () => __awaiter(void 0, void 0, void 0, function* () {
|
237
|
-
const errorListener = jest.fn(() => {
|
238
|
-
throw new Error('Listener error');
|
239
|
-
});
|
240
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', errorListener);
|
241
|
-
console.warn = jest.fn();
|
242
|
-
const xhr = {};
|
243
|
-
const openCallback = XHRInterceptor_1.default.setOpenCallback.mock.calls[0][0];
|
244
|
-
openCallback('GET', 'https://example.com', xhr);
|
245
|
-
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining('Listener error'));
|
246
|
-
}));
|
247
|
-
});
|
248
|
-
describe('ignored requests', () => {
|
249
|
-
it('should ignore requests to ignored hosts', () => {
|
250
|
-
HTTPInterceptor_1.httpInterceptor.enable({ ignoredHosts: ['ignored.com'] });
|
251
|
-
const openCallback = XHRInterceptor_1.default.setOpenCallback.mock.calls[0][0];
|
252
|
-
const listener = jest.fn();
|
253
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener);
|
254
|
-
openCallback('GET', 'https://ignored.com', { uniqueId: '123' });
|
255
|
-
expect(listener).not.toHaveBeenCalled();
|
256
|
-
openCallback('GET', 'https://example.com', { uniqueId: '124' });
|
257
|
-
expect(listener).toHaveBeenCalled();
|
258
|
-
});
|
259
|
-
it('should ignore requests to ignored URLs', () => {
|
260
|
-
HTTPInterceptor_1.httpInterceptor.enable({ ignoredUrls: ['https://example.com/ignored'] });
|
261
|
-
const openCallback = XHRInterceptor_1.default.setOpenCallback.mock.calls[0][0];
|
262
|
-
const listener = jest.fn();
|
263
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener);
|
264
|
-
openCallback('GET', 'https://example.com/ignored', { uniqueId: '123' });
|
265
|
-
expect(listener).not.toHaveBeenCalled();
|
266
|
-
openCallback('GET', 'https://example.com/api', { uniqueId: '124' });
|
267
|
-
expect(listener).toHaveBeenCalled();
|
268
|
-
});
|
269
|
-
it('should ignore requests matching ignored patterns', () => {
|
270
|
-
HTTPInterceptor_1.httpInterceptor.enable({ ignoredPatterns: [/^GET https:\/\/test\.com/] });
|
271
|
-
const openCallback = XHRInterceptor_1.default.setOpenCallback.mock.calls[0][0];
|
272
|
-
const listener = jest.fn();
|
273
|
-
HTTPInterceptor_1.httpInterceptor.addListener('open', listener);
|
274
|
-
openCallback('GET', 'https://test.com/api', { uniqueId: '123' });
|
275
|
-
expect(listener).not.toHaveBeenCalled();
|
276
|
-
openCallback('POST', 'https://test.com/api', { uniqueId: '124' });
|
277
|
-
expect(listener).toHaveBeenCalled();
|
278
|
-
});
|
279
|
-
});
|
280
|
-
});
|
281
|
-
//# sourceMappingURL=HTTPInterceptor.test.js.map
|