From fa015370d8f886ee3dcb348483dfa4187239d4d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 8 Oct 2023 14:41:45 +0200 Subject: [PATCH] refactor: remove unneeded conditions at worker file path checking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/utils.ts | 7 ------- tests/pools/abstract-pool.test.mjs | 14 +------------- tests/pools/cluster/dynamic.test.mjs | 2 +- tests/pools/thread/dynamic.test.mjs | 2 +- 4 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/pools/utils.ts b/src/pools/utils.ts index e08b31aa..eb800c4a 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 041c62a2..765a2b0d 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 edd96390..93dcc7fa 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 0918065b..c31e141c 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'" ) }) -- 2.34.1