Skip to content

Commit

Permalink
Fetch: remove usage of FileReader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KhafraDev committed Mar 3, 2024
1 parent 9a0819b commit 0a24e44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 54 deletions.
22 changes: 5 additions & 17 deletions fetch/api/request/request-consume-empty.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,11 @@ function checkBodyText(test, request) {
});
}

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) {
Expand Down
29 changes: 9 additions & 20 deletions fetch/api/request/request-consume.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,15 @@ function checkBodyText(request, expectedBody) {
});
}

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");

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");
});
});
async function checkBodyBlob(request, expectedBody, checkContentType) {
const bodyAsBlob = await request.blob();

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) {
Expand Down
23 changes: 6 additions & 17 deletions fetch/api/response/response-consume-empty.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@ function checkBodyText(test, response) {
});
}

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) {
Expand Down

0 comments on commit 0a24e44

Please sign in to comment.