From 5607484402adc89d9c8f3d8a7697c86089676f80 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 11 Apr 2021 20:03:41 +0200 Subject: [PATCH] Convert done callbacks to async/await in `test/unit/network_spec.js` --- test/unit/network_spec.js | 40 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/test/unit/network_spec.js b/test/unit/network_spec.js index 7d186e100..e8b4b9f4c 100644 --- a/test/unit/network_spec.js +++ b/test/unit/network_spec.js @@ -20,7 +20,7 @@ describe("network", function () { const pdf1 = new URL("../pdfs/tracemonkey.pdf", window.location).href; const pdf1Length = 1016315; - it("read without stream and range", function (done) { + it("read without stream and range", async function () { const stream = new PDFNetworkStream({ url: pdf1, rangeChunkSize: 65536, @@ -49,22 +49,15 @@ describe("network", function () { }); }; - const readPromise = Promise.all([read(), promise]); + await Promise.all([read(), promise]); - readPromise - .then(function (page) { - expect(len).toEqual(pdf1Length); - expect(count).toEqual(1); - expect(isStreamingSupported).toEqual(false); - expect(isRangeSupported).toEqual(false); - done(); - }) - .catch(function (reason) { - done.fail(reason); - }); + expect(len).toEqual(pdf1Length); + expect(count).toEqual(1); + expect(isStreamingSupported).toEqual(false); + expect(isRangeSupported).toEqual(false); }); - it("read custom ranges", function (done) { + it("read custom ranges", async function () { // We don't test on browsers that don't support range request, so // requiring this test to pass. const rangeSize = 32768; @@ -111,23 +104,16 @@ describe("network", function () { }); }; - const readPromises = Promise.all([ + await Promise.all([ read(range1Reader, result1), read(range2Reader, result2), promise, ]); - readPromises - .then(function () { - expect(result1.value).toEqual(rangeSize); - expect(result2.value).toEqual(tailSize); - expect(isStreamingSupported).toEqual(false); - expect(isRangeSupported).toEqual(true); - expect(fullReaderCancelled).toEqual(true); - done(); - }) - .catch(function (reason) { - done.fail(reason); - }); + expect(result1.value).toEqual(rangeSize); + expect(result2.value).toEqual(tailSize); + expect(isStreamingSupported).toEqual(false); + expect(isRangeSupported).toEqual(true); + expect(fullReaderCancelled).toEqual(true); }); });