From a074ffee1b46f43d0dcfba58128748c7492104dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 30 Sep 2023 00:12:35 +0200 Subject: [PATCH] test: switch to ESM MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package.json | 4 +- ...-array.test.js => circular-array.test.mjs} | 6 +- tests/{deque.test.js => deque.test.mjs} | 4 +- ...ct-pool.test.js => abstract-pool.test.mjs} | 27 +++++---- .../{dynamic.test.js => dynamic.test.mjs} | 8 +-- .../cluster/{fixed.test.js => fixed.test.mjs} | 10 ++-- ....test.js => selection-strategies.test.mjs} | 8 +-- ...und-robin-worker-choice-strategy.test.mjs} | 14 ++--- ...> worker-choice-strategy-context.test.mjs} | 60 +++++++------------ .../{dynamic.test.js => dynamic.test.mjs} | 8 +-- .../thread/{fixed.test.js => fixed.test.mjs} | 10 ++-- tests/pools/{utils.test.js => utils.test.mjs} | 12 ++-- ...rker-node.test.js => worker-node.test.mjs} | 16 ++--- tests/{utils.test.js => utils.test.mjs} | 18 +++--- ...orker.test.js => abstract-worker.test.mjs} | 22 +++---- ...worker.test.js => cluster-worker.test.mjs} | 4 +- ...-worker.test.js => thread-worker.test.mjs} | 4 +- 17 files changed, 109 insertions(+), 126 deletions(-) rename tests/{circular-array.test.js => circular-array.test.mjs} (98%) rename tests/{deque.test.js => deque.test.mjs} (98%) rename tests/pools/{abstract-pool.test.js => abstract-pool.test.mjs} (98%) rename tests/pools/cluster/{dynamic.test.js => dynamic.test.mjs} (95%) rename tests/pools/cluster/{fixed.test.js => fixed.test.mjs} (97%) rename tests/pools/selection-strategies/{selection-strategies.test.js => selection-strategies.test.mjs} (99%) rename tests/pools/selection-strategies/{weighted-round-robin-worker-choice-strategy.test.js => weighted-round-robin-worker-choice-strategy.test.mjs} (70%) rename tests/pools/selection-strategies/{worker-choice-strategy-context.test.js => worker-choice-strategy-context.test.mjs} (89%) rename tests/pools/thread/{dynamic.test.js => dynamic.test.mjs} (95%) rename tests/pools/thread/{fixed.test.js => fixed.test.mjs} (97%) rename tests/pools/{utils.test.js => utils.test.mjs} (91%) rename tests/pools/{worker-node.test.js => worker-node.test.mjs} (94%) rename tests/{utils.test.js => utils.test.mjs} (96%) rename tests/worker/{abstract-worker.test.js => abstract-worker.test.mjs} (96%) rename tests/worker/{cluster-worker.test.js => cluster-worker.test.mjs} (83%) rename tests/worker/{thread-worker.test.js => thread-worker.test.mjs} (90%) diff --git a/package.json b/package.json index 4fab7713..d5bef2c8 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "benchmark": "pnpm build && node -r source-map-support/register benchmarks/internal/bench.mjs", "benchmark:debug": "pnpm build && node -r source-map-support/register --inspect benchmarks/internal/bench.mjs", "benchmark:prod": "pnpm build:prod && node benchmarks/internal/bench.mjs", - "test": "pnpm build --environment SOURCEMAP:false && c8 mocha 'tests/**/*.test.js'", - "test:debug": "pnpm build && mocha --no-parallel --inspect 'tests/**/*.test.js'", + "test": "pnpm build --environment SOURCEMAP:false && c8 mocha 'tests/**/*.test.mjs'", + "test:debug": "pnpm build && mocha --no-parallel --inspect 'tests/**/*.test.mjs'", "coverage": "c8 report --reporter=lcov", "coverage:html": "c8 report --reporter=html", "format": "biome format . --write; ts-standard . --fix", diff --git a/tests/circular-array.test.js b/tests/circular-array.test.mjs similarity index 98% rename from tests/circular-array.test.js rename to tests/circular-array.test.mjs index fa87a310..0e13a8c3 100644 --- a/tests/circular-array.test.js +++ b/tests/circular-array.test.mjs @@ -1,8 +1,8 @@ -const { expect } = require('expect') -const { +import { expect } from 'expect' +import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE -} = require('../lib/circular-array') +} from '../lib/circular-array.js' describe('Circular array test suite', () => { it('Verify that circular array can be instantiated', () => { diff --git a/tests/deque.test.js b/tests/deque.test.mjs similarity index 98% rename from tests/deque.test.js rename to tests/deque.test.mjs index 73e54590..6c8ebbb1 100644 --- a/tests/deque.test.js +++ b/tests/deque.test.mjs @@ -1,5 +1,5 @@ -const { expect } = require('expect') -const { Deque } = require('../lib/deque') +import { expect } from 'expect' +import { Deque } from '../lib/deque.js' describe('Deque test suite', () => { it('Verify push() behavior', () => { diff --git a/tests/pools/abstract-pool.test.js b/tests/pools/abstract-pool.test.mjs similarity index 98% rename from tests/pools/abstract-pool.test.js rename to tests/pools/abstract-pool.test.mjs index e6572cc1..09a21c9d 100644 --- a/tests/pools/abstract-pool.test.js +++ b/tests/pools/abstract-pool.test.mjs @@ -1,7 +1,8 @@ -const { EventEmitterAsyncResource } = require('node:events') -const { expect } = require('expect') -const sinon = require('sinon') -const { +import { EventEmitterAsyncResource } from 'node:events' +import { readFileSync } from 'node:fs' +import { expect } from 'expect' +import { restore, stub } from 'sinon' +import { DynamicClusterPool, DynamicThreadPool, FixedClusterPool, @@ -10,15 +11,15 @@ const { PoolTypes, WorkerChoiceStrategies, WorkerTypes -} = require('../../lib') -const { CircularArray } = require('../../lib/circular-array') -const { Deque } = require('../../lib/deque') -const { DEFAULT_TASK_NAME } = require('../../lib/utils') -const { version } = require('../../package.json') -const { waitPoolEvents } = require('../test-utils') -const { WorkerNode } = require('../../lib/pools/worker-node') +} from '../../lib/index.js' +import { CircularArray } from '../../lib/circular-array.js' +import { Deque } from '../../lib/deque.js' +import { DEFAULT_TASK_NAME } from '../../lib/utils.js' +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 numberOfWorkers = 2 class StubPoolWithIsMain extends FixedThreadPool { isMain () { @@ -27,7 +28,7 @@ describe('Abstract pool test suite', () => { } afterEach(() => { - sinon.restore() + restore() }) it('Simulate pool creation from a non main thread/process', () => { @@ -1218,7 +1219,7 @@ describe('Abstract pool test suite', () => { enableTasksQueue: true } ) - sinon.stub(pool, 'hasBackPressure').returns(true) + stub(pool, 'hasBackPressure').returns(true) expect(pool.emitter.eventNames()).toStrictEqual([]) const promises = new Set() let poolBackPressure = 0 diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.mjs similarity index 95% rename from tests/pools/cluster/dynamic.test.js rename to tests/pools/cluster/dynamic.test.mjs index 1e729eae..edd96390 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.mjs @@ -1,7 +1,7 @@ -const { expect } = require('expect') -const { DynamicClusterPool, PoolEvents } = require('../../../lib') -const { TaskFunctions } = require('../../test-types') -const { sleep, waitWorkerEvents } = require('../../test-utils') +import { expect } from 'expect' +import { DynamicClusterPool, PoolEvents } from '../../../lib/index.js' +import { TaskFunctions } from '../../test-types.js' +import { sleep, waitWorkerEvents } from '../../test-utils.js' describe('Dynamic cluster pool test suite', () => { const min = 1 diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.mjs similarity index 97% rename from tests/pools/cluster/fixed.test.js rename to tests/pools/cluster/fixed.test.mjs index 9b79f6ed..7d829f32 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.mjs @@ -1,8 +1,8 @@ -const { expect } = require('expect') -const { FixedClusterPool, PoolEvents } = require('../../../lib') -const { TaskFunctions } = require('../../test-types') -const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils') -const { DEFAULT_TASK_NAME } = require('../../../lib/utils') +import { expect } from 'expect' +import { FixedClusterPool, PoolEvents } from '../../../lib/index.js' +import { TaskFunctions } from '../../test-types.js' +import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.js' +import { DEFAULT_TASK_NAME } from '../../../lib/utils.js' describe('Fixed cluster pool test suite', () => { const numberOfWorkers = 8 diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.mjs similarity index 99% rename from tests/pools/selection-strategies/selection-strategies.test.js rename to tests/pools/selection-strategies/selection-strategies.test.mjs index 3329e1dc..342d2fa6 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.mjs @@ -1,12 +1,12 @@ -const { expect } = require('expect') -const { +import { expect } from 'expect' +import { DynamicClusterPool, DynamicThreadPool, FixedClusterPool, FixedThreadPool, WorkerChoiceStrategies -} = require('../../../lib') -const { CircularArray } = require('../../../lib/circular-array') +} from '../../../lib/index.js' +import { CircularArray } from '../../../lib/circular-array.js' describe('Selection strategies test suite', () => { const min = 0 diff --git a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs similarity index 70% rename from tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js rename to tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs index d774bce8..c659b31e 100644 --- a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js +++ b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs @@ -1,10 +1,8 @@ -const { expect } = require('expect') -const sinon = require('sinon') -const { FixedThreadPool } = require('../../../lib') -const { - WeightedRoundRobinWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') -const { generateRandomInteger } = require('../../test-utils') +import { expect } from 'expect' +import { restore } from 'sinon' +import { FixedThreadPool } from '../../../lib/index.js' +import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js' +import { generateRandomInteger } from '../../test-utils.js' describe('Weighted round robin strategy worker choice strategy test suite', () => { // const min = 1 @@ -16,7 +14,7 @@ describe('Weighted round robin strategy worker choice strategy test suite', () = }) afterEach(() => { - sinon.restore() + restore() }) after(async () => { diff --git a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js b/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs similarity index 89% rename from tests/pools/selection-strategies/worker-choice-strategy-context.test.js rename to tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs index df8cd25c..f9b1c8d5 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs @@ -1,34 +1,18 @@ -const { expect } = require('expect') -const sinon = require('sinon') -const { - FixedThreadPool, +import { expect } from 'expect' +import { createStubInstance, restore, stub } from 'sinon' +import { DynamicThreadPool, + FixedThreadPool, WorkerChoiceStrategies -} = require('../../../lib') -const { - WorkerChoiceStrategyContext -} = require('../../../lib/pools/selection-strategies/worker-choice-strategy-context') -const { - RoundRobinWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy') -const { - LeastUsedWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/least-used-worker-choice-strategy') -const { - LeastBusyWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy') -const { - LeastEluWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy') -const { - FairShareWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy') -const { - WeightedRoundRobinWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') -const { - InterleavedWeightedRoundRobinWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy') +} from '../../../lib/index.js' +import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.js' +import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.js' +import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.js' +import { LeastBusyWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy.js' +import { LeastEluWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy.js' +import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.js' +import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js' +import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.js' describe('Worker choice strategy context test suite', () => { const min = 1 @@ -48,7 +32,7 @@ describe('Worker choice strategy context test suite', () => { }) afterEach(() => { - sinon.restore() + restore() }) after(async () => { @@ -69,10 +53,10 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) - const WorkerChoiceStrategyStub = sinon.createStubInstance( + const WorkerChoiceStrategyStub = createStubInstance( RoundRobinWorkerChoiceStrategy, { - choose: sinon.stub().returns(0) + choose: stub().returns(0) } ) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( @@ -95,16 +79,16 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) - const WorkerChoiceStrategyUndefinedStub = sinon.createStubInstance( + const WorkerChoiceStrategyUndefinedStub = createStubInstance( RoundRobinWorkerChoiceStrategy, { - choose: sinon.stub().returns(undefined) + choose: stub().returns(undefined) } ) - const WorkerChoiceStrategyNullStub = sinon.createStubInstance( + const WorkerChoiceStrategyNullStub = createStubInstance( RoundRobinWorkerChoiceStrategy, { - choose: sinon.stub().returns(null) + choose: stub().returns(null) } ) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( @@ -130,10 +114,10 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) - const WorkerChoiceStrategyStub = sinon.createStubInstance( + const WorkerChoiceStrategyStub = createStubInstance( RoundRobinWorkerChoiceStrategy, { - choose: sinon.stub().returns(0) + choose: stub().returns(0) } ) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.mjs similarity index 95% rename from tests/pools/thread/dynamic.test.js rename to tests/pools/thread/dynamic.test.mjs index 1c5997cc..0a608a01 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.mjs @@ -1,7 +1,7 @@ -const { expect } = require('expect') -const { DynamicThreadPool, PoolEvents } = require('../../../lib') -const { TaskFunctions } = require('../../test-types') -const { sleep, waitWorkerEvents } = require('../../test-utils') +import { expect } from 'expect' +import { DynamicThreadPool, PoolEvents } from '../../../lib/index.js' +import { TaskFunctions } from '../../test-types.js' +import { sleep, waitWorkerEvents } from '../../test-utils.js' describe('Dynamic thread pool test suite', () => { const min = 1 diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.mjs similarity index 97% rename from tests/pools/thread/fixed.test.js rename to tests/pools/thread/fixed.test.mjs index acd94406..a1cb8dd2 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.mjs @@ -1,8 +1,8 @@ -const { expect } = require('expect') -const { FixedThreadPool, PoolEvents } = require('../../../lib') -const { TaskFunctions } = require('../../test-types') -const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils') -const { DEFAULT_TASK_NAME } = require('../../../lib/utils') +import { expect } from 'expect' +import { FixedThreadPool, PoolEvents } from '../../../lib/index.js' +import { TaskFunctions } from '../../test-types.js' +import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.js' +import { DEFAULT_TASK_NAME } from '../../../lib/utils.js' describe('Fixed thread pool test suite', () => { const numberOfThreads = 6 diff --git a/tests/pools/utils.test.js b/tests/pools/utils.test.mjs similarity index 91% rename from tests/pools/utils.test.js rename to tests/pools/utils.test.mjs index 23ef2e2f..bf0c72af 100644 --- a/tests/pools/utils.test.js +++ b/tests/pools/utils.test.mjs @@ -1,9 +1,9 @@ -const { expect } = require('expect') -const { - DEFAULT_CIRCULAR_ARRAY_SIZE, - CircularArray -} = require('../../lib/circular-array') -const { updateMeasurementStatistics } = require('../../lib/pools/utils') +import { expect } from 'expect' +import { + CircularArray, + DEFAULT_CIRCULAR_ARRAY_SIZE +} from '../../lib/circular-array.js' +import { updateMeasurementStatistics } from '../../lib/pools/utils.js' describe('Pool utils test suite', () => { it('Verify updateMeasurementStatistics() behavior', () => { diff --git a/tests/pools/worker-node.test.js b/tests/pools/worker-node.test.mjs similarity index 94% rename from tests/pools/worker-node.test.js rename to tests/pools/worker-node.test.mjs index bfbd5d8d..0780db25 100644 --- a/tests/pools/worker-node.test.js +++ b/tests/pools/worker-node.test.mjs @@ -1,11 +1,11 @@ -const { MessageChannel, Worker } = require('node:worker_threads') -const cluster = require('node:cluster') -const { expect } = require('expect') -const { WorkerNode } = require('../../lib/pools/worker-node') -const { WorkerTypes } = require('../../lib') -const { CircularArray } = require('../../lib/circular-array') -const { Deque } = require('../../lib/deque') -const { DEFAULT_TASK_NAME } = require('../../lib/utils') +import { MessageChannel, Worker } from 'node:worker_threads' +import cluster from 'node:cluster' +import { expect } from 'expect' +import { WorkerNode } from '../../lib/pools/worker-node.js' +import { WorkerTypes } from '../../lib/index.js' +import { CircularArray } from '../../lib/circular-array.js' +import { Deque } from '../../lib/deque.js' +import { DEFAULT_TASK_NAME } from '../../lib/utils.js' describe('Worker node test suite', () => { const threadWorker = new Worker('./tests/worker-files/thread/testWorker.js') diff --git a/tests/utils.test.js b/tests/utils.test.mjs similarity index 96% rename from tests/utils.test.js rename to tests/utils.test.mjs index 061c1648..74c53a16 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.mjs @@ -1,9 +1,9 @@ -const { randomInt } = require('node:crypto') -const { Worker } = require('node:worker_threads') -const cluster = require('node:cluster') -const os = require('node:os') -const { expect } = require('expect') -const { +import { Worker } from 'node:worker_threads' +import cluster from 'node:cluster' +import os from 'node:os' +import { randomInt } from 'node:crypto' +import { expect } from 'expect' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, DEFAULT_TASK_NAME, DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS, @@ -11,8 +11,8 @@ const { availableParallelism, average, exponentialDelay, - getWorkerType, getWorkerId, + getWorkerType, isAsyncFunction, isKillBehavior, isPlainObject, @@ -22,8 +22,8 @@ const { round, secureRandom, sleep -} = require('../lib/utils') -const { KillBehaviors, WorkerTypes } = require('../lib') +} from '../lib/utils.js' +import { KillBehaviors, WorkerTypes } from '../lib/index.js' describe('Utils test suite', () => { it('Verify DEFAULT_TASK_NAME value', () => { diff --git a/tests/worker/abstract-worker.test.js b/tests/worker/abstract-worker.test.mjs similarity index 96% rename from tests/worker/abstract-worker.test.js rename to tests/worker/abstract-worker.test.mjs index 1b055217..9058790b 100644 --- a/tests/worker/abstract-worker.test.js +++ b/tests/worker/abstract-worker.test.mjs @@ -1,7 +1,7 @@ -const { expect } = require('expect') -const sinon = require('sinon') -const { ClusterWorker, KillBehaviors, ThreadWorker } = require('../../lib') -const { DEFAULT_TASK_NAME, EMPTY_FUNCTION } = require('../../lib/utils') +import { expect } from 'expect' +import { restore, stub } from 'sinon' +import { ClusterWorker, KillBehaviors, ThreadWorker } from '../../lib/index.js' +import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../lib/utils.js' describe('Abstract worker test suite', () => { class StubWorkerWithMainWorker extends ThreadWorker { @@ -12,7 +12,7 @@ describe('Abstract worker test suite', () => { } afterEach(() => { - sinon.restore() + restore() }) it('Verify worker options default values', () => { @@ -178,12 +178,12 @@ describe('Abstract worker test suite', () => { it('Verify that sync kill handler is called when worker is killed', () => { const worker = new ClusterWorker(() => {}, { - killHandler: sinon.stub().returns() + killHandler: stub().returns() }) worker.isMain = false - worker.getMainWorker = sinon.stub().returns({ + worker.getMainWorker = stub().returns({ id: 1, - send: sinon.stub().returns() + send: stub().returns() }) worker.handleKillMessage() expect(worker.getMainWorker().send.calledOnce).toBe(true) @@ -191,7 +191,7 @@ describe('Abstract worker test suite', () => { }) it('Verify that async kill handler is called when worker is killed', () => { - const killHandlerStub = sinon.stub().returns() + const killHandlerStub = stub().returns() const worker = new ClusterWorker(() => {}, { killHandler: async () => Promise.resolve(killHandlerStub()) }) @@ -308,9 +308,9 @@ describe('Abstract worker test suite', () => { status: false, error: new TypeError('name parameter is an empty string') }) - worker.getMainWorker = sinon.stub().returns({ + worker.getMainWorker = stub().returns({ id: 1, - send: sinon.stub().returns() + send: stub().returns() }) expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Function) expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function) diff --git a/tests/worker/cluster-worker.test.js b/tests/worker/cluster-worker.test.mjs similarity index 83% rename from tests/worker/cluster-worker.test.js rename to tests/worker/cluster-worker.test.mjs index f857412b..ea6a0481 100644 --- a/tests/worker/cluster-worker.test.js +++ b/tests/worker/cluster-worker.test.mjs @@ -1,5 +1,5 @@ -const { expect } = require('expect') -const { ClusterWorker } = require('../../lib') +import { expect } from 'expect' +import { ClusterWorker } from '../../lib/index.js' describe('Cluster worker test suite', () => { let numberOfMessagesSent = 0 diff --git a/tests/worker/thread-worker.test.js b/tests/worker/thread-worker.test.mjs similarity index 90% rename from tests/worker/thread-worker.test.js rename to tests/worker/thread-worker.test.mjs index 495e10b1..8b6f9c79 100644 --- a/tests/worker/thread-worker.test.js +++ b/tests/worker/thread-worker.test.mjs @@ -1,5 +1,5 @@ -const { expect } = require('expect') -const { ThreadWorker } = require('../../lib') +import { expect } from 'expect' +import { ThreadWorker } from '../../lib/index.js' describe('Thread worker test suite', () => { let numberOfMessagesPosted = 0 -- 2.34.1