diff --git a/mediapipe/tasks/web/core/task_runner_test.ts b/mediapipe/tasks/web/core/task_runner_test.ts index f44cfe49e..52df0550a 100644 --- a/mediapipe/tasks/web/core/task_runner_test.ts +++ b/mediapipe/tasks/web/core/task_runner_test.ts @@ -118,9 +118,10 @@ describe('TaskRunner', () => { let fetchSpy: jasmine.Spy; let taskRunner: TaskRunnerFake; - let fetchStatus = 200; + let fetchStatus: number; beforeEach(() => { + fetchStatus = 200; fetchSpy = jasmine.createSpy().and.callFake(async url => { return { arrayBuffer: () => mockBytes.buffer, diff --git a/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts b/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts index 59e932972..f45035b6b 100644 --- a/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts +++ b/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts @@ -185,6 +185,23 @@ describe('VisionTaskRunner', () => { }).toThrowError(/You must create a new task to reset the canvas./); }); + it('validates that an undefined canvas leaves the graph unmodified', + async () => { + if (typeof OffscreenCanvas === 'undefined') { + console.log('Test is not supported under Node.'); + return; + } + + const visionTaskRunner = new VisionTaskRunnerFake(); + const canvas = new OffscreenCanvas(1, 1); + visionTaskRunner.graphRunner.wasmModule.canvas = canvas; + + await visionTaskRunner.setOptions({canvas}); + await visionTaskRunner.setOptions({canvas: undefined}); + + expect(visionTaskRunner.graphRunner.wasmModule.canvas).toBe(canvas); + }); + it('sends packets to graph', async () => { const visionTaskRunner = new VisionTaskRunnerFake(); await visionTaskRunner.setOptions({runningMode: 'VIDEO'}); diff --git a/mediapipe/tasks/web/vision/core/vision_task_runner.ts b/mediapipe/tasks/web/vision/core/vision_task_runner.ts index 9abbf0978..4a7178912 100644 --- a/mediapipe/tasks/web/vision/core/vision_task_runner.ts +++ b/mediapipe/tasks/web/vision/core/vision_task_runner.ts @@ -89,7 +89,7 @@ export abstract class VisionTaskRunner extends TaskRunner { this.baseOptions.setUseStreamMode(useStreamMode); } - if ('canvas' in options) { + if (options.canvas !== undefined) { if (this.graphRunner.wasmModule.canvas !== options.canvas) { throw new Error('You must create a new task to reset the canvas.'); }