From: Jérôme Benoit Date: Sun, 8 Oct 2023 14:00:59 +0000 (+0200) Subject: test: toThrowError() -> toThrow() X-Git-Tag: v3.0.1~25 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=948faff72540848de48b6caa1f3a2c5501b1764d;p=poolifier.git test: toThrowError() -> toThrow() Signed-off-by: Jérôme Benoit --- diff --git a/tests/circular-array.test.mjs b/tests/circular-array.test.mjs index 0e13a8c32..dfa1b53c8 100644 --- a/tests/circular-array.test.mjs +++ b/tests/circular-array.test.mjs @@ -30,13 +30,13 @@ describe('Circular array test suite', () => { }) it('Verify that circular array size is valid at instance creation', () => { - expect(() => new CircularArray(0.25)).toThrowError( + expect(() => new CircularArray(0.25)).toThrow( new TypeError('Invalid circular array size: 0.25 is not a safe integer') ) - expect(() => new CircularArray(-1)).toThrowError( + expect(() => new CircularArray(-1)).toThrow( new RangeError('Invalid circular array size: -1 < 0') ) - expect(() => new CircularArray(Number.MAX_SAFE_INTEGER + 1)).toThrowError( + expect(() => new CircularArray(Number.MAX_SAFE_INTEGER + 1)).toThrow( new TypeError( `Invalid circular array size: ${ Number.MAX_SAFE_INTEGER + 1 @@ -116,15 +116,15 @@ describe('Circular array test suite', () => { }) it('Verify that circular array resize works as intended', () => { - expect(() => new CircularArray().resize(0.25)).toThrowError( + expect(() => new CircularArray().resize(0.25)).toThrow( new TypeError('Invalid circular array size: 0.25 is not a safe integer') ) - expect(() => new CircularArray().resize(-1)).toThrowError( + expect(() => new CircularArray().resize(-1)).toThrow( new RangeError('Invalid circular array size: -1 < 0') ) expect(() => new CircularArray().resize(Number.MAX_SAFE_INTEGER + 1) - ).toThrowError( + ).toThrow( new TypeError( `Invalid circular array size: ${ Number.MAX_SAFE_INTEGER + 1 diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 765a2b0d1..8c0319e7c 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -48,7 +48,7 @@ describe('Abstract pool test suite', () => { errorHandler: e => console.error(e) } ) - ).toThrowError( + ).toThrow( new Error( 'Cannot start a pool from a worker with the same type as the pool' ) @@ -66,12 +66,12 @@ describe('Abstract pool test suite', () => { }) it('Verify that filePath is checked', () => { - expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError( + expect(() => new FixedThreadPool(numberOfWorkers)).toThrow( new Error("Cannot find the worker file 'undefined'") ) expect( () => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts') - ).toThrowError(new Error("Cannot find the worker file './dummyWorker.ts'")) + ).toThrow(new Error("Cannot find the worker file './dummyWorker.ts'")) }) it('Verify that numberOfWorkers is checked', () => { @@ -81,7 +81,7 @@ describe('Abstract pool test suite', () => { undefined, './tests/worker-files/thread/testWorker.mjs' ) - ).toThrowError( + ).toThrow( new Error( 'Cannot instantiate a pool without specifying the number of workers' ) @@ -92,7 +92,7 @@ describe('Abstract pool test suite', () => { expect( () => new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js') - ).toThrowError( + ).toThrow( new RangeError( 'Cannot instantiate a pool with a negative number of workers' ) @@ -103,7 +103,7 @@ describe('Abstract pool test suite', () => { expect( () => new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.mjs') - ).toThrowError( + ).toThrow( new TypeError( 'Cannot instantiate a pool with a non safe integer number of workers' ) @@ -118,7 +118,7 @@ describe('Abstract pool test suite', () => { undefined, './tests/worker-files/cluster/testWorker.js' ) - ).toThrowError( + ).toThrow( new TypeError( 'Cannot instantiate a dynamic pool without specifying the maximum pool size' ) @@ -130,7 +130,7 @@ describe('Abstract pool test suite', () => { 1, './tests/worker-files/thread/testWorker.mjs' ) - ).toThrowError( + ).toThrow( new TypeError( 'Cannot instantiate a pool with a non safe integer number of workers' ) @@ -142,7 +142,7 @@ describe('Abstract pool test suite', () => { 0.5, './tests/worker-files/cluster/testWorker.js' ) - ).toThrowError( + ).toThrow( new TypeError( 'Cannot instantiate a dynamic pool with a non safe integer maximum pool size' ) @@ -154,7 +154,7 @@ describe('Abstract pool test suite', () => { 1, './tests/worker-files/thread/testWorker.mjs' ) - ).toThrowError( + ).toThrow( new RangeError( 'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size' ) @@ -166,7 +166,7 @@ describe('Abstract pool test suite', () => { 0, './tests/worker-files/thread/testWorker.mjs' ) - ).toThrowError( + ).toThrow( new RangeError( 'Cannot instantiate a dynamic pool with a maximum pool size equal to zero' ) @@ -178,7 +178,7 @@ describe('Abstract pool test suite', () => { 1, './tests/worker-files/cluster/testWorker.js' ) - ).toThrowError( + ).toThrow( new RangeError( 'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead' ) @@ -295,9 +295,7 @@ describe('Abstract pool test suite', () => { workerChoiceStrategy: 'invalidStrategy' } ) - ).toThrowError( - new Error("Invalid worker choice strategy 'invalidStrategy'") - ) + ).toThrow(new Error("Invalid worker choice strategy 'invalidStrategy'")) expect( () => new FixedThreadPool( @@ -309,7 +307,7 @@ describe('Abstract pool test suite', () => { } } ) - ).toThrowError( + ).toThrow( new TypeError( 'Invalid worker choice strategy options: retries must be an integer' ) @@ -325,7 +323,7 @@ describe('Abstract pool test suite', () => { } } ) - ).toThrowError( + ).toThrow( new RangeError( "Invalid worker choice strategy options: retries '-1' must be greater or equal than zero" ) @@ -339,7 +337,7 @@ describe('Abstract pool test suite', () => { workerChoiceStrategyOptions: { weights: {} } } ) - ).toThrowError( + ).toThrow( new Error( 'Invalid worker choice strategy options: must have a weight for each worker node' ) @@ -353,7 +351,7 @@ describe('Abstract pool test suite', () => { workerChoiceStrategyOptions: { measurement: 'invalidMeasurement' } } ) - ).toThrowError( + ).toThrow( new Error( "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'" ) @@ -368,7 +366,7 @@ describe('Abstract pool test suite', () => { tasksQueueOptions: 'invalidTasksQueueOptions' } ) - ).toThrowError( + ).toThrow( new TypeError('Invalid tasks queue options: must be a plain object') ) expect( @@ -381,7 +379,7 @@ describe('Abstract pool test suite', () => { tasksQueueOptions: { concurrency: 0 } } ) - ).toThrowError( + ).toThrow( new RangeError( 'Invalid worker node tasks concurrency: 0 is a negative integer or zero' ) @@ -396,7 +394,7 @@ describe('Abstract pool test suite', () => { tasksQueueOptions: { concurrency: -1 } } ) - ).toThrowError( + ).toThrow( new RangeError( 'Invalid worker node tasks concurrency: -1 is a negative integer or zero' ) @@ -411,7 +409,7 @@ describe('Abstract pool test suite', () => { tasksQueueOptions: { concurrency: 0.2 } } ) - ).toThrowError( + ).toThrow( new TypeError('Invalid worker node tasks concurrency: must be an integer') ) expect( @@ -424,7 +422,7 @@ describe('Abstract pool test suite', () => { tasksQueueOptions: { size: 0 } } ) - ).toThrowError( + ).toThrow( new RangeError( 'Invalid worker node tasks queue size: 0 is a negative integer or zero' ) @@ -439,7 +437,7 @@ describe('Abstract pool test suite', () => { tasksQueueOptions: { size: -1 } } ) - ).toThrowError( + ).toThrow( new RangeError( 'Invalid worker node tasks queue size: -1 is a negative integer or zero' ) @@ -454,7 +452,7 @@ describe('Abstract pool test suite', () => { tasksQueueOptions: { size: 0.2 } } ) - ).toThrowError( + ).toThrow( new TypeError('Invalid worker node tasks queue size: must be an integer') ) }) @@ -595,7 +593,7 @@ describe('Abstract pool test suite', () => { }) expect(() => pool.setWorkerChoiceStrategyOptions('invalidWorkerChoiceStrategyOptions') - ).toThrowError( + ).toThrow( new TypeError( 'Invalid worker choice strategy options: must be a plain object' ) @@ -604,28 +602,24 @@ describe('Abstract pool test suite', () => { pool.setWorkerChoiceStrategyOptions({ retries: 'invalidChoiceRetries' }) - ).toThrowError( + ).toThrow( new TypeError( 'Invalid worker choice strategy options: retries must be an integer' ) ) - expect(() => - pool.setWorkerChoiceStrategyOptions({ retries: -1 }) - ).toThrowError( + expect(() => pool.setWorkerChoiceStrategyOptions({ retries: -1 })).toThrow( new RangeError( "Invalid worker choice strategy options: retries '-1' must be greater or equal than zero" ) ) - expect(() => - pool.setWorkerChoiceStrategyOptions({ weights: {} }) - ).toThrowError( + expect(() => pool.setWorkerChoiceStrategyOptions({ weights: {} })).toThrow( new Error( 'Invalid worker choice strategy options: must have a weight for each worker node' ) ) expect(() => pool.setWorkerChoiceStrategyOptions({ measurement: 'invalidMeasurement' }) - ).toThrowError( + ).toThrow( new Error( "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'" ) @@ -734,35 +728,33 @@ describe('Abstract pool test suite', () => { expect(workerNode.onEmptyQueue).toBeInstanceOf(Function) expect(workerNode.onBackPressure).toBeInstanceOf(Function) } - expect(() => - pool.setTasksQueueOptions('invalidTasksQueueOptions') - ).toThrowError( + expect(() => pool.setTasksQueueOptions('invalidTasksQueueOptions')).toThrow( new TypeError('Invalid tasks queue options: must be a plain object') ) - expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrowError( + expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrow( new RangeError( 'Invalid worker node tasks concurrency: 0 is a negative integer or zero' ) ) - expect(() => pool.setTasksQueueOptions({ concurrency: -1 })).toThrowError( + expect(() => pool.setTasksQueueOptions({ concurrency: -1 })).toThrow( new RangeError( 'Invalid worker node tasks concurrency: -1 is a negative integer or zero' ) ) - expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrowError( + expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrow( new TypeError('Invalid worker node tasks concurrency: must be an integer') ) - expect(() => pool.setTasksQueueOptions({ size: 0 })).toThrowError( + expect(() => pool.setTasksQueueOptions({ size: 0 })).toThrow( new RangeError( 'Invalid worker node tasks queue size: 0 is a negative integer or zero' ) ) - expect(() => pool.setTasksQueueOptions({ size: -1 })).toThrowError( + expect(() => pool.setTasksQueueOptions({ size: -1 })).toThrow( new RangeError( 'Invalid worker node tasks queue size: -1 is a negative integer or zero' ) ) - expect(() => pool.setTasksQueueOptions({ size: 0.2 })).toThrowError( + expect(() => pool.setTasksQueueOptions({ size: 0.2 })).toThrow( new TypeError('Invalid worker node tasks queue size: must be an integer') ) await pool.destroy() @@ -918,7 +910,7 @@ describe('Abstract pool test suite', () => { expect(pool.info.started).toBe(false) expect(pool.info.ready).toBe(false) expect(pool.workerNodes).toStrictEqual([]) - await expect(pool.execute()).rejects.toThrowError( + await expect(pool.execute()).rejects.toThrow( new Error('Cannot execute a task on not started pool') ) pool.start() @@ -936,20 +928,20 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/testWorker.js' ) - await expect(pool.execute(undefined, 0)).rejects.toThrowError( + await expect(pool.execute(undefined, 0)).rejects.toThrow( new TypeError('name argument must be a string') ) - await expect(pool.execute(undefined, '')).rejects.toThrowError( + await expect(pool.execute(undefined, '')).rejects.toThrow( new TypeError('name argument must not be an empty string') ) - await expect(pool.execute(undefined, undefined, {})).rejects.toThrowError( + await expect(pool.execute(undefined, undefined, {})).rejects.toThrow( new TypeError('transferList argument must be an array') ) await expect(pool.execute(undefined, 'unknown')).rejects.toBe( "Task function 'unknown' not found" ) await pool.destroy() - await expect(pool.execute()).rejects.toThrowError( + await expect(pool.execute()).rejects.toThrow( new Error('Cannot execute a task on not started pool') ) }) @@ -1300,18 +1292,18 @@ describe('Abstract pool test suite', () => { await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1) await expect( dynamicThreadPool.addTaskFunction(0, () => {}) - ).rejects.toThrowError(new TypeError('name argument must be a string')) + ).rejects.toThrow(new TypeError('name argument must be a string')) await expect( dynamicThreadPool.addTaskFunction('', () => {}) - ).rejects.toThrowError( + ).rejects.toThrow( new TypeError('name argument must not be an empty string') ) - await expect( - dynamicThreadPool.addTaskFunction('test', 0) - ).rejects.toThrowError(new TypeError('fn argument must be a function')) - await expect( - dynamicThreadPool.addTaskFunction('test', '') - ).rejects.toThrowError(new TypeError('fn argument must be a function')) + await expect(dynamicThreadPool.addTaskFunction('test', 0)).rejects.toThrow( + new TypeError('fn argument must be a function') + ) + await expect(dynamicThreadPool.addTaskFunction('test', '')).rejects.toThrow( + new TypeError('fn argument must be a function') + ) expect(dynamicThreadPool.listTaskFunctionNames()).toStrictEqual([ DEFAULT_TASK_NAME, 'test' @@ -1373,9 +1365,7 @@ describe('Abstract pool test suite', () => { DEFAULT_TASK_NAME, 'test' ]) - await expect( - dynamicThreadPool.removeTaskFunction('test') - ).rejects.toThrowError( + await expect(dynamicThreadPool.removeTaskFunction('test')).rejects.toThrow( new Error('Cannot remove a task function not handled on the pool side') ) const echoTaskFunction = data => { @@ -1438,23 +1428,21 @@ describe('Abstract pool test suite', () => { './tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs' ) await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1) - await expect( - dynamicThreadPool.setDefaultTaskFunction(0) - ).rejects.toThrowError( + await expect(dynamicThreadPool.setDefaultTaskFunction(0)).rejects.toThrow( new Error( "Task function operation 'default' failed on worker 31 with error: 'TypeError: name parameter is not a string'" ) ) await expect( dynamicThreadPool.setDefaultTaskFunction(DEFAULT_TASK_NAME) - ).rejects.toThrowError( + ).rejects.toThrow( new Error( "Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function reserved name as the default task function'" ) ) await expect( dynamicThreadPool.setDefaultTaskFunction('unknown') - ).rejects.toThrowError( + ).rejects.toThrow( new Error( "Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function to a non-existing task function'" ) diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index 93dcc7fad..afc013f16 100644 --- a/tests/pools/cluster/dynamic.test.mjs +++ b/tests/pools/cluster/dynamic.test.mjs @@ -73,7 +73,7 @@ describe('Dynamic cluster pool test suite', () => { }) it('Validation of inputs test', () => { - expect(() => new DynamicClusterPool(min)).toThrowError( + expect(() => new DynamicClusterPool(min)).toThrow( "Cannot find the worker file 'undefined'" ) }) diff --git a/tests/pools/cluster/fixed.test.mjs b/tests/pools/cluster/fixed.test.mjs index 4471f5130..426a64f00 100644 --- a/tests/pools/cluster/fixed.test.mjs +++ b/tests/pools/cluster/fixed.test.mjs @@ -322,6 +322,6 @@ describe('Fixed cluster pool test suite', () => { expect( () => new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.js') - ).toThrowError('Cannot instantiate a fixed pool with zero worker') + ).toThrow('Cannot instantiate a fixed pool with zero worker') }) }) diff --git a/tests/pools/selection-strategies/selection-strategies.test.mjs b/tests/pools/selection-strategies/selection-strategies.test.mjs index e0eec68b7..601d66c82 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.mjs +++ b/tests/pools/selection-strategies/selection-strategies.test.mjs @@ -2300,6 +2300,6 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.mjs', { workerChoiceStrategy: 'UNKNOWN_STRATEGY' } ) - ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'") + ).toThrow("Invalid worker choice strategy 'UNKNOWN_STRATEGY'") }) }) diff --git a/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs b/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs index dc898e4ff..2a5f914e9 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs @@ -98,14 +98,14 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.workerChoiceStrategy, workerChoiceStrategyUndefinedStub ) - expect(() => workerChoiceStrategyContext.execute()).toThrowError( + expect(() => workerChoiceStrategyContext.execute()).toThrow( new Error('Worker node key chosen is null or undefined after 6 retries') ) workerChoiceStrategyContext.workerChoiceStrategies.set( workerChoiceStrategyContext.workerChoiceStrategy, workerChoiceStrategyNullStub ) - expect(() => workerChoiceStrategyContext.execute()).toThrowError( + expect(() => workerChoiceStrategyContext.execute()).toThrow( new Error('Worker node key chosen is null or undefined after 6 retries') ) }) diff --git a/tests/pools/thread/dynamic.test.mjs b/tests/pools/thread/dynamic.test.mjs index c31e141c0..4fcd2d1b0 100644 --- a/tests/pools/thread/dynamic.test.mjs +++ b/tests/pools/thread/dynamic.test.mjs @@ -73,7 +73,7 @@ describe('Dynamic thread pool test suite', () => { }) it('Validation of inputs test', () => { - expect(() => new DynamicThreadPool(min)).toThrowError( + expect(() => new DynamicThreadPool(min)).toThrow( "Cannot find the worker file 'undefined'" ) }) diff --git a/tests/pools/thread/fixed.test.mjs b/tests/pools/thread/fixed.test.mjs index fd7f59356..214913d4b 100644 --- a/tests/pools/thread/fixed.test.mjs +++ b/tests/pools/thread/fixed.test.mjs @@ -341,6 +341,6 @@ describe('Fixed thread pool test suite', () => { it('Verify that a pool with zero worker fails', () => { expect( () => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.mjs') - ).toThrowError('Cannot instantiate a fixed pool with zero worker') + ).toThrow('Cannot instantiate a fixed pool with zero worker') }) }) diff --git a/tests/pools/worker-node.test.mjs b/tests/pools/worker-node.test.mjs index a847e4fed..d524c464e 100644 --- a/tests/pools/worker-node.test.mjs +++ b/tests/pools/worker-node.test.mjs @@ -14,32 +14,32 @@ describe('Worker node test suite', () => { const clusterWorkerNode = new WorkerNode(clusterWorker, 12) it('Worker node instantiation', () => { - expect(() => new WorkerNode()).toThrowError( + expect(() => new WorkerNode()).toThrow( new TypeError('Cannot construct a worker node without a worker') ) - expect(() => new WorkerNode(threadWorker)).toThrowError( + expect(() => new WorkerNode(threadWorker)).toThrow( new TypeError( 'Cannot construct a worker node without a tasks queue back pressure size' ) ) expect( () => new WorkerNode(threadWorker, 'invalidTasksQueueBackPressureSize') - ).toThrowError( + ).toThrow( new TypeError( 'Cannot construct a worker node with a tasks queue back pressure size that is not an integer' ) ) - expect(() => new WorkerNode(threadWorker, 0.2)).toThrowError( + expect(() => new WorkerNode(threadWorker, 0.2)).toThrow( new TypeError( 'Cannot construct a worker node with a tasks queue back pressure size that is not an integer' ) ) - expect(() => new WorkerNode(threadWorker, 0)).toThrowError( + expect(() => new WorkerNode(threadWorker, 0)).toThrow( new RangeError( 'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer' ) ) - expect(() => new WorkerNode(threadWorker, -1)).toThrowError( + expect(() => new WorkerNode(threadWorker, -1)).toThrow( new RangeError( 'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer' ) @@ -134,7 +134,7 @@ describe('Worker node test suite', () => { it('Worker node getTaskFunctionWorkerUsage()', () => { expect(() => threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction') - ).toThrowError( + ).toThrow( new TypeError( "Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list is not yet defined" ) @@ -142,7 +142,7 @@ describe('Worker node test suite', () => { threadWorkerNode.info.taskFunctionNames = [DEFAULT_TASK_NAME, 'fn1'] expect(() => threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction') - ).toThrowError( + ).toThrow( new TypeError( "Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list has less than 3 elements" ) diff --git a/tests/worker/abstract-worker.test.mjs b/tests/worker/abstract-worker.test.mjs index 575e06513..4abbbeb1e 100644 --- a/tests/worker/abstract-worker.test.mjs +++ b/tests/worker/abstract-worker.test.mjs @@ -25,39 +25,35 @@ describe('Abstract worker test suite', () => { }) it('Verify that worker options are checked at worker creation', () => { - expect(() => new ClusterWorker(() => {}, '')).toThrowError( + expect(() => new ClusterWorker(() => {}, '')).toThrow( new TypeError('opts worker options parameter is not a plain object') ) - expect( - () => new ClusterWorker(() => {}, { killBehavior: '' }) - ).toThrowError(new TypeError("killBehavior option '' is not valid")) - expect(() => new ClusterWorker(() => {}, { killBehavior: 0 })).toThrowError( + expect(() => new ClusterWorker(() => {}, { killBehavior: '' })).toThrow( + new TypeError("killBehavior option '' is not valid") + ) + expect(() => new ClusterWorker(() => {}, { killBehavior: 0 })).toThrow( new TypeError("killBehavior option '0' is not valid") ) - expect( - () => new ThreadWorker(() => {}, { maxInactiveTime: '' }) - ).toThrowError(new TypeError('maxInactiveTime option is not an integer')) - expect( - () => new ThreadWorker(() => {}, { maxInactiveTime: 0.5 }) - ).toThrowError(new TypeError('maxInactiveTime option is not an integer')) - expect( - () => new ThreadWorker(() => {}, { maxInactiveTime: 0 }) - ).toThrowError( + expect(() => new ThreadWorker(() => {}, { maxInactiveTime: '' })).toThrow( + new TypeError('maxInactiveTime option is not an integer') + ) + expect(() => new ThreadWorker(() => {}, { maxInactiveTime: 0.5 })).toThrow( + new TypeError('maxInactiveTime option is not an integer') + ) + expect(() => new ThreadWorker(() => {}, { maxInactiveTime: 0 })).toThrow( new TypeError( 'maxInactiveTime option is not a positive integer greater or equal than 5' ) ) - expect( - () => new ThreadWorker(() => {}, { maxInactiveTime: 4 }) - ).toThrowError( + expect(() => new ThreadWorker(() => {}, { maxInactiveTime: 4 })).toThrow( new TypeError( 'maxInactiveTime option is not a positive integer greater or equal than 5' ) ) - expect(() => new ThreadWorker(() => {}, { killHandler: '' })).toThrowError( + expect(() => new ThreadWorker(() => {}, { killHandler: '' })).toThrow( new TypeError('killHandler option is not a function') ) - expect(() => new ThreadWorker(() => {}, { killHandler: 0 })).toThrowError( + expect(() => new ThreadWorker(() => {}, { killHandler: 0 })).toThrow( new TypeError('killHandler option is not a function') ) }) @@ -79,48 +75,48 @@ describe('Abstract worker test suite', () => { }) it('Verify that taskFunctions parameter is mandatory', () => { - expect(() => new ClusterWorker()).toThrowError( + expect(() => new ClusterWorker()).toThrow( new Error('taskFunctions parameter is mandatory') ) }) it('Verify that taskFunctions parameter is a function or a plain object', () => { - expect(() => new ClusterWorker(0)).toThrowError( + expect(() => new ClusterWorker(0)).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) ) - expect(() => new ClusterWorker('')).toThrowError( + expect(() => new ClusterWorker('')).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) ) - expect(() => new ClusterWorker(true)).toThrowError( + expect(() => new ClusterWorker(true)).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) ) - expect(() => new ClusterWorker([])).toThrowError( + expect(() => new ClusterWorker([])).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) ) - expect(() => new ClusterWorker(new Map())).toThrowError( + expect(() => new ClusterWorker(new Map())).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) ) - expect(() => new ClusterWorker(new Set())).toThrowError( + expect(() => new ClusterWorker(new Set())).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) ) - expect(() => new ClusterWorker(new WeakMap())).toThrowError( + expect(() => new ClusterWorker(new WeakMap())).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) ) - expect(() => new ClusterWorker(new WeakSet())).toThrowError( + expect(() => new ClusterWorker(new WeakSet())).toThrow( new TypeError( 'taskFunctions parameter is not a function or a plain object' ) @@ -128,7 +124,7 @@ describe('Abstract worker test suite', () => { }) it('Verify that taskFunctions parameter is not an empty object', () => { - expect(() => new ClusterWorker({})).toThrowError( + expect(() => new ClusterWorker({})).toThrow( new Error('taskFunctions parameter object is empty') ) }) @@ -148,10 +144,10 @@ describe('Abstract worker test suite', () => { return 1 } const fn2 = '' - expect(() => new ThreadWorker({ '': fn1 })).toThrowError( + expect(() => new ThreadWorker({ '': fn1 })).toThrow( new TypeError('A taskFunctions parameter object key is an empty string') ) - expect(() => new ThreadWorker({ fn1, fn2 })).toThrowError( + expect(() => new ThreadWorker({ fn1, fn2 })).toThrow( new TypeError('A taskFunctions parameter object value is not a function') ) }) @@ -186,7 +182,7 @@ describe('Abstract worker test suite', () => { it('Verify that getMainWorker() throw error if main worker is not set', () => { expect(() => new StubWorkerWithMainWorker(() => {}).getMainWorker() - ).toThrowError('Main worker not set') + ).toThrow('Main worker not set') }) it('Verify that hasTaskFunction() is working', () => {