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

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

View File

@ -35,28 +35,22 @@ describe("custom canvas rendering", function () {
let loadingTask; let loadingTask;
let page; let page;
beforeAll(function (done) { beforeAll(async function () {
CanvasFactory = new DefaultCanvasFactory(); CanvasFactory = new DefaultCanvasFactory();
loadingTask = getDocument(transparentGetDocumentParams); loadingTask = getDocument(transparentGetDocumentParams);
loadingTask.promise const doc = await loadingTask.promise;
.then(function (doc) { const data = await doc.getPage(1);
return doc.getPage(1); page = data;
})
.then(function (data) {
page = data;
done();
})
.catch(done.fail);
}); });
afterAll(function (done) { afterAll(async function () {
CanvasFactory = null; CanvasFactory = null;
page = null; page = null;
loadingTask.destroy().then(done); await loadingTask.destroy();
}); });
it("renders to canvas with a default white background", function (done) { it("renders to canvas with a default white background", async function () {
const viewport = page.getViewport({ scale: 1 }); const viewport = page.getViewport({ scale: 1 });
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height); const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
@ -64,21 +58,18 @@ describe("custom canvas rendering", function () {
canvasContext: canvasAndCtx.context, canvasContext: canvasAndCtx.context,
viewport, viewport,
}); });
renderTask.promise await renderTask.promise;
.then(function () {
expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({
r: 255, r: 255,
g: 255, g: 255,
b: 255, b: 255,
a: 255, a: 255,
}); });
CanvasFactory.destroy(canvasAndCtx); CanvasFactory.destroy(canvasAndCtx);
done();
})
.catch(done.fail);
}); });
it("renders to canvas with a custom background", function (done) { it("renders to canvas with a custom background", async function () {
const viewport = page.getViewport({ scale: 1 }); const viewport = page.getViewport({ scale: 1 });
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height); const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
@ -87,18 +78,15 @@ describe("custom canvas rendering", function () {
viewport, viewport,
background: "rgba(255,0,0,1.0)", background: "rgba(255,0,0,1.0)",
}); });
renderTask.promise await renderTask.promise;
.then(function () {
expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({
r: 255, r: 255,
g: 0, g: 0,
b: 0, b: 0,
a: 255, a: 255,
}); });
CanvasFactory.destroy(canvasAndCtx); CanvasFactory.destroy(canvasAndCtx);
done();
})
.catch(done.fail);
}); });
}); });