Convert done callbacks to async/await in test/unit/node_stream_spec.js
This commit is contained in:
parent
99dc0d6b65
commit
fcf4d02fca
@ -18,7 +18,7 @@ import { AbortException } from "../../src/shared/util.js";
|
|||||||
import { isNodeJS } from "../../src/shared/is_node.js";
|
import { isNodeJS } from "../../src/shared/is_node.js";
|
||||||
import { PDFNodeStream } from "../../src/display/node_stream.js";
|
import { PDFNodeStream } from "../../src/display/node_stream.js";
|
||||||
|
|
||||||
// Ensure that these test only runs in Node.js environments.
|
// Ensure that these tests only run in Node.js environments.
|
||||||
if (!isNodeJS) {
|
if (!isNodeJS) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The "node_stream" unit-tests can only be run in Node.js environments.'
|
'The "node_stream" unit-tests can only be run in Node.js environments.'
|
||||||
@ -84,7 +84,7 @@ describe("node_stream", function () {
|
|||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("read both http(s) and filesystem pdf files", function (done) {
|
it("read both http(s) and filesystem pdf files", async function () {
|
||||||
const stream1 = new PDFNodeStream({
|
const stream1 = new PDFNodeStream({
|
||||||
url: `http://127.0.0.1:${port}/tracemonkey.pdf`,
|
url: `http://127.0.0.1:${port}/tracemonkey.pdf`,
|
||||||
rangeChunkSize: 65536,
|
rangeChunkSize: 65536,
|
||||||
@ -135,23 +135,17 @@ describe("node_stream", function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const readPromise = Promise.all([read1(), read2(), promise1, promise2]);
|
await Promise.all([read1(), read2(), promise1, promise2]);
|
||||||
readPromise
|
|
||||||
.then(result => {
|
|
||||||
expect(isStreamingSupported1).toEqual(false);
|
expect(isStreamingSupported1).toEqual(false);
|
||||||
expect(isRangeSupported1).toEqual(false);
|
expect(isRangeSupported1).toEqual(false);
|
||||||
expect(isStreamingSupported2).toEqual(false);
|
expect(isStreamingSupported2).toEqual(false);
|
||||||
expect(isRangeSupported2).toEqual(false);
|
expect(isRangeSupported2).toEqual(false);
|
||||||
expect(len1).toEqual(pdfLength);
|
expect(len1).toEqual(pdfLength);
|
||||||
expect(len1).toEqual(len2);
|
expect(len1).toEqual(len2);
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(reason => {
|
|
||||||
done.fail(reason);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("read custom ranges for both http(s) and filesystem urls", function (done) {
|
it("read custom ranges for both http(s) and filesystem urls", async function () {
|
||||||
const rangeSize = 32768;
|
const rangeSize = 32768;
|
||||||
const stream1 = new PDFNodeStream({
|
const stream1 = new PDFNodeStream({
|
||||||
url: `http://127.0.0.1:${port}/tracemonkey.pdf`,
|
url: `http://127.0.0.1:${port}/tracemonkey.pdf`,
|
||||||
@ -225,7 +219,7 @@ describe("node_stream", function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const readPromises = Promise.all([
|
await Promise.all([
|
||||||
read(range11Reader, result11),
|
read(range11Reader, result11),
|
||||||
read(range12Reader, result12),
|
read(range12Reader, result12),
|
||||||
read(range21Reader, result21),
|
read(range21Reader, result21),
|
||||||
@ -234,8 +228,6 @@ describe("node_stream", function () {
|
|||||||
promise2,
|
promise2,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
readPromises
|
|
||||||
.then(function () {
|
|
||||||
expect(result11.value).toEqual(rangeSize);
|
expect(result11.value).toEqual(rangeSize);
|
||||||
expect(result12.value).toEqual(tailSize);
|
expect(result12.value).toEqual(tailSize);
|
||||||
expect(result21.value).toEqual(rangeSize);
|
expect(result21.value).toEqual(rangeSize);
|
||||||
@ -246,10 +238,5 @@ describe("node_stream", function () {
|
|||||||
expect(isStreamingSupported2).toEqual(false);
|
expect(isStreamingSupported2).toEqual(false);
|
||||||
expect(isRangeSupported2).toEqual(true);
|
expect(isRangeSupported2).toEqual(true);
|
||||||
expect(fullReaderCancelled2).toEqual(true);
|
expect(fullReaderCancelled2).toEqual(true);
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(function (reason) {
|
|
||||||
done.fail(reason);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user