From: Jérôme Benoit Date: Sun, 8 Oct 2023 12:41:45 +0000 (+0200) Subject: refactor: remove unneeded conditions at worker file path checking X-Git-Tag: v3.0.1~27 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fa015370d8f886ee3dcb348483dfa4187239d4d3;p=poolifier.git refactor: remove unneeded conditions at worker file path checking Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/utils.ts b/src/pools/utils.ts index e08b31aa8..eb800c4ab 100644 --- a/src/pools/utils.ts +++ b/src/pools/utils.ts @@ -9,13 +9,6 @@ import type { TasksQueueOptions } from './pool' import type { IWorker, MeasurementStatistics } from './worker' export const checkFilePath = (filePath: string): void => { - if ( - filePath == null || - typeof filePath !== 'string' || - (typeof filePath === 'string' && filePath.trim().length === 0) - ) { - throw new Error('Please specify a file with a worker implementation') - } if (!existsSync(filePath)) { throw new Error(`Cannot find the worker file '${filePath}'`) } diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 041c62a2b..765a2b0d1 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -66,20 +66,8 @@ describe('Abstract pool test suite', () => { }) it('Verify that filePath is checked', () => { - const expectedError = new Error( - 'Please specify a file with a worker implementation' - ) expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError( - expectedError - ) - expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError( - expectedError - ) - expect(() => new FixedThreadPool(numberOfWorkers, 0)).toThrowError( - expectedError - ) - expect(() => new FixedThreadPool(numberOfWorkers, true)).toThrowError( - expectedError + new Error("Cannot find the worker file 'undefined'") ) expect( () => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts') diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index edd963903..93dcc7fad 100644 --- a/tests/pools/cluster/dynamic.test.mjs +++ b/tests/pools/cluster/dynamic.test.mjs @@ -74,7 +74,7 @@ describe('Dynamic cluster pool test suite', () => { it('Validation of inputs test', () => { expect(() => new DynamicClusterPool(min)).toThrowError( - 'Please specify a file with a worker implementation' + "Cannot find the worker file 'undefined'" ) }) diff --git a/tests/pools/thread/dynamic.test.mjs b/tests/pools/thread/dynamic.test.mjs index 0918065b4..c31e141c0 100644 --- a/tests/pools/thread/dynamic.test.mjs +++ b/tests/pools/thread/dynamic.test.mjs @@ -74,7 +74,7 @@ describe('Dynamic thread pool test suite', () => { it('Validation of inputs test', () => { expect(() => new DynamicThreadPool(min)).toThrowError( - 'Please specify a file with a worker implementation' + "Cannot find the worker file 'undefined'" ) })