Skip to content

Commit ec5dca8

Browse files
committed
chore(fetch): remove AbortController polyfills
1 parent 737e242 commit ec5dca8

File tree

3 files changed

+0
-262
lines changed

3 files changed

+0
-262
lines changed

Diff for: packages/fetch/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181
"@types/chai-as-promised": "^7.1.5",
8282
"@types/chai-string": "^1.4.2",
8383
"@types/mocha": "^9.1.0",
84-
"abort-controller": "^3.0.0",
85-
"abortcontroller-polyfill": "^1.7.1",
8684
"busboy": "^0.3.1",
8785
"c8": "^7.3.0",
8886
"chai": "^4.2.0",

Diff for: packages/fetch/test/main.js

-243
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import chaiString from "chai-string";
1515
import FormData from "form-data";
1616
import FormDataNode from "formdata-node";
1717
import delay from "delay";
18-
import AbortControllerMysticatea from "abort-controller";
19-
import abortControllerPolyfill from "abortcontroller-polyfill/dist/abortcontroller.js";
20-
const AbortControllerPolyfill = abortControllerPolyfill.AbortController;
2118

2219
// Test subjects
2320
import fetch, { Headers, Request, Response } from "@remix-run/web-fetch";
@@ -985,246 +982,6 @@ describe("node-fetch", () => {
985982
});
986983
});
987984

988-
const testAbortController = (
989-
name,
990-
buildAbortController,
991-
moreTests = null
992-
) => {
993-
describe(`AbortController (${name})`, () => {
994-
let controller;
995-
996-
beforeEach(() => {
997-
controller = buildAbortController();
998-
});
999-
1000-
it("should support request cancellation with signal", () => {
1001-
const fetches = [
1002-
fetch(`${base}timeout`, {
1003-
method: "POST",
1004-
signal: controller.signal,
1005-
headers: {
1006-
"Content-Type": "application/json",
1007-
body: JSON.stringify({ hello: "world" }),
1008-
},
1009-
}),
1010-
];
1011-
setTimeout(() => {
1012-
controller.abort();
1013-
}, 100);
1014-
1015-
return Promise.all(
1016-
fetches.map((fetched) =>
1017-
expect(fetched)
1018-
.to.eventually.be.rejected.and.be.an.instanceOf(Error)
1019-
.and.include({
1020-
type: "aborted",
1021-
name: "AbortError",
1022-
})
1023-
)
1024-
);
1025-
});
1026-
1027-
it("should support multiple request cancellation with signal", () => {
1028-
const fetches = [
1029-
fetch(`${base}timeout`, { signal: controller.signal }),
1030-
fetch(`${base}timeout`, {
1031-
method: "POST",
1032-
signal: controller.signal,
1033-
headers: {
1034-
"Content-Type": "application/json",
1035-
body: JSON.stringify({ hello: "world" }),
1036-
},
1037-
}),
1038-
];
1039-
setTimeout(() => {
1040-
controller.abort();
1041-
}, 100);
1042-
1043-
return Promise.all(
1044-
fetches.map((fetched) =>
1045-
expect(fetched)
1046-
.to.eventually.be.rejected.and.be.an.instanceOf(Error)
1047-
.and.include({
1048-
type: "aborted",
1049-
name: "AbortError",
1050-
})
1051-
)
1052-
);
1053-
});
1054-
1055-
it("should reject immediately if signal has already been aborted", () => {
1056-
const url = `${base}timeout`;
1057-
const options = {
1058-
signal: controller.signal,
1059-
};
1060-
controller.abort();
1061-
const fetched = fetch(url, options);
1062-
return expect(fetched)
1063-
.to.eventually.be.rejected.and.be.an.instanceOf(Error)
1064-
.and.include({
1065-
type: "aborted",
1066-
name: "AbortError",
1067-
});
1068-
});
1069-
1070-
it("should allow redirects to be aborted", () => {
1071-
const request = new Request(`${base}redirect/slow`, {
1072-
signal: controller.signal,
1073-
});
1074-
setTimeout(() => {
1075-
controller.abort();
1076-
}, 20);
1077-
return expect(fetch(request))
1078-
.to.be.eventually.rejected.and.be.an.instanceOf(Error)
1079-
.and.have.property("name", "AbortError");
1080-
});
1081-
1082-
it("should allow redirected response body to be aborted", () => {
1083-
const request = new Request(`${base}redirect/slow-stream`, {
1084-
signal: controller.signal,
1085-
});
1086-
return expect(
1087-
fetch(request).then((res) => {
1088-
expect(res.headers.get("content-type")).to.equal("text/plain");
1089-
const result = res.text();
1090-
controller.abort();
1091-
return result;
1092-
})
1093-
)
1094-
.to.be.eventually.rejected.and.be.an.instanceOf(Error)
1095-
.and.have.property("name", "AbortError");
1096-
});
1097-
1098-
it("should reject response body with AbortError when aborted before stream has been read completely", () => {
1099-
return expect(
1100-
fetch(`${base}slow`, { signal: controller.signal })
1101-
).to.eventually.be.fulfilled.then((res) => {
1102-
const promise = res.text();
1103-
controller.abort();
1104-
return expect(promise)
1105-
.to.eventually.be.rejected.and.be.an.instanceof(Error)
1106-
.and.have.property("name", "AbortError");
1107-
});
1108-
});
1109-
1110-
it("should reject response body methods immediately with AbortError when aborted before stream is disturbed", () => {
1111-
return expect(
1112-
fetch(`${base}slow`, { signal: controller.signal })
1113-
).to.eventually.be.fulfilled.then((res) => {
1114-
controller.abort();
1115-
return expect(res.text())
1116-
.to.eventually.be.rejected.and.be.an.instanceof(Error)
1117-
.and.have.property("name", "AbortError");
1118-
});
1119-
});
1120-
1121-
it("should emit error event to response body with an AbortError when aborted before underlying stream is closed", (done) => {
1122-
expect(
1123-
fetch(`${base}slow`, { signal: controller.signal })
1124-
).to.eventually.be.fulfilled.then((res) => {
1125-
const collect = async () => {
1126-
try {
1127-
return await res.arrayBuffer();
1128-
} catch (error) {
1129-
expect(error)
1130-
.to.be.an.instanceof(Error)
1131-
.and.have.property("name", "AbortError");
1132-
done();
1133-
}
1134-
};
1135-
1136-
collect();
1137-
controller.abort();
1138-
});
1139-
});
1140-
1141-
it("should cancel request body of type Stream with AbortError when aborted", () => {
1142-
const body = new stream.Readable({ objectMode: true });
1143-
body._read = () => {};
1144-
const promise = fetch(`${base}slow`, {
1145-
signal: controller.signal,
1146-
body,
1147-
method: "POST",
1148-
});
1149-
1150-
const result = Promise.all([
1151-
new Promise((resolve, reject) => {
1152-
body.on("error", (error) => {
1153-
try {
1154-
expect(error)
1155-
.to.be.an.instanceof(Error)
1156-
.and.have.property("name", "AbortError");
1157-
resolve();
1158-
} catch (error_) {
1159-
reject(error_);
1160-
}
1161-
});
1162-
}),
1163-
expect(promise)
1164-
.to.eventually.be.rejected.and.be.an.instanceof(Error)
1165-
.and.have.property("name", "AbortError"),
1166-
]);
1167-
1168-
controller.abort();
1169-
1170-
return result;
1171-
});
1172-
1173-
if (moreTests) {
1174-
moreTests();
1175-
}
1176-
});
1177-
};
1178-
1179-
testAbortController(
1180-
"polyfill",
1181-
() => new AbortControllerPolyfill(),
1182-
() => {
1183-
it("should remove internal AbortSignal event listener after request is aborted", () => {
1184-
const controller = new AbortControllerPolyfill();
1185-
const { signal } = controller;
1186-
1187-
setTimeout(() => {
1188-
controller.abort();
1189-
}, 20);
1190-
1191-
return expect(fetch(`${base}timeout`, { signal }))
1192-
.to.eventually.be.rejected.and.be.an.instanceof(Error)
1193-
.and.have.property("name", "AbortError")
1194-
.then(() => {
1195-
return expect(signal.listeners.abort.length).to.equal(0);
1196-
});
1197-
});
1198-
1199-
it("should remove internal AbortSignal event listener after request and response complete without aborting", () => {
1200-
const controller = new AbortControllerPolyfill();
1201-
const { signal } = controller;
1202-
const fetchHtml = fetch(`${base}html`, { signal }).then((res) =>
1203-
res.text()
1204-
);
1205-
const fetchResponseError = fetch(`${base}error/reset`, { signal });
1206-
const fetchRedirect = fetch(`${base}redirect/301`, { signal }).then(
1207-
(res) => res.json()
1208-
);
1209-
return Promise.all([
1210-
expect(fetchHtml).to.eventually.be.fulfilled.and.equal(
1211-
"<html></html>"
1212-
),
1213-
expect(fetchResponseError).to.be.eventually.rejected,
1214-
expect(fetchRedirect).to.eventually.be.fulfilled,
1215-
]).then(() => {
1216-
expect(signal.listeners.abort.length).to.equal(0);
1217-
});
1218-
});
1219-
}
1220-
);
1221-
1222-
testAbortController("mysticatea", () => new AbortControllerMysticatea());
1223-
1224-
if (process.version > "v15") {
1225-
testAbortController("native", () => new AbortController());
1226-
}
1227-
1228985
it("should throw a TypeError if a signal is not of type AbortSignal or EventTarget", () => {
1229986
return Promise.all([
1230987
expect(fetch(`${base}inspect`, { signal: {} }))

Diff for: yarn.lock

-17
Original file line numberDiff line numberDiff line change
@@ -827,18 +827,6 @@
827827
resolved "https://registry.npmjs.org/@web3-storage/multipart-parser/-/multipart-parser-1.0.0.tgz#6b69dc2a32a5b207ba43e556c25cc136a56659c4"
828828
integrity sha512-BEO6al7BYqcnfX15W2cnGR+Q566ACXAT9UQykORCWW80lmkpWsnEob6zJS1ZVBKsSJC8+7vJkHwlp+lXG1UCdw==
829829

830-
abort-controller@^3.0.0:
831-
version "3.0.0"
832-
resolved "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
833-
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
834-
dependencies:
835-
event-target-shim "^5.0.0"
836-
837-
abortcontroller-polyfill@^1.7.1:
838-
version "1.7.5"
839-
resolved "https://registry.npmjs.org/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.5.tgz#6738495f4e901fbb57b6c0611d0c75f76c485bed"
840-
integrity sha512-JMJ5soJWP18htbbxJjG7bG6yuI6pRhgJ0scHHTfkUjf6wjP912xZWvM+A4sJK3gqd9E8fcPbDnOefbA9Th/FIQ==
841-
842830
acorn-jsx@^5.3.1:
843831
version "5.3.2"
844832
resolved "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"
@@ -2937,11 +2925,6 @@ esutils@^2.0.2:
29372925
resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
29382926
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
29392927

2940-
event-target-shim@^5.0.0:
2941-
version "5.0.1"
2942-
resolved "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
2943-
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
2944-
29452928
events@^3.0.0, events@^3.3.0:
29462929
version "3.3.0"
29472930
resolved "https://registry.npmjs.org/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"

0 commit comments

Comments
 (0)