refactor: remove unneeded conditions at worker file path checking
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 8 Oct 2023 12:41:45 +0000 (14:41 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 8 Oct 2023 12:41:45 +0000 (14:41 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/utils.ts
tests/pools/abstract-pool.test.mjs
tests/pools/cluster/dynamic.test.mjs
tests/pools/thread/dynamic.test.mjs

index e08b31aa838537c1ceee37f284ff39ac53960308..eb800c4ab50f9d39e2b6fc98ebb4cf39bfc134b5 100644 (file)
@@ -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}'`)
   }
index 041c62a2b1277c179d689dbe182d6b382fc55cef..765a2b0d1553febb95feb3fd36307e6f2eacda66 100644 (file)
@@ -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')
index edd9639036937143a64ee5c8a571cecc6c436f35..93dcc7fad89e8adb942ce667d99e21ebb2a91e88 100644 (file)
@@ -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'"
     )
   })
 
index 0918065b403314f942fc4e3422e83740cdd3e654..c31e141c091b52c7ff2050253051eb8fd2e68092 100644 (file)
@@ -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'"
     )
   })