Fetch: remove usage of FileReader
Node doesn't implement FileReader and the repo where fetch tests are run will soon be removing its FileReader shim. Cleanup these tests while here.
diff --git a/fetch/api/request/request-consume-empty.any.js b/fetch/api/request/request-consume-empty.any.js
index 034a860..0bf9672a 100644
--- a/fetch/api/request/request-consume-empty.any.js
+++ b/fetch/api/request/request-consume-empty.any.js
@@ -8,23 +8,11 @@
});
}
-function checkBodyBlob(test, request) {
- return request.blob().then(function(bodyAsBlob) {
- var promise = new Promise(function(resolve, reject) {
- var reader = new FileReader();
- reader.onload = function(evt) {
- resolve(reader.result)
- };
- reader.onerror = function() {
- reject("Blob's reader failed");
- };
- reader.readAsText(bodyAsBlob);
- });
- return promise.then(function(body) {
- assert_equals(body, "", "Resolved value should be empty");
- assert_false(request.bodyUsed);
- });
- });
+async function checkBodyBlob(test, request) {
+ const bodyAsBlob = await request.blob();
+ const body = await bodyAsBlob.text();
+ assert_equals(body, "", "Resolved value should be empty");
+ assert_false(request.bodyUsed);
}
function checkBodyArrayBuffer(test, request) {
diff --git a/fetch/api/request/request-consume.any.js b/fetch/api/request/request-consume.any.js
index aff5d65..3db9e8f 100644
--- a/fetch/api/request/request-consume.any.js
+++ b/fetch/api/request/request-consume.any.js
@@ -9,26 +9,15 @@
});
}
-function checkBodyBlob(request, expectedBody, checkContentType) {
- return request.blob().then(function(bodyAsBlob) {
- if (checkContentType)
- assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type");
+async function checkBodyBlob(request, expectedBody, checkContentType) {
+ const bodyAsBlob = await request.blob();
- var promise = new Promise(function (resolve, reject) {
- var reader = new FileReader();
- reader.onload = function(evt) {
- resolve(reader.result)
- };
- reader.onerror = function() {
- reject("Blob's reader failed");
- };
- reader.readAsText(bodyAsBlob);
- });
- return promise.then(function(body) {
- assert_equals(body, expectedBody, "Retrieve and verify request's body");
- assert_true(request.bodyUsed, "body as blob: bodyUsed turned true");
- });
- });
+ if (checkContentType)
+ assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type");
+
+ const body = await bodyAsBlob.text();
+ assert_equals(body, expectedBody, "Retrieve and verify request's body");
+ assert_true(request.bodyUsed, "body as blob: bodyUsed turned true");
}
function checkBodyArrayBuffer(request, expectedBody) {
diff --git a/fetch/api/response/response-consume-empty.any.js b/fetch/api/response/response-consume-empty.any.js
index 0fa85ec..a5df356 100644
--- a/fetch/api/response/response-consume-empty.any.js
+++ b/fetch/api/response/response-consume-empty.any.js
@@ -8,23 +8,12 @@
});
}
-function checkBodyBlob(test, response) {
- return response.blob().then(function(bodyAsBlob) {
- var promise = new Promise(function(resolve, reject) {
- var reader = new FileReader();
- reader.onload = function(evt) {
- resolve(reader.result)
- };
- reader.onerror = function() {
- reject("Blob's reader failed");
- };
- reader.readAsText(bodyAsBlob);
- });
- return promise.then(function(body) {
- assert_equals(body, "", "Resolved value should be empty");
- assert_false(response.bodyUsed);
- });
- });
+async function checkBodyBlob(test, response) {
+ const bodyAsBlob = await response.blob();
+ const body = await bodyAsBlob.text();
+
+ assert_equals(body, "", "Resolved value should be empty");
+ assert_false(response.bodyUsed);
}
function checkBodyArrayBuffer(test, response) {