Re-factor the PDFDocumentProxy.cleanup
unit-tests to use async/await
This commit is contained in:
parent
a2bc6481a0
commit
232fbd28e1
@ -1339,12 +1339,10 @@ describe("api", function () {
|
|||||||
.catch(done.fail);
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("cleans up document resources", function (done) {
|
it("cleans up document resources", async function () {
|
||||||
const promise = pdfDocument.cleanup();
|
await pdfDocument.cleanup();
|
||||||
promise.then(function () {
|
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
done();
|
|
||||||
}, done.fail);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("checks that fingerprints are unique", function (done) {
|
it("checks that fingerprints are unique", function (done) {
|
||||||
@ -1982,85 +1980,69 @@ describe("api", function () {
|
|||||||
]).then(done);
|
]).then(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("cleans up document resources after rendering of page", function (done) {
|
it("cleans up document resources after rendering of page", async function () {
|
||||||
const loadingTask = getDocument(buildGetDocumentParams(basicApiFileName));
|
const loadingTask = getDocument(buildGetDocumentParams(basicApiFileName));
|
||||||
let canvasAndCtx;
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const pdfPage = await pdfDoc.getPage(1);
|
||||||
|
|
||||||
loadingTask.promise
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
.then(pdfDoc => {
|
const canvasAndCtx = CanvasFactory.create(
|
||||||
return pdfDoc.getPage(1).then(pdfPage => {
|
viewport.width,
|
||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
viewport.height
|
||||||
canvasAndCtx = CanvasFactory.create(
|
);
|
||||||
viewport.width,
|
|
||||||
viewport.height
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderTask = pdfPage.render({
|
const renderTask = pdfPage.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
return renderTask.promise.then(() => {
|
await renderTask.promise;
|
||||||
return pdfDoc.cleanup();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
expect(true).toEqual(true);
|
|
||||||
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
await pdfDoc.cleanup();
|
||||||
loadingTask.destroy().then(done);
|
|
||||||
}, done.fail);
|
expect(true).toEqual(true);
|
||||||
|
|
||||||
|
CanvasFactory.destroy(canvasAndCtx);
|
||||||
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("cleans up document resources during rendering of page", function (done) {
|
it("cleans up document resources during rendering of page", async function () {
|
||||||
const loadingTask = getDocument(
|
const loadingTask = getDocument(
|
||||||
buildGetDocumentParams("tracemonkey.pdf")
|
buildGetDocumentParams("tracemonkey.pdf")
|
||||||
);
|
);
|
||||||
let canvasAndCtx;
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const pdfPage = await pdfDoc.getPage(1);
|
||||||
|
|
||||||
loadingTask.promise
|
const viewport = pdfPage.getViewport({ scale: 1 });
|
||||||
.then(pdfDoc => {
|
const canvasAndCtx = CanvasFactory.create(
|
||||||
return pdfDoc.getPage(1).then(pdfPage => {
|
viewport.width,
|
||||||
const viewport = pdfPage.getViewport({ scale: 1 });
|
viewport.height
|
||||||
canvasAndCtx = CanvasFactory.create(
|
);
|
||||||
viewport.width,
|
|
||||||
viewport.height
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderTask = pdfPage.render({
|
const renderTask = pdfPage.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
|
// Ensure that clean-up runs during rendering.
|
||||||
|
renderTask.onContinue = function (cont) {
|
||||||
|
waitSome(cont);
|
||||||
|
};
|
||||||
|
|
||||||
renderTask.onContinue = function (cont) {
|
try {
|
||||||
waitSome(cont);
|
await pdfDoc.cleanup();
|
||||||
};
|
|
||||||
|
|
||||||
return pdfDoc
|
throw new Error("shall fail cleanup");
|
||||||
.cleanup()
|
} catch (reason) {
|
||||||
.then(
|
expect(reason instanceof Error).toEqual(true);
|
||||||
() => {
|
expect(reason.message).toEqual(
|
||||||
throw new Error("shall fail cleanup");
|
"startCleanup: Page 1 is currently rendering."
|
||||||
},
|
);
|
||||||
reason => {
|
}
|
||||||
expect(reason instanceof Error).toEqual(true);
|
await renderTask.promise;
|
||||||
expect(reason.message).toEqual(
|
|
||||||
"startCleanup: Page 1 is currently rendering."
|
CanvasFactory.destroy(canvasAndCtx);
|
||||||
);
|
await loadingTask.destroy();
|
||||||
}
|
|
||||||
)
|
|
||||||
.then(() => {
|
|
||||||
return renderTask.promise;
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
|
||||||
loadingTask.destroy().then(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(done.fail);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("caches image resources at the document/page level as expected (issue 11878)", async function () {
|
it("caches image resources at the document/page level as expected (issue 11878)", async function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user