Convert done callbacks to async/await in test/unit/custom_spec.js
				
					
				
			This commit is contained in:
		
							parent
							
								
									a1c1e1b9f8
								
							
						
					
					
						commit
						c1e9f6025f
					
				| @ -35,28 +35,22 @@ describe("custom canvas rendering", function () { | ||||
|   let loadingTask; | ||||
|   let page; | ||||
| 
 | ||||
|   beforeAll(function (done) { | ||||
|   beforeAll(async function () { | ||||
|     CanvasFactory = new DefaultCanvasFactory(); | ||||
| 
 | ||||
|     loadingTask = getDocument(transparentGetDocumentParams); | ||||
|     loadingTask.promise | ||||
|       .then(function (doc) { | ||||
|         return doc.getPage(1); | ||||
|       }) | ||||
|       .then(function (data) { | ||||
|         page = data; | ||||
|         done(); | ||||
|       }) | ||||
|       .catch(done.fail); | ||||
|     const doc = await loadingTask.promise; | ||||
|     const data = await doc.getPage(1); | ||||
|     page = data; | ||||
|   }); | ||||
| 
 | ||||
|   afterAll(function (done) { | ||||
|   afterAll(async function () { | ||||
|     CanvasFactory = 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 canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height); | ||||
| 
 | ||||
| @ -64,21 +58,18 @@ describe("custom canvas rendering", function () { | ||||
|       canvasContext: canvasAndCtx.context, | ||||
|       viewport, | ||||
|     }); | ||||
|     renderTask.promise | ||||
|       .then(function () { | ||||
|         expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ | ||||
|           r: 255, | ||||
|           g: 255, | ||||
|           b: 255, | ||||
|           a: 255, | ||||
|         }); | ||||
|         CanvasFactory.destroy(canvasAndCtx); | ||||
|         done(); | ||||
|       }) | ||||
|       .catch(done.fail); | ||||
|     await renderTask.promise; | ||||
| 
 | ||||
|     expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ | ||||
|       r: 255, | ||||
|       g: 255, | ||||
|       b: 255, | ||||
|       a: 255, | ||||
|     }); | ||||
|     CanvasFactory.destroy(canvasAndCtx); | ||||
|   }); | ||||
| 
 | ||||
|   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 canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height); | ||||
| 
 | ||||
| @ -87,18 +78,15 @@ describe("custom canvas rendering", function () { | ||||
|       viewport, | ||||
|       background: "rgba(255,0,0,1.0)", | ||||
|     }); | ||||
|     renderTask.promise | ||||
|       .then(function () { | ||||
|         expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ | ||||
|           r: 255, | ||||
|           g: 0, | ||||
|           b: 0, | ||||
|           a: 255, | ||||
|         }); | ||||
|         CanvasFactory.destroy(canvasAndCtx); | ||||
|         done(); | ||||
|       }) | ||||
|       .catch(done.fail); | ||||
|     await renderTask.promise; | ||||
| 
 | ||||
|     expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({ | ||||
|       r: 255, | ||||
|       g: 0, | ||||
|       b: 0, | ||||
|       a: 255, | ||||
|     }); | ||||
|     CanvasFactory.destroy(canvasAndCtx); | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user