Convert done callbacks to async/await in test/unit/fetch_stream_spec.js

This commit is contained in:
Tim van der Meij 2021-04-11 20:07:27 +02:00
parent 5607484402
commit a1c1e1b9f8
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -20,7 +20,7 @@ describe("fetch_stream", function () {
const pdfUrl = new URL("../pdfs/tracemonkey.pdf", window.location).href;
const pdfLength = 1016315;
it("read with streaming", function (done) {
it("read with streaming", async function () {
const stream = new PDFFetchStream({
url: pdfUrl,
disableStream: false,
@ -47,18 +47,14 @@ describe("fetch_stream", function () {
});
};
const readPromise = Promise.all([read(), promise]);
readPromise
.then(function () {
expect(len).toEqual(pdfLength);
expect(isStreamingSupported).toEqual(true);
expect(isRangeSupported).toEqual(false);
done();
})
.catch(done.fail);
await Promise.all([read(), promise]);
expect(len).toEqual(pdfLength);
expect(isStreamingSupported).toEqual(true);
expect(isRangeSupported).toEqual(false);
});
it("read ranges with streaming", function (done) {
it("read ranges with streaming", async function () {
const rangeSize = 32768;
const stream = new PDFFetchStream({
url: pdfUrl,
@ -98,20 +94,16 @@ describe("fetch_stream", function () {
});
};
const readPromise = Promise.all([
await Promise.all([
read(rangeReader1, result1),
read(rangeReader2, result2),
promise,
]);
readPromise
.then(function () {
expect(isStreamingSupported).toEqual(true);
expect(isRangeSupported).toEqual(true);
expect(fullReaderCancelled).toEqual(true);
expect(result1.value).toEqual(rangeSize);
expect(result2.value).toEqual(tailSize);
done();
})
.catch(done.fail);
expect(isStreamingSupported).toEqual(true);
expect(isRangeSupported).toEqual(true);
expect(fullReaderCancelled).toEqual(true);
expect(result1.value).toEqual(rangeSize);
expect(result2.value).toEqual(tailSize);
});
});