From: Jérôme Benoit Date: Sat, 30 Sep 2023 09:15:04 +0000 (+0200) Subject: refactor: code cleanup X-Git-Tag: v2.7.5~18 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2eb1488903cf9551f65e987537aa6144f77b36c5;p=poolifier.git refactor: code cleanup Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 84212a3f..c7792d79 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -1,5 +1,7 @@ import { EventEmitterAsyncResource } from 'node:events' +import { dirname, join } from 'node:path' import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' import { expect } from 'expect' import { restore, stub } from 'sinon' import { @@ -19,7 +21,12 @@ import { waitPoolEvents } from '../test-utils.js' import { WorkerNode } from '../../lib/pools/worker-node.js' describe('Abstract pool test suite', () => { - const version = JSON.parse(readFileSync('./package.json', 'utf8')).version + const version = JSON.parse( + readFileSync( + join(dirname(fileURLToPath(import.meta.url)), '../../package.json'), + 'utf8' + ) + ).version const numberOfWorkers = 2 class StubPoolWithIsMain extends FixedThreadPool { isMain () { diff --git a/tests/test-utils.js b/tests/test-utils.js index 4478d290..3963adec 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -1,4 +1,4 @@ -const { TaskFunctions } = require('./test-types') +const { TaskFunctions } = require('./test-types.js') const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => { return await new Promise(resolve => { diff --git a/tests/worker-files/cluster/asyncErrorWorker.js b/tests/worker-files/cluster/asyncErrorWorker.js index 468a0ff9..f358fc3e 100644 --- a/tests/worker-files/cluster/asyncErrorWorker.js +++ b/tests/worker-files/cluster/asyncErrorWorker.js @@ -1,6 +1,6 @@ 'use strict' const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils') +const { sleepTaskFunction } = require('../../test-utils.js') async function error (data) { return sleepTaskFunction( diff --git a/tests/worker-files/cluster/asyncWorker.js b/tests/worker-files/cluster/asyncWorker.js index f07625bd..3ec0d950 100644 --- a/tests/worker-files/cluster/asyncWorker.js +++ b/tests/worker-files/cluster/asyncWorker.js @@ -1,6 +1,6 @@ 'use strict' const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils') +const { sleepTaskFunction } = require('../../test-utils.js') async function sleep (data) { return sleepTaskFunction(data, 2000) diff --git a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js b/tests/worker-files/cluster/longRunningWorkerHardBehavior.js index ee6b93cc..a95d6538 100644 --- a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js +++ b/tests/worker-files/cluster/longRunningWorkerHardBehavior.js @@ -1,6 +1,6 @@ 'use strict' const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils') +const { sleepTaskFunction } = require('../../test-utils.js') async function sleep (data) { return sleepTaskFunction(data, 50000) diff --git a/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js b/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js index cd057ef0..0459acf7 100644 --- a/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js +++ b/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js @@ -1,6 +1,6 @@ 'use strict' const { ClusterWorker } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils') +const { sleepTaskFunction } = require('../../test-utils.js') async function sleep (data) { return sleepTaskFunction(data, 50000) diff --git a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js index aecd5bbf..0777cecb 100644 --- a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js +++ b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js @@ -4,7 +4,7 @@ const { jsonIntegerSerialization, factorial, fibonacci -} = require('../../test-utils') +} = require('../../test-utils.js') module.exports = new ClusterWorker( { diff --git a/tests/worker-files/cluster/testWorker.js b/tests/worker-files/cluster/testWorker.js index 4511bcaa..57715266 100644 --- a/tests/worker-files/cluster/testWorker.js +++ b/tests/worker-files/cluster/testWorker.js @@ -1,7 +1,7 @@ 'use strict' const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { executeTaskFunction } = require('../../test-utils') -const { TaskFunctions } = require('../../test-types') +const { executeTaskFunction } = require('../../test-utils.js') +const { TaskFunctions } = require('../../test-types.js') function test (data) { data = data || {} diff --git a/tests/worker-files/thread/asyncErrorWorker.mjs b/tests/worker-files/thread/asyncErrorWorker.mjs index ff16bb6a..c7c9371c 100644 --- a/tests/worker-files/thread/asyncErrorWorker.mjs +++ b/tests/worker-files/thread/asyncErrorWorker.mjs @@ -4,6 +4,7 @@ import { sleepTaskFunction } from '../../test-utils.js' /** * * @param data + * @returns */ async function error (data) { return sleepTaskFunction( diff --git a/tests/worker-files/thread/asyncWorker.mjs b/tests/worker-files/thread/asyncWorker.mjs index 4c52783f..30442bfc 100644 --- a/tests/worker-files/thread/asyncWorker.mjs +++ b/tests/worker-files/thread/asyncWorker.mjs @@ -4,6 +4,7 @@ import { sleepTaskFunction } from '../../test-utils.js' /** * * @param data + * @returns */ async function sleep (data) { return sleepTaskFunction(data, 2000) diff --git a/tests/worker-files/thread/echoWorker.mjs b/tests/worker-files/thread/echoWorker.mjs index 0b9251cb..04b6c996 100644 --- a/tests/worker-files/thread/echoWorker.mjs +++ b/tests/worker-files/thread/echoWorker.mjs @@ -3,6 +3,7 @@ import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' /** * * @param data + * @returns */ function echo (data) { return data diff --git a/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs b/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs index 911ddb9f..01cf3c0e 100644 --- a/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs +++ b/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs @@ -4,6 +4,7 @@ import { sleepTaskFunction } from '../../test-utils.js' /** * * @param data + * @returns */ async function sleep (data) { return sleepTaskFunction(data, 50000) diff --git a/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs b/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs index 6441a183..9083e1d1 100644 --- a/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs +++ b/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs @@ -4,6 +4,7 @@ import { sleepTaskFunction } from '../../test-utils.js' /** * * @param data + * @returns */ async function sleep (data) { return sleepTaskFunction(data, 50000) diff --git a/tests/worker-files/thread/testWorker.mjs b/tests/worker-files/thread/testWorker.mjs index e2c67067..618a9ac0 100644 --- a/tests/worker-files/thread/testWorker.mjs +++ b/tests/worker-files/thread/testWorker.mjs @@ -5,6 +5,7 @@ import { TaskFunctions } from '../../test-types.js' /** * * @param data + * @returns */ function test (data) { data = data || {}