From 630f0acfda6a1b894102504c9d5316b99c0a188d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 5 May 2023 16:32:06 +0200 Subject: [PATCH] fix: check that task functions worker parameter is not empty MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/abstract-worker.ts | 3 +++ tests/worker/abstract-worker.test.js | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 1a2a1559..8b461f7d 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -131,6 +131,9 @@ export abstract class AbstractWorker< firstEntry = false } } + if (firstEntry) { + throw new Error('taskFunctions parameter object is empty') + } } else { this.taskFunctions.set(DEFAULT_FUNCTION_NAME, taskFunctions.bind(this)) } diff --git a/tests/worker/abstract-worker.test.js b/tests/worker/abstract-worker.test.js index 5b42eb9d..7f05cbb7 100644 --- a/tests/worker/abstract-worker.test.js +++ b/tests/worker/abstract-worker.test.js @@ -45,7 +45,7 @@ describe('Abstract worker test suite', () => { ) }) - it('Verify that taskFunctions parameter is an object literal', () => { + it('Verify that taskFunctions parameter is not an empty object literal', () => { expect(() => new ClusterWorker([])).toThrowError( new TypeError('taskFunctions parameter is not an object literal') ) @@ -61,6 +61,9 @@ describe('Abstract worker test suite', () => { expect(() => new ClusterWorker(new WeakSet())).toThrowError( new TypeError('taskFunctions parameter is not an object literal') ) + expect(() => new ClusterWorker({})).toThrowError( + new TypeError('taskFunctions parameter object is empty') + ) }) it('Verify that taskFunctions parameter with multiple task functions is taken', () => { -- 2.34.1