Skip to content

Commit fbef6e2

Browse files
committed
chore: add more tests
1 parent d538c67 commit fbef6e2

File tree

5 files changed

+435
-97
lines changed

5 files changed

+435
-97
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
],
3535
"scripts": {
3636
"flow": "flow",
37-
"lint": "eslint --cache --ignore-path .gitignore *.js"
37+
"lint": "eslint --cache --ignore-path .gitignore *.js",
38+
"test:ios": "./run-tests.js --platform ios --simulator 'iPhone 11 (14.1)' test/index.js",
39+
"test:android": "./run-tests.js --platform android --emulator Pixel_API_28_AOSP test/index.js"
3840
},
3941
"dependencies": {
4042
"p-defer": "^3.0.0"

src/Fetch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ class Fetch {
6565
return this._deferredPromise.promise;
6666
}
6767

68-
__setNativeResponseType(options) {
69-
if (options.textStreaming) {
68+
__setNativeResponseType({ reactNative }) {
69+
if (reactNative?.textStreaming) {
7070
this._nativeResponseType = "text";
7171

7272
return;
7373
}
7474

7575
this._nativeResponseType =
76-
options.__nativeResponseType ?? this._nativeResponseType;
76+
reactNative?.__nativeResponseType ?? this._nativeResponseType;
7777
}
7878

7979
__subscribeToNetworkEvents() {

src/Request.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Request {
1818

1919
this._body = this._body ?? new Body(options.body);
2020
this.method = options.method ?? this.method;
21+
this.method = this.method.toUpperCase();
2122

2223
if (this._body._bodyInit && ["GET", "HEAD"].includes(this.method)) {
2324
throw new TypeError("Body not allowed for GET or HEAD requests");
@@ -34,6 +35,8 @@ class Request {
3435
if (!this.headers.has("content-type") && this._body._mimeType) {
3536
this.headers.set("content-type", this._body._mimeType);
3637
}
38+
39+
this.__handleCacheOption(options.cache);
3740
}
3841

3942
__handleRequestInput(request, options) {
@@ -49,6 +52,34 @@ class Request {
4952
}
5053
}
5154

55+
__handleCacheOption(cache) {
56+
if (!["GET", "HEAD"].includes(this.method)) {
57+
return;
58+
}
59+
60+
if (!["no-store", "no-cache"].includes(cache)) {
61+
return;
62+
}
63+
64+
const currentTime = Date.now();
65+
// Search for a '_' parameter in the query string
66+
const querySearchRegExp = /([?&])_=[^&]*/;
67+
68+
if (querySearchRegExp.test(this.url)) {
69+
this.url = this.url.replace(
70+
querySearchRegExp,
71+
`$1_=${currentTime}`
72+
);
73+
74+
return;
75+
}
76+
77+
const hasQueryRegExp = /\?/;
78+
const querySeparator = hasQueryRegExp.test(this.url) ? "&" : "?";
79+
80+
this.url += `${querySeparator}_=${currentTime}`;
81+
}
82+
5283
get bodyUsed() {
5384
return this._body.bodyUsed;
5485
}

0 commit comments

Comments
 (0)