From: Jérôme Benoit Date: Fri, 5 May 2023 14:32:06 +0000 (+0200) Subject: fix: check that task functions worker parameter is not empty X-Git-Tag: v2.4.12~15^2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=630f0acfda6a1b894102504c9d5316b99c0a188d;p=poolifier.git fix: check that task functions worker parameter is not empty Signed-off-by: Jérôme Benoit --- 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', () => {