Skip to content

Commit 455a95a

Browse files
medfreemanklis87
authored andcommitted
test(redux-requests-fetch): add a request abort test with polyfilled fetch & AbortController
Add `isomorphic-fetch` & `yet-another-abortcontroller-polyfill` devDependencies
1 parent dc9a867 commit 455a95a

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

packages/redux-requests-fetch/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@
5353
"eslint-plugin-jsx-a11y": "6.4.1",
5454
"eslint-plugin-react": "7.21.5",
5555
"eslint-plugin-react-hooks": "4.2.0",
56+
"isomorphic-fetch": "3.0.0",
5657
"jest": "26.6.3",
5758
"nodemon": "2.0.6",
5859
"npm-run-all": "4.1.5",
5960
"rimraf": "3.0.2",
6061
"typescript": "4.1.2",
6162
"webpack": "5.9.0",
62-
"webpack-cli": "4.2.0"
63+
"webpack-cli": "4.2.0",
64+
"yet-another-abortcontroller-polyfill": "0.0.4"
6365
},
6466
"publishConfig": {
6567
"access": "public"

packages/redux-requests-fetch/src/fetch-api-driver.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import 'isomorphic-fetch'
2+
import 'yet-another-abortcontroller-polyfill'
3+
14
import { createDriver } from './fetch-api-driver';
25

36
describe('fetchApiDriver', () => {
@@ -144,6 +147,22 @@ describe('fetchApiDriver', () => {
144147
expect(abort).toHaveBeenCalledTimes(1);
145148
});
146149

150+
it('properly handles aborting requests with the polyfilled `fetch` & `AbortController`', async() => {
151+
const driver = createDriver(fetch, {
152+
AbortController,
153+
});
154+
155+
const promise = driver({ url: 'http://localhost' });
156+
try {
157+
promise.cancel();
158+
await promise;
159+
} catch(e) {
160+
expect(e).toBe('REQUEST_ABORTED')
161+
}
162+
// makes sure the promise doesn't resolve
163+
expect(promise).rejects.toBeDefined();
164+
});
165+
147166
it('uses baseURL for relative urls', async () => {
148167
const requestInstance = jest.fn().mockResolvedValue({
149168
ok: true,

yarn.lock

+43
Original file line numberDiff line numberDiff line change
@@ -6395,6 +6395,14 @@ isobject@^4.0.0:
63956395
resolved "https://registry.yarnpkg.com/isobject/-/isobject-4.0.0.tgz#3f1c9155e73b192022a80819bacd0343711697b0"
63966396
integrity sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA==
63976397

6398+
6399+
version "3.0.0"
6400+
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz#0267b005049046d2421207215d45d6a262b8b8b4"
6401+
integrity sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==
6402+
dependencies:
6403+
node-fetch "^2.6.1"
6404+
whatwg-fetch "^3.4.1"
6405+
63986406
isstream@~0.1.2:
63996407
version "0.1.2"
64006408
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@@ -7740,6 +7748,13 @@ node-fetch@^2.3.0, node-fetch@^2.5.0:
77407748
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
77417749
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
77427750

7751+
node-fetch@^2.6.1:
7752+
version "2.6.5"
7753+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.5.tgz#42735537d7f080a7e5f78b6c549b7146be1742fd"
7754+
integrity sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==
7755+
dependencies:
7756+
whatwg-url "^5.0.0"
7757+
77437758
node-gyp@^5.0.2:
77447759
version "5.1.0"
77457760
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-5.1.0.tgz#8e31260a7af4a2e2f994b0673d4e0b3866156332"
@@ -10293,6 +10308,11 @@ tr46@^2.0.2:
1029310308
dependencies:
1029410309
punycode "^2.1.1"
1029510310

10311+
tr46@~0.0.3:
10312+
version "0.0.3"
10313+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
10314+
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
10315+
1029610316
trim-newlines@^1.0.0:
1029710317
version "1.0.0"
1029810318
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
@@ -10676,6 +10696,11 @@ wcwidth@^1.0.0:
1067610696
dependencies:
1067710697
defaults "^1.0.3"
1067810698

10699+
webidl-conversions@^3.0.0:
10700+
version "3.0.1"
10701+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
10702+
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
10703+
1067910704
webidl-conversions@^4.0.2:
1068010705
version "4.0.2"
1068110706
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
@@ -10762,11 +10787,24 @@ whatwg-encoding@^1.0.5:
1076210787
dependencies:
1076310788
iconv-lite "0.4.24"
1076410789

10790+
whatwg-fetch@^3.4.1:
10791+
version "3.6.2"
10792+
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz#dced24f37f2624ed0281725d51d0e2e3fe677f8c"
10793+
integrity sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==
10794+
1076510795
whatwg-mimetype@^2.3.0:
1076610796
version "2.3.0"
1076710797
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
1076810798
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==
1076910799

10800+
whatwg-url@^5.0.0:
10801+
version "5.0.0"
10802+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
10803+
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
10804+
dependencies:
10805+
tr46 "~0.0.3"
10806+
webidl-conversions "^3.0.0"
10807+
1077010808
whatwg-url@^7.0.0:
1077110809
version "7.0.0"
1077210810
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.0.0.tgz#fde926fa54a599f3adf82dff25a9f7be02dc6edd"
@@ -11013,3 +11051,8 @@ yargs@^15.4.1:
1101311051
which-module "^2.0.0"
1101411052
y18n "^4.0.0"
1101511053
yargs-parser "^18.1.2"
11054+
11055+
11056+
version "0.0.4"
11057+
resolved "https://registry.yarnpkg.com/yet-another-abortcontroller-polyfill/-/yet-another-abortcontroller-polyfill-0.0.4.tgz#ce2270e564a4f2d07351812f599e10143526f98b"
11058+
integrity sha512-6do/P+mjm7FDUD+q8FrZ0ClMIbjGuKyWuWm3Vz2O7QmVf73HVLYIDV6toS7T0qoH1yeI2HPb8VgJp7w+zcVWvA==

0 commit comments

Comments
 (0)