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 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); |  | ||||||
|       }) |  | ||||||
|       .then(function (data) { |  | ||||||
|     page = 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,8 +58,8 @@ 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, | ||||||
| @ -73,12 +67,9 @@ describe("custom canvas rendering", function () { | |||||||
|       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,8 +78,8 @@ 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, | ||||||
| @ -96,9 +87,6 @@ describe("custom canvas rendering", function () { | |||||||
|       a: 255, |       a: 255, | ||||||
|     }); |     }); | ||||||
|     CanvasFactory.destroy(canvasAndCtx); |     CanvasFactory.destroy(canvasAndCtx); | ||||||
|         done(); |  | ||||||
|       }) |  | ||||||
|       .catch(done.fail); |  | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user