From d35e571704515a8b729d3455e4784054f07c368f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 27 Dec 2023 12:21:55 +0100 Subject: [PATCH] build: switch default to ESM MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintrc.js => .eslintrc.cjs | 8 ++-- .lintstagedrc.js | 2 +- README.md | 6 +-- ...nchmarks-types.js => benchmarks-types.cjs} | 0 ...nchmarks-utils.js => benchmarks-utils.cjs} | 8 ++-- benchmarks/internal/bench.mjs | 4 +- .../{cluster-worker.js => cluster-worker.cjs} | 6 +-- benchmarks/internal/thread-worker.mjs | 4 +- benchmarks/worker-selection/least.mjs | 2 +- benchmarks/worker-selection/round-robin.mjs | 2 +- commitlint.config.js | 2 +- .../{dynamicExample.js => dynamicExample.cjs} | 0 .../{fixedExample.js => fixedExample.cjs} | 2 +- ...ionExample.js => multiFunctionExample.cjs} | 2 +- ...ctionWorker.js => multiFunctionWorker.cjs} | 0 .../{yourWorker.js => yourWorker.cjs} | 0 examples/typescript/pool.ts | 2 +- package.json | 5 +- rollup.config.mjs | 4 +- src/index.ts | 48 +++++++++---------- src/pools/abstract-pool.ts | 22 ++++----- src/pools/cluster/dynamic.ts | 6 +-- src/pools/cluster/fixed.ts | 8 ++-- src/pools/pool.ts | 6 +-- .../abstract-worker-choice-strategy.ts | 8 ++-- .../fair-share-worker-choice-strategy.ts | 10 ++-- ...hted-round-robin-worker-choice-strategy.ts | 10 ++-- .../least-busy-worker-choice-strategy.ts | 10 ++-- .../least-elu-worker-choice-strategy.ts | 10 ++-- .../least-used-worker-choice-strategy.ts | 8 ++-- .../round-robin-worker-choice-strategy.ts | 8 ++-- ...hted-round-robin-worker-choice-strategy.ts | 10 ++-- .../worker-choice-strategy-context.ts | 24 +++++----- src/pools/thread/dynamic.ts | 6 +-- src/pools/thread/fixed.ts | 8 ++-- src/pools/utils.ts | 12 ++--- src/pools/worker-node.ts | 12 ++--- src/pools/worker.ts | 4 +- src/utility-types.ts | 2 +- src/utils.ts | 6 +-- src/worker/abstract-worker.ts | 10 ++-- src/worker/cluster-worker.ts | 8 ++-- src/worker/thread-worker.ts | 8 ++-- src/worker/utils.ts | 6 +-- tests/circular-array.test.mjs | 2 +- tests/deque.test.mjs | 2 +- tests/pools/abstract-pool.test.mjs | 48 +++++++++---------- tests/pools/cluster/dynamic.test.mjs | 16 +++---- tests/pools/cluster/fixed.test.mjs | 32 ++++++------- .../selection-strategies.test.mjs | 8 ++-- ...ound-robin-worker-choice-strategy.test.mjs | 6 +-- .../worker-choice-strategy-context.test.mjs | 18 +++---- tests/pools/thread/dynamic.test.mjs | 6 +-- tests/pools/thread/fixed.test.mjs | 8 ++-- tests/pools/utils.test.mjs | 6 +-- tests/pools/worker-node.test.mjs | 12 ++--- tests/{test-types.js => test-types.cjs} | 0 tests/{test-utils.js => test-utils.cjs} | 2 +- tests/utils.test.mjs | 4 +- ...yncErrorWorker.js => asyncErrorWorker.cjs} | 4 +- .../{asyncWorker.js => asyncWorker.cjs} | 4 +- .../cluster/{echoWorker.js => echoWorker.cjs} | 2 +- .../{emptyWorker.js => emptyWorker.cjs} | 2 +- .../{errorWorker.js => errorWorker.cjs} | 2 +- ...r.js => longRunningWorkerHardBehavior.cjs} | 4 +- ...r.js => longRunningWorkerSoftBehavior.cjs} | 4 +- ...js => testMultipleTaskFunctionsWorker.cjs} | 4 +- .../cluster/{testWorker.js => testWorker.cjs} | 6 +-- .../worker-files/thread/asyncErrorWorker.mjs | 4 +- tests/worker-files/thread/asyncWorker.mjs | 4 +- tests/worker-files/thread/echoWorker.mjs | 2 +- tests/worker-files/thread/emptyWorker.mjs | 2 +- tests/worker-files/thread/errorWorker.mjs | 2 +- .../thread/longRunningWorkerHardBehavior.mjs | 4 +- .../thread/longRunningWorkerSoftBehavior.mjs | 4 +- .../testMultipleTaskFunctionsWorker.mjs | 4 +- tests/worker-files/thread/testWorker.mjs | 6 +-- tests/worker/abstract-worker.test.mjs | 4 +- tests/worker/cluster-worker.test.mjs | 4 +- tests/worker/thread-worker.test.mjs | 4 +- 80 files changed, 288 insertions(+), 287 deletions(-) rename .eslintrc.js => .eslintrc.cjs (95%) rename benchmarks/{benchmarks-types.js => benchmarks-types.cjs} (100%) rename benchmarks/{benchmarks-utils.js => benchmarks-utils.cjs} (97%) rename benchmarks/internal/{cluster-worker.js => cluster-worker.cjs} (67%) rename examples/javascript/{dynamicExample.js => dynamicExample.cjs} (100%) rename examples/javascript/{fixedExample.js => fixedExample.cjs} (98%) rename examples/javascript/{multiFunctionExample.js => multiFunctionExample.cjs} (94%) rename examples/javascript/{multiFunctionWorker.js => multiFunctionWorker.cjs} (100%) rename examples/javascript/{yourWorker.js => yourWorker.cjs} (100%) rename tests/{test-types.js => test-types.cjs} (100%) rename tests/{test-utils.js => test-utils.cjs} (98%) rename tests/worker-files/cluster/{asyncErrorWorker.js => asyncErrorWorker.cjs} (65%) rename tests/worker-files/cluster/{asyncWorker.js => asyncWorker.cjs} (58%) rename tests/worker-files/cluster/{echoWorker.js => echoWorker.cjs} (64%) rename tests/worker-files/cluster/{emptyWorker.js => emptyWorker.cjs} (65%) rename tests/worker-files/cluster/{errorWorker.js => errorWorker.cjs} (72%) rename tests/worker-files/cluster/{longRunningWorkerHardBehavior.js => longRunningWorkerHardBehavior.cjs} (58%) rename tests/worker-files/cluster/{longRunningWorkerSoftBehavior.js => longRunningWorkerSoftBehavior.cjs} (56%) rename tests/worker-files/cluster/{testMultipleTaskFunctionsWorker.js => testMultipleTaskFunctionsWorker.cjs} (75%) rename tests/worker-files/cluster/{testWorker.js => testWorker.cjs} (58%) diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 95% rename from .eslintrc.js rename to .eslintrc.cjs index c1e571d5..85ae204a 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -155,24 +155,24 @@ module.exports = defineConfig({ } }, { - files: ['**/*.js', '**/*.mjs'], + files: ['**/*.cjs', '**/*.mjs'], plugins: ['jsdoc'], extends: ['plugin:n/recommended', 'plugin:jsdoc/recommended', 'standard'] }, { - files: ['tests/**/*.js', 'tests/**/*.mjs'], + files: ['tests/**/*.cjs', 'tests/**/*.mjs'], rules: { 'jsdoc/require-jsdoc': 'off' } }, { - files: ['benchmarks/**/*.js', 'benchmarks/**/*.mjs'], + files: ['benchmarks/**/*.cjs', 'benchmarks/**/*.mjs'], rules: { 'jsdoc/require-jsdoc': 'off' } }, { - files: ['examples/javascript/**/*.js'], + files: ['examples/javascript/**/*.cjs'], rules: { 'jsdoc/require-jsdoc': 'off' } diff --git a/.lintstagedrc.js b/.lintstagedrc.js index 361afe3d..1886925b 100644 --- a/.lintstagedrc.js +++ b/.lintstagedrc.js @@ -1,4 +1,4 @@ -module.exports = { +export default { '**/*.{ts,tsx,js,jsx,cjs,mjs}': [ 'biome format --write', 'ts-standard --fix', diff --git a/README.md b/README.md index 68e9fe65..8cea8d62 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,7 @@ npm install poolifier --save You can implement a [worker_threads](https://nodejs.org/api/worker_threads.html#class-worker) worker in a simple way by extending the class _ThreadWorker_: ```js -'use strict' -const { ThreadWorker } = require('poolifier') +import { ThreadWorker } from 'poolifier' function yourFunction(data) { // this will be executed in the worker thread, @@ -107,8 +106,7 @@ module.exports = new ThreadWorker(yourFunction, { Instantiate your pool based on your needs : ```js -'use strict' -const { DynamicThreadPool, FixedThreadPool, PoolEvents, availableParallelism } = require('poolifier') +import { DynamicThreadPool, FixedThreadPool, PoolEvents, availableParallelism } from 'poolifier' // a fixed worker_threads pool const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', { diff --git a/benchmarks/benchmarks-types.js b/benchmarks/benchmarks-types.cjs similarity index 100% rename from benchmarks/benchmarks-types.js rename to benchmarks/benchmarks-types.cjs diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.cjs similarity index 97% rename from benchmarks/benchmarks-utils.js rename to benchmarks/benchmarks-utils.cjs index a0a42b95..e9491098 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.cjs @@ -17,8 +17,8 @@ const { PoolTypes, WorkerChoiceStrategies, WorkerTypes -} = require('../lib/index.js') -const { TaskFunctions } = require('./benchmarks-types.js') +} = require('../lib/index.cjs') +const { TaskFunctions } = require('./benchmarks-types.cjs') const buildPoolifierPool = (workerType, poolType, poolSize, poolOptions) => { switch (poolType) { @@ -33,7 +33,7 @@ const buildPoolifierPool = (workerType, poolType, poolSize, poolOptions) => { case WorkerTypes.cluster: return new FixedClusterPool( poolSize, - './benchmarks/internal/cluster-worker.js', + './benchmarks/internal/cluster-worker.cjs', poolOptions ) } @@ -51,7 +51,7 @@ const buildPoolifierPool = (workerType, poolType, poolSize, poolOptions) => { return new DynamicClusterPool( Math.floor(poolSize / 2), poolSize, - './benchmarks/internal/cluster-worker.js', + './benchmarks/internal/cluster-worker.cjs', poolOptions ) } diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 5ea11e18..88868af7 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -4,8 +4,8 @@ import { WorkerTypes, availableParallelism } from '../../lib/index.mjs' -import { TaskFunctions } from '../benchmarks-types.js' -import { runPoolifierPoolBenchmark } from '../benchmarks-utils.js' +import { TaskFunctions } from '../benchmarks-types.cjs' +import { runPoolifierPoolBenchmark } from '../benchmarks-utils.cjs' const poolSize = availableParallelism() const taskExecutions = 1 diff --git a/benchmarks/internal/cluster-worker.js b/benchmarks/internal/cluster-worker.cjs similarity index 67% rename from benchmarks/internal/cluster-worker.js rename to benchmarks/internal/cluster-worker.cjs index 18bd648c..94980725 100644 --- a/benchmarks/internal/cluster-worker.js +++ b/benchmarks/internal/cluster-worker.cjs @@ -1,7 +1,7 @@ const { isPrimary } = require('node:cluster') -const { ClusterWorker } = require('../../lib') -const { executeTaskFunction } = require('../benchmarks-utils.js') -const { TaskFunctions } = require('../benchmarks-types.js') +const { ClusterWorker } = require('../../lib/index.cjs') +const { executeTaskFunction } = require('../benchmarks-utils.cjs') +const { TaskFunctions } = require('../benchmarks-types.cjs') const taskFunction = data => { data = data || {} diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index b0994e77..92508dd8 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -1,7 +1,7 @@ import { isMainThread } from 'node:worker_threads' import { ThreadWorker } from '../../lib/index.mjs' -import { executeTaskFunction } from '../benchmarks-utils.js' -import { TaskFunctions } from '../benchmarks-types.js' +import { executeTaskFunction } from '../benchmarks-utils.cjs' +import { TaskFunctions } from '../benchmarks-types.cjs' const taskFunction = data => { data = data || {} diff --git a/benchmarks/worker-selection/least.mjs b/benchmarks/worker-selection/least.mjs index 0969369f..6dd91df0 100644 --- a/benchmarks/worker-selection/least.mjs +++ b/benchmarks/worker-selection/least.mjs @@ -1,5 +1,5 @@ import Benchmark from 'benchmark' -import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.js' +import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.cjs' function generateRandomTasksMap ( numberOfWorkers, diff --git a/benchmarks/worker-selection/round-robin.mjs b/benchmarks/worker-selection/round-robin.mjs index 302cd2c6..b13c8111 100644 --- a/benchmarks/worker-selection/round-robin.mjs +++ b/benchmarks/worker-selection/round-robin.mjs @@ -1,5 +1,5 @@ import Benchmark from 'benchmark' -import { LIST_FORMATTER } from '../benchmarks-utils.js' +import { LIST_FORMATTER } from '../benchmarks-utils.cjs' function generateWorkersArray (numberOfWorkers) { return [...Array(numberOfWorkers).keys()] diff --git a/commitlint.config.js b/commitlint.config.js index 4fedde6d..7c4ff4d9 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1 @@ -module.exports = { extends: ['@commitlint/config-conventional'] } +export default { extends: ['@commitlint/config-conventional'] } diff --git a/examples/javascript/dynamicExample.js b/examples/javascript/dynamicExample.cjs similarity index 100% rename from examples/javascript/dynamicExample.js rename to examples/javascript/dynamicExample.cjs diff --git a/examples/javascript/fixedExample.js b/examples/javascript/fixedExample.cjs similarity index 98% rename from examples/javascript/fixedExample.js rename to examples/javascript/fixedExample.cjs index 55ed724d..38e0c8af 100644 --- a/examples/javascript/fixedExample.js +++ b/examples/javascript/fixedExample.cjs @@ -5,7 +5,7 @@ const { availableParallelism } = require('poolifier') -const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', { +const pool = new FixedThreadPool(availableParallelism(), './yourWorker.cjs', { errorHandler: e => console.error(e), onlineHandler: () => console.info('worker is online') }) diff --git a/examples/javascript/multiFunctionExample.js b/examples/javascript/multiFunctionExample.cjs similarity index 94% rename from examples/javascript/multiFunctionExample.js rename to examples/javascript/multiFunctionExample.cjs index 9667be3d..7ab57ab7 100644 --- a/examples/javascript/multiFunctionExample.js +++ b/examples/javascript/multiFunctionExample.cjs @@ -3,7 +3,7 @@ const { FixedThreadPool, availableParallelism } = require('poolifier') const pool = new FixedThreadPool( availableParallelism(), - './multiFunctionWorker.js', + './multiFunctionWorker.cjs', { errorHandler: e => console.error(e), onlineHandler: () => console.info('worker is online') diff --git a/examples/javascript/multiFunctionWorker.js b/examples/javascript/multiFunctionWorker.cjs similarity index 100% rename from examples/javascript/multiFunctionWorker.js rename to examples/javascript/multiFunctionWorker.cjs diff --git a/examples/javascript/yourWorker.js b/examples/javascript/yourWorker.cjs similarity index 100% rename from examples/javascript/yourWorker.js rename to examples/javascript/yourWorker.cjs diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index de49c93a..57898d98 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -1,6 +1,6 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import type { MyData, MyResponse } from './worker' +import type { MyData, MyResponse } from './worker.js' import { DynamicThreadPool, FixedThreadPool, diff --git a/package.json b/package.json index 983fda59..6eb05ce4 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,12 @@ "version": "3.1.11", "description": "Fast and small Node.js Worker_Threads and Cluster Worker Pool", "license": "MIT", - "main": "./lib/index.js", + "type": "module", + "main": "./lib/index.cjs", "exports": { ".": { "types": "./lib/index.d.ts", - "require": "./lib/index.js", + "require": "./lib/index.cjs", "import": "./lib/index.mjs" } }, diff --git a/rollup.config.mjs b/rollup.config.mjs index d4af3f3f..26739f65 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -37,11 +37,13 @@ export default defineConfig([ format: 'cjs', ...(isDevelopmentBuild && { dir: './lib', + entryFileNames: '[name].cjs', + chunkFileNames: '[name]-[hash].cjs', preserveModules: true, preserveModulesRoot: './src' }), ...(!isDevelopmentBuild && { - file: './lib/index.js', + file: './lib/index.cjs', plugins: [terser({ maxWorkers })] }), ...(sourcemap && { diff --git a/src/index.ts b/src/index.ts index 880fdcba..0a9ab8f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ -export type { AbstractPool } from './pools/abstract-pool' -export { DynamicClusterPool } from './pools/cluster/dynamic' -export { FixedClusterPool } from './pools/cluster/fixed' -export type { ClusterPoolOptions } from './pools/cluster/fixed' -export { PoolEvents, PoolTypes } from './pools/pool' +export type { AbstractPool } from './pools/abstract-pool.js' +export { DynamicClusterPool } from './pools/cluster/dynamic.js' +export { FixedClusterPool } from './pools/cluster/fixed.js' +export type { ClusterPoolOptions } from './pools/cluster/fixed.js' +export { PoolEvents, PoolTypes } from './pools/pool.js' export type { IPool, PoolEvent, @@ -10,8 +10,8 @@ export type { PoolOptions, PoolType, TasksQueueOptions -} from './pools/pool' -export { WorkerTypes } from './pools/worker' +} from './pools/pool.js' +export { WorkerTypes } from './pools/worker.js' export type { ErrorHandler, EventLoopUtilizationMeasurementStatistics, @@ -28,11 +28,11 @@ export type { WorkerNodeOptions, WorkerType, WorkerUsage -} from './pools/worker' +} from './pools/worker.js' export { Measurements, WorkerChoiceStrategies -} from './pools/selection-strategies/selection-strategies-types' +} from './pools/selection-strategies/selection-strategies-types.js' export type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions, @@ -43,27 +43,27 @@ export type { TaskStatisticsRequirements, WorkerChoiceStrategy, WorkerChoiceStrategyOptions -} from './pools/selection-strategies/selection-strategies-types' -export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context' -export { DynamicThreadPool } from './pools/thread/dynamic' -export { FixedThreadPool } from './pools/thread/fixed' -export type { ThreadPoolOptions } from './pools/thread/fixed' -export type { AbstractWorker } from './worker/abstract-worker' -export { ClusterWorker } from './worker/cluster-worker' -export { ThreadWorker } from './worker/thread-worker' -export { KillBehaviors } from './worker/worker-options' +} from './pools/selection-strategies/selection-strategies-types.js' +export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context.js' +export { DynamicThreadPool } from './pools/thread/dynamic.js' +export { FixedThreadPool } from './pools/thread/fixed.js' +export type { ThreadPoolOptions } from './pools/thread/fixed.js' +export type { AbstractWorker } from './worker/abstract-worker.js' +export { ClusterWorker } from './worker/cluster-worker.js' +export { ThreadWorker } from './worker/thread-worker.js' +export { KillBehaviors } from './worker/worker-options.js' export type { KillBehavior, KillHandler, WorkerOptions -} from './worker/worker-options' +} from './worker/worker-options.js' export type { TaskAsyncFunction, TaskFunction, TaskFunctionOperationResult, TaskFunctions, TaskSyncFunction -} from './worker/task-functions' +} from './worker/task-functions.js' export type { MessageValue, PromiseResponseWrapper, @@ -72,7 +72,7 @@ export type { WorkerError, WorkerStatistics, Writable -} from './utility-types' -export type { CircularArray } from './circular-array' -export type { Deque, Node } from './deque' -export { availableParallelism } from './utils' +} from './utility-types.js' +export type { CircularArray } from './circular-array.js' +export type { Deque, Node } from './deque.js' +export { availableParallelism } from './utils.js' diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 7b18d355..e210fa0f 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -7,7 +7,7 @@ import type { MessageValue, PromiseResponseWrapper, Task -} from '../utility-types' +} from '../utility-types.js' import { DEFAULT_TASK_NAME, EMPTY_FUNCTION, @@ -20,9 +20,9 @@ import { min, round, sleep -} from '../utils' -import { KillBehaviors } from '../worker/worker-options' -import type { TaskFunction } from '../worker/task-functions' +} from '../utils.js' +import { KillBehaviors } from '../worker/worker-options.js' +import type { TaskFunction } from '../worker/task-functions.js' import { type IPool, PoolEvents, @@ -31,7 +31,7 @@ import { type PoolType, PoolTypes, type TasksQueueOptions -} from './pool' +} from './pool.js' import type { IWorker, IWorkerNode, @@ -40,16 +40,16 @@ import type { WorkerNodeEventDetail, WorkerType, WorkerUsage -} from './worker' +} from './worker.js' import { Measurements, WorkerChoiceStrategies, type WorkerChoiceStrategy, type WorkerChoiceStrategyOptions -} from './selection-strategies/selection-strategies-types' -import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context' -import { version } from './version' -import { WorkerNode } from './worker-node' +} from './selection-strategies/selection-strategies-types.js' +import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js' +import { version } from './version.js' +import { WorkerNode } from './worker-node.js' import { checkFilePath, checkValidTasksQueueOptions, @@ -60,7 +60,7 @@ import { updateTaskStatisticsWorkerUsage, updateWaitTimeWorkerUsage, waitWorkerNodeEvents -} from './utils' +} from './utils.js' /** * Base class that implements some shared logic for all poolifier pools. diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 08ebc75c..311d5c9d 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -1,6 +1,6 @@ -import { checkDynamicPoolSize } from '../utils' -import { PoolEvents, type PoolType, PoolTypes } from '../pool' -import { type ClusterPoolOptions, FixedClusterPool } from './fixed' +import { checkDynamicPoolSize } from '../utils.js' +import { PoolEvents, type PoolType, PoolTypes } from '../pool.js' +import { type ClusterPoolOptions, FixedClusterPool } from './fixed.js' /** * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers. diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 63f129f6..3b45dc17 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -1,8 +1,8 @@ import cluster, { type Worker } from 'node:cluster' -import type { MessageValue } from '../../utility-types' -import { AbstractPool } from '../abstract-pool' -import { type PoolOptions, type PoolType, PoolTypes } from '../pool' -import { type WorkerType, WorkerTypes } from '../worker' +import type { MessageValue } from '../../utility-types.js' +import { AbstractPool } from '../abstract-pool.js' +import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js' +import { type WorkerType, WorkerTypes } from '../worker.js' /** * Options for a poolifier cluster pool. diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 08aad620..546f67b7 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -1,7 +1,7 @@ import type { TransferListItem, WorkerOptions } from 'node:worker_threads' import type { EventEmitterAsyncResource } from 'node:events' import type { ClusterSettings } from 'node:cluster' -import type { TaskFunction } from '../worker/task-functions' +import type { TaskFunction } from '../worker/task-functions.js' import type { ErrorHandler, ExitHandler, @@ -10,11 +10,11 @@ import type { MessageHandler, OnlineHandler, WorkerType -} from './worker' +} from './worker.js' import type { WorkerChoiceStrategy, WorkerChoiceStrategyOptions -} from './selection-strategies/selection-strategies-types' +} from './selection-strategies/selection-strategies-types.js' /** * Enumeration of pool types. diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index d91f3c69..49b7c584 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -1,16 +1,16 @@ import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, buildInternalWorkerChoiceStrategyOptions -} from '../../utils' -import type { IPool } from '../pool' -import type { IWorker } from '../worker' +} from '../../utils.js' +import type { IPool } from '../pool.js' +import type { IWorker } from '../worker.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions, MeasurementStatisticsRequirements, StrategyPolicy, TaskStatisticsRequirements -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Worker choice strategy abstract base class. diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index aff4e73d..c6b87ade 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -1,13 +1,13 @@ -import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils' -import type { IPool } from '../pool' -import type { IWorker, StrategyData } from '../worker' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js' +import type { IPool } from '../pool.js' +import type { IWorker, StrategyData } from '../worker.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import { type IWorkerChoiceStrategy, type InternalWorkerChoiceStrategyOptions, Measurements, type TaskStatisticsRequirements -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the next worker with a fair share scheduling algorithm. diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index b11f0a17..db439f02 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -1,12 +1,12 @@ -import type { IWorker } from '../worker' -import type { IPool } from '../pool' -import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import type { IWorker } from '../worker.js' +import type { IPool } from '../pool.js' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions, TaskStatisticsRequirements -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the next worker with an interleaved weighted round robin scheduling algorithm. diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index a37f91d4..d800c383 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -1,12 +1,12 @@ -import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils' -import type { IPool } from '../pool' -import type { IWorker } from '../worker' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js' +import type { IPool } from '../pool.js' +import type { IWorker } from '../worker.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions, TaskStatisticsRequirements -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the least busy worker. diff --git a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts index d81f2064..81d108a3 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -1,12 +1,12 @@ -import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils' -import type { IPool } from '../pool' -import type { IWorker } from '../worker' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js' +import type { IPool } from '../pool.js' +import type { IWorker } from '../worker.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions, TaskStatisticsRequirements -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the worker with the least ELU. diff --git a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts index 6318affe..c1a4a6ac 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -1,10 +1,10 @@ -import type { IPool } from '../pool' -import type { IWorker } from '../worker' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import type { IPool } from '../pool.js' +import type { IWorker } from '../worker.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the least used worker. diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 2d08cff2..34c4f596 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -1,10 +1,10 @@ -import type { IPool } from '../pool' -import type { IWorker } from '../worker' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import type { IPool } from '../pool.js' +import type { IWorker } from '../worker.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the next worker in a round robin fashion. diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 5338b320..4b7eac7a 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -1,12 +1,12 @@ -import type { IWorker } from '../worker' -import type { IPool } from '../pool' -import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import type { IWorker } from '../worker.js' +import type { IPool } from '../pool.js' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions, TaskStatisticsRequirements -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the next worker with a weighted round robin scheduling algorithm. diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index 9a015347..d76ee8af 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -1,21 +1,21 @@ -import { buildInternalWorkerChoiceStrategyOptions } from '../../utils' -import type { IPool } from '../pool' -import type { IWorker } from '../worker' -import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy' -import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from './interleaved-weighted-round-robin-worker-choice-strategy' -import { LeastBusyWorkerChoiceStrategy } from './least-busy-worker-choice-strategy' -import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy' -import { LeastEluWorkerChoiceStrategy } from './least-elu-worker-choice-strategy' -import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy' +import { buildInternalWorkerChoiceStrategyOptions } from '../../utils.js' +import type { IPool } from '../pool.js' +import type { IWorker } from '../worker.js' +import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy.js' +import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from './interleaved-weighted-round-robin-worker-choice-strategy.js' +import { LeastBusyWorkerChoiceStrategy } from './least-busy-worker-choice-strategy.js' +import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy.js' +import { LeastEluWorkerChoiceStrategy } from './least-elu-worker-choice-strategy.js' +import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, InternalWorkerChoiceStrategyOptions, StrategyPolicy, TaskStatisticsRequirements, WorkerChoiceStrategy -} from './selection-strategies-types' -import { WorkerChoiceStrategies } from './selection-strategies-types' -import { WeightedRoundRobinWorkerChoiceStrategy } from './weighted-round-robin-worker-choice-strategy' +} from './selection-strategies-types.js' +import { WorkerChoiceStrategies } from './selection-strategies-types.js' +import { WeightedRoundRobinWorkerChoiceStrategy } from './weighted-round-robin-worker-choice-strategy.js' /** * The worker choice strategy context. diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index d3764c28..2fc36081 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -1,6 +1,6 @@ -import { PoolEvents, type PoolType, PoolTypes } from '../pool' -import { checkDynamicPoolSize } from '../utils' -import { FixedThreadPool, type ThreadPoolOptions } from './fixed' +import { PoolEvents, type PoolType, PoolTypes } from '../pool.js' +import { checkDynamicPoolSize } from '../utils.js' +import { FixedThreadPool, type ThreadPoolOptions } from './fixed.js' /** * A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads. diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index f48d0bcd..11a24e27 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -5,10 +5,10 @@ import { type Worker, isMainThread } from 'node:worker_threads' -import type { MessageValue } from '../../utility-types' -import { AbstractPool } from '../abstract-pool' -import { type PoolOptions, type PoolType, PoolTypes } from '../pool' -import { type WorkerType, WorkerTypes } from '../worker' +import type { MessageValue } from '../../utility-types.js' +import { AbstractPool } from '../abstract-pool.js' +import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js' +import { type WorkerType, WorkerTypes } from '../worker.js' /** * Options for a poolifier thread pool. diff --git a/src/pools/utils.ts b/src/pools/utils.ts index 619e2061..99584d85 100644 --- a/src/pools/utils.ts +++ b/src/pools/utils.ts @@ -2,14 +2,14 @@ import { existsSync } from 'node:fs' import cluster from 'node:cluster' import { SHARE_ENV, Worker, type WorkerOptions } from 'node:worker_threads' import { env } from 'node:process' -import { average, isPlainObject, max, median, min } from '../utils' -import type { MessageValue, Task } from '../utility-types' +import { average, isPlainObject, max, median, min } from '../utils.js' +import type { MessageValue, Task } from '../utility-types.js' import { type MeasurementStatisticsRequirements, WorkerChoiceStrategies, type WorkerChoiceStrategy -} from './selection-strategies/selection-strategies-types' -import type { TasksQueueOptions } from './pool' +} from './selection-strategies/selection-strategies-types.js' +import type { TasksQueueOptions } from './pool.js' import { type IWorker, type IWorkerNode, @@ -18,8 +18,8 @@ import { type WorkerType, WorkerTypes, type WorkerUsage -} from './worker' -import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context' +} from './worker.js' +import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js' export const getDefaultTasksQueueOptions = ( poolMaxSize: number diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index d2397676..bf2600d5 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -1,9 +1,9 @@ import { MessageChannel } from 'node:worker_threads' import { EventEmitter } from 'node:events' -import { CircularArray } from '../circular-array' -import type { Task } from '../utility-types' -import { DEFAULT_TASK_NAME, getWorkerId, getWorkerType } from '../utils' -import { Deque } from '../deque' +import { CircularArray } from '../circular-array.js' +import type { Task } from '../utility-types.js' +import { DEFAULT_TASK_NAME, getWorkerId, getWorkerType } from '../utils.js' +import { Deque } from '../deque.js' import { type ErrorHandler, type ExitHandler, @@ -17,8 +17,8 @@ import { type WorkerType, WorkerTypes, type WorkerUsage -} from './worker' -import { checkWorkerNodeArguments, createWorker } from './utils' +} from './worker.js' +import { checkWorkerNodeArguments, createWorker } from './utils.js' /** * Worker node. diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 9c8b77fc..c7a9dcb3 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -1,7 +1,7 @@ import type { MessageChannel, WorkerOptions } from 'node:worker_threads' import type { EventEmitter } from 'node:events' -import type { CircularArray } from '../circular-array' -import type { Task } from '../utility-types' +import type { CircularArray } from '../circular-array.js' +import type { Task } from '../utility-types.js' /** * Callback invoked when the worker has started successfully. diff --git a/src/utility-types.ts b/src/utility-types.ts index 5d2376cc..e407309a 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -1,7 +1,7 @@ import type { EventLoopUtilization } from 'node:perf_hooks' import type { MessagePort, TransferListItem } from 'node:worker_threads' import type { AsyncResource } from 'node:async_hooks' -import type { KillBehavior } from './worker/worker-options' +import type { KillBehavior } from './worker/worker-options.js' /** * Worker error. diff --git a/src/utils.ts b/src/utils.ts index f7aab637..7d6309d5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,9 +6,9 @@ import { cpus } from 'node:os' import type { InternalWorkerChoiceStrategyOptions, MeasurementStatisticsRequirements -} from './pools/selection-strategies/selection-strategies-types' -import type { KillBehavior } from './worker/worker-options' -import { type IWorker, type WorkerType, WorkerTypes } from './pools/worker' +} from './pools/selection-strategies/selection-strategies-types.js' +import type { KillBehavior } from './worker/worker-options.js' +import { type IWorker, type WorkerType, WorkerTypes } from './pools/worker.js' /** * Default task name. diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index e2b16e25..81523d8c 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -6,26 +6,26 @@ import type { Task, TaskPerformance, WorkerStatistics -} from '../utility-types' +} from '../utility-types.js' import { DEFAULT_TASK_NAME, EMPTY_FUNCTION, isAsyncFunction, isPlainObject -} from '../utils' -import { KillBehaviors, type WorkerOptions } from './worker-options' +} from '../utils.js' +import { KillBehaviors, type WorkerOptions } from './worker-options.js' import type { TaskAsyncFunction, TaskFunction, TaskFunctionOperationResult, TaskFunctions, TaskSyncFunction -} from './task-functions' +} from './task-functions.js' import { checkTaskFunctionName, checkValidTaskFunctionEntry, checkValidWorkerOptions -} from './utils' +} from './utils.js' const DEFAULT_MAX_INACTIVE_TIME = 60000 const DEFAULT_WORKER_OPTIONS: WorkerOptions = { diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index d972692e..fa810c7e 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -1,8 +1,8 @@ import cluster, { type Worker } from 'node:cluster' -import type { MessageValue } from '../utility-types' -import { AbstractWorker } from './abstract-worker' -import type { WorkerOptions } from './worker-options' -import type { TaskFunction, TaskFunctions } from './task-functions' +import type { MessageValue } from '../utility-types.js' +import { AbstractWorker } from './abstract-worker.js' +import type { WorkerOptions } from './worker-options.js' +import type { TaskFunction, TaskFunctions } from './task-functions.js' /** * A cluster worker used by a poolifier `ClusterPool`. diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index bc143a1f..2a50249f 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -4,10 +4,10 @@ import { parentPort, threadId } from 'node:worker_threads' -import type { MessageValue } from '../utility-types' -import { AbstractWorker } from './abstract-worker' -import type { WorkerOptions } from './worker-options' -import type { TaskFunction, TaskFunctions } from './task-functions' +import type { MessageValue } from '../utility-types.js' +import { AbstractWorker } from './abstract-worker.js' +import type { WorkerOptions } from './worker-options.js' +import type { TaskFunction, TaskFunctions } from './task-functions.js' /** * A thread worker used by a poolifier `ThreadPool`. diff --git a/src/worker/utils.ts b/src/worker/utils.ts index e023cc37..b9372401 100644 --- a/src/worker/utils.ts +++ b/src/worker/utils.ts @@ -1,6 +1,6 @@ -import { isPlainObject } from '../utils' -import type { TaskFunction } from './task-functions' -import { KillBehaviors, type WorkerOptions } from './worker-options' +import { isPlainObject } from '../utils.js' +import type { TaskFunction } from './task-functions.js' +import { KillBehaviors, type WorkerOptions } from './worker-options.js' export const checkValidWorkerOptions = (opts: WorkerOptions): void => { if (opts != null && !isPlainObject(opts)) { diff --git a/tests/circular-array.test.mjs b/tests/circular-array.test.mjs index dfa1b53c..ed069045 100644 --- a/tests/circular-array.test.mjs +++ b/tests/circular-array.test.mjs @@ -2,7 +2,7 @@ import { expect } from 'expect' import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE -} from '../lib/circular-array.js' +} from '../lib/circular-array.cjs' describe('Circular array test suite', () => { it('Verify that circular array can be instantiated', () => { diff --git a/tests/deque.test.mjs b/tests/deque.test.mjs index 6c8ebbb1..91ae5987 100644 --- a/tests/deque.test.mjs +++ b/tests/deque.test.mjs @@ -1,5 +1,5 @@ import { expect } from 'expect' -import { Deque } from '../lib/deque.js' +import { Deque } from '../lib/deque.cjs' describe('Deque test suite', () => { it('Verify push() behavior', () => { diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index cf4b55af..a1022261 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -14,12 +14,12 @@ import { PoolTypes, WorkerChoiceStrategies, 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' -import { waitPoolEvents } from '../test-utils.js' -import { WorkerNode } from '../../lib/pools/worker-node.js' +} from '../../lib/index.cjs' +import { CircularArray } from '../../lib/circular-array.cjs' +import { Deque } from '../../lib/deque.cjs' +import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' +import { waitPoolEvents } from '../test-utils.cjs' +import { WorkerNode } from '../../lib/pools/worker-node.cjs' describe('Abstract pool test suite', () => { const version = JSON.parse( @@ -105,7 +105,7 @@ describe('Abstract pool test suite', () => { it('Verify that a negative number of workers is checked', () => { expect( () => - new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js') + new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.cjs') ).toThrow( new RangeError( 'Cannot instantiate a pool with a negative number of workers' @@ -146,7 +146,7 @@ describe('Abstract pool test suite', () => { new DynamicClusterPool( 1, undefined, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) ).toThrow( new TypeError( @@ -170,7 +170,7 @@ describe('Abstract pool test suite', () => { new DynamicClusterPool( 0, 0.5, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) ).toThrow( new TypeError( @@ -206,7 +206,7 @@ describe('Abstract pool test suite', () => { new DynamicClusterPool( 1, 1, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) ).toThrow( new RangeError( @@ -788,7 +788,7 @@ describe('Abstract pool test suite', () => { pool = new DynamicClusterPool( Math.floor(numberOfWorkers / 2), numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) expect(pool.info).toStrictEqual({ version, @@ -812,7 +812,7 @@ describe('Abstract pool test suite', () => { it('Verify that pool worker tasks usage are initialized', async () => { const pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) for (const workerNode of pool.workerNodes) { expect(workerNode).toBeInstanceOf(WorkerNode) @@ -848,7 +848,7 @@ describe('Abstract pool test suite', () => { it('Verify that pool worker tasks queue are initialized', async () => { let pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) for (const workerNode of pool.workerNodes) { expect(workerNode).toBeInstanceOf(WorkerNode) @@ -874,7 +874,7 @@ describe('Abstract pool test suite', () => { it('Verify that pool worker info are initialized', async () => { let pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) for (const workerNode of pool.workerNodes) { expect(workerNode).toBeInstanceOf(WorkerNode) @@ -926,7 +926,7 @@ describe('Abstract pool test suite', () => { it('Verify that pool can be started after initialization', async () => { const pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { startWorkers: false } @@ -953,7 +953,7 @@ describe('Abstract pool test suite', () => { it('Verify that pool execute() arguments are checked', async () => { const pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) await expect(pool.execute(undefined, 0)).rejects.toThrow( new TypeError('name argument must be a string') @@ -976,7 +976,7 @@ describe('Abstract pool test suite', () => { it('Verify that pool worker tasks usage are computed', async () => { const pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) const promises = new Set() const maxMultiplier = 2 @@ -1127,7 +1127,7 @@ describe('Abstract pool test suite', () => { const pool = new DynamicClusterPool( Math.floor(numberOfWorkers / 2), numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) expect(pool.emitter.eventNames()).toStrictEqual([]) let poolInfo @@ -1396,7 +1396,7 @@ describe('Abstract pool test suite', () => { await dynamicThreadPool.destroy() const fixedClusterPool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js' + './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs' ) await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1) expect(fixedClusterPool.hasTaskFunction(DEFAULT_TASK_NAME)).toBe(true) @@ -1536,7 +1536,7 @@ describe('Abstract pool test suite', () => { await dynamicThreadPool.destroy() const fixedClusterPool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js' + './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs' ) await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1) expect(fixedClusterPool.listTaskFunctionNames()).toStrictEqual([ @@ -1606,7 +1606,7 @@ describe('Abstract pool test suite', () => { const pool = new DynamicClusterPool( Math.floor(numberOfWorkers / 2), numberOfWorkers, - './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js' + './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs' ) const data = { n: 10 } const result0 = await pool.execute(data) @@ -1671,7 +1671,7 @@ describe('Abstract pool test suite', () => { const pool = new DynamicClusterPool( Math.floor(numberOfWorkers / 2), numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) const workerNodeKey = 0 await expect( @@ -1684,7 +1684,7 @@ describe('Abstract pool test suite', () => { const pool = new DynamicClusterPool( Math.floor(numberOfWorkers / 2), numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) const workerNodeKey = 0 await expect( @@ -1704,7 +1704,7 @@ describe('Abstract pool test suite', () => { const pool = new DynamicClusterPool( Math.floor(numberOfWorkers / 2), numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) await expect( pool.sendTaskFunctionOperationToWorkers({ diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index 2a654b6a..8c9196d1 100644 --- a/tests/pools/cluster/dynamic.test.mjs +++ b/tests/pools/cluster/dynamic.test.mjs @@ -1,7 +1,7 @@ import { expect } from 'expect' -import { DynamicClusterPool, PoolEvents } from '../../../lib/index.js' -import { TaskFunctions } from '../../test-types.js' -import { sleep, waitWorkerEvents } from '../../test-utils.js' +import { DynamicClusterPool, PoolEvents } from '../../../lib/index.cjs' +import { TaskFunctions } from '../../test-types.cjs' +import { sleep, waitWorkerEvents } from '../../test-utils.cjs' describe('Dynamic cluster pool test suite', () => { const min = 1 @@ -9,7 +9,7 @@ describe('Dynamic cluster pool test suite', () => { const pool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { errorHandler: e => console.error(e) } @@ -84,7 +84,7 @@ describe('Dynamic cluster pool test suite', () => { const pool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) const result = await pool.execute() expect(result).toStrictEqual({ ok: 1 }) @@ -96,7 +96,7 @@ describe('Dynamic cluster pool test suite', () => { const longRunningPool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/longRunningWorkerHardBehavior.js', + './tests/worker-files/cluster/longRunningWorkerHardBehavior.cjs', { errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), @@ -123,7 +123,7 @@ describe('Dynamic cluster pool test suite', () => { const longRunningPool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js', + './tests/worker-files/cluster/longRunningWorkerSoftBehavior.cjs', { errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), @@ -146,7 +146,7 @@ describe('Dynamic cluster pool test suite', () => { const pool = new DynamicClusterPool( 0, max, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) expect(pool).toBeInstanceOf(DynamicClusterPool) // We need to clean up the resources after our test diff --git a/tests/pools/cluster/fixed.test.mjs b/tests/pools/cluster/fixed.test.mjs index de188a2e..ed5882c4 100644 --- a/tests/pools/cluster/fixed.test.mjs +++ b/tests/pools/cluster/fixed.test.mjs @@ -1,22 +1,22 @@ 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' +import { FixedClusterPool, PoolEvents } from '../../../lib/index.cjs' +import { TaskFunctions } from '../../test-types.cjs' +import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs' +import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs' describe('Fixed cluster pool test suite', () => { const numberOfWorkers = 8 const tasksConcurrency = 2 const pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { errorHandler: e => console.error(e) } ) const queuePool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { enableTasksQueue: true, tasksQueueOptions: { @@ -27,30 +27,30 @@ describe('Fixed cluster pool test suite', () => { ) const emptyPool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/emptyWorker.js', + './tests/worker-files/cluster/emptyWorker.cjs', { exitHandler: () => console.info('empty pool worker exited') } ) const echoPool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/echoWorker.js' + './tests/worker-files/cluster/echoWorker.cjs' ) const errorPool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/errorWorker.js', + './tests/worker-files/cluster/errorWorker.cjs', { errorHandler: e => console.error(e) } ) const asyncErrorPool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/asyncErrorWorker.js', + './tests/worker-files/cluster/asyncErrorWorker.cjs', { errorHandler: e => console.error(e) } ) const asyncPool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/asyncWorker.js' + './tests/worker-files/cluster/asyncWorker.cjs' ) after('Destroy all pools', async () => { @@ -82,7 +82,7 @@ describe('Fixed cluster pool test suite', () => { it("Verify that 'ready' event is emitted", async () => { const pool = new FixedClusterPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { errorHandler: e => console.error(e) } @@ -277,7 +277,7 @@ describe('Fixed cluster pool test suite', () => { }) it('Verify that cluster pool options are checked', async () => { - const workerFilePath = './tests/worker-files/cluster/testWorker.js' + const workerFilePath = './tests/worker-files/cluster/testWorker.cjs' let pool = new FixedClusterPool(numberOfWorkers, workerFilePath) expect(pool.opts.env).toBeUndefined() expect(pool.opts.settings).toBeUndefined() @@ -300,7 +300,7 @@ describe('Fixed cluster pool test suite', () => { }) it('Should work even without opts in input', async () => { - const workerFilePath = './tests/worker-files/cluster/testWorker.js' + const workerFilePath = './tests/worker-files/cluster/testWorker.cjs' const pool = new FixedClusterPool(numberOfWorkers, workerFilePath) const res = await pool.execute() expect(res).toStrictEqual({ ok: 1 }) @@ -309,7 +309,7 @@ describe('Fixed cluster pool test suite', () => { }) it('Verify destroyWorkerNode()', async () => { - const workerFilePath = './tests/worker-files/cluster/testWorker.js' + const workerFilePath = './tests/worker-files/cluster/testWorker.cjs' const pool = new FixedClusterPool(numberOfWorkers, workerFilePath) const workerNodeKey = 0 let disconnectEvent = 0 @@ -330,7 +330,7 @@ describe('Fixed cluster pool test suite', () => { it('Verify that a pool with zero worker fails', () => { expect( () => - new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.js') + new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.cjs') ).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 e1719155..39a2ccc3 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.mjs +++ b/tests/pools/selection-strategies/selection-strategies.test.mjs @@ -5,8 +5,8 @@ import { FixedClusterPool, FixedThreadPool, WorkerChoiceStrategies -} from '../../../lib/index.js' -import { CircularArray } from '../../../lib/circular-array.js' +} from '../../../lib/index.cjs' +import { CircularArray } from '../../../lib/circular-array.cjs' describe('Selection strategies test suite', () => { const min = 0 @@ -85,7 +85,7 @@ describe('Selection strategies test suite', () => { const pool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy) @@ -389,7 +389,7 @@ describe('Selection strategies test suite', () => { const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN let pool = new FixedClusterPool( max, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { workerChoiceStrategy } ) let results = new Set() diff --git a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs index 25c262fd..0e756886 100644 --- a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs +++ b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs @@ -1,7 +1,7 @@ import { expect } from 'expect' -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' +import { FixedThreadPool } from '../../../lib/index.cjs' +import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs' +import { generateRandomInteger } from '../../test-utils.cjs' describe('Weighted round robin strategy worker choice strategy test suite', () => { // const min = 1 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 2b8d35d8..6615b8c4 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs @@ -4,15 +4,15 @@ import { DynamicThreadPool, FixedThreadPool, WorkerChoiceStrategies -} 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' +} from '../../../lib/index.cjs' +import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.cjs' +import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.cjs' +import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.cjs' +import { LeastBusyWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy.cjs' +import { LeastEluWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy.cjs' +import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.cjs' +import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs' +import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.cjs' describe('Worker choice strategy context test suite', () => { const min = 1 diff --git a/tests/pools/thread/dynamic.test.mjs b/tests/pools/thread/dynamic.test.mjs index f7329710..06cf64c6 100644 --- a/tests/pools/thread/dynamic.test.mjs +++ b/tests/pools/thread/dynamic.test.mjs @@ -1,7 +1,7 @@ import { expect } from 'expect' -import { DynamicThreadPool, PoolEvents } from '../../../lib/index.js' -import { TaskFunctions } from '../../test-types.js' -import { sleep, waitWorkerEvents } from '../../test-utils.js' +import { DynamicThreadPool, PoolEvents } from '../../../lib/index.cjs' +import { TaskFunctions } from '../../test-types.cjs' +import { sleep, waitWorkerEvents } from '../../test-utils.cjs' describe('Dynamic thread pool test suite', () => { const min = 1 diff --git a/tests/pools/thread/fixed.test.mjs b/tests/pools/thread/fixed.test.mjs index a7c4a48f..85415d63 100644 --- a/tests/pools/thread/fixed.test.mjs +++ b/tests/pools/thread/fixed.test.mjs @@ -1,8 +1,8 @@ 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' +import { FixedThreadPool, PoolEvents } from '../../../lib/index.cjs' +import { TaskFunctions } from '../../test-types.cjs' +import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs' +import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs' describe('Fixed thread pool test suite', () => { const numberOfThreads = 6 diff --git a/tests/pools/utils.test.mjs b/tests/pools/utils.test.mjs index adff47d9..bc0c7126 100644 --- a/tests/pools/utils.test.mjs +++ b/tests/pools/utils.test.mjs @@ -4,13 +4,13 @@ import { expect } from 'expect' import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE -} from '../../lib/circular-array.js' +} from '../../lib/circular-array.cjs' import { createWorker, getDefaultTasksQueueOptions, updateMeasurementStatistics -} from '../../lib/pools/utils.js' -import { WorkerTypes } from '../../lib/index.js' +} from '../../lib/pools/utils.cjs' +import { WorkerTypes } from '../../lib/index.cjs' describe('Pool utils test suite', () => { it('Verify getDefaultTasksQueueOptions() behavior', () => { diff --git a/tests/pools/worker-node.test.mjs b/tests/pools/worker-node.test.mjs index f22ea153..549db4b6 100644 --- a/tests/pools/worker-node.test.mjs +++ b/tests/pools/worker-node.test.mjs @@ -1,11 +1,11 @@ import { MessageChannel, Worker as ThreadWorker } from 'node:worker_threads' import { Worker as ClusterWorker } 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' +import { WorkerNode } from '../../lib/pools/worker-node.cjs' +import { WorkerTypes } from '../../lib/index.cjs' +import { CircularArray } from '../../lib/circular-array.cjs' +import { Deque } from '../../lib/deque.cjs' +import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' describe('Worker node test suite', () => { const threadWorkerNode = new WorkerNode( @@ -15,7 +15,7 @@ describe('Worker node test suite', () => { ) const clusterWorkerNode = new WorkerNode( WorkerTypes.cluster, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { tasksQueueBackPressureSize: 12 } ) diff --git a/tests/test-types.js b/tests/test-types.cjs similarity index 100% rename from tests/test-types.js rename to tests/test-types.cjs diff --git a/tests/test-utils.js b/tests/test-utils.cjs similarity index 98% rename from tests/test-utils.js rename to tests/test-utils.cjs index ef759824..6dba5866 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.cjs @@ -1,4 +1,4 @@ -const { TaskFunctions } = require('./test-types.js') +const { TaskFunctions } = require('./test-types.cjs') const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => { return await new Promise(resolve => { diff --git a/tests/utils.test.mjs b/tests/utils.test.mjs index fd4f776b..2d1ee9e6 100644 --- a/tests/utils.test.mjs +++ b/tests/utils.test.mjs @@ -23,8 +23,8 @@ import { round, secureRandom, sleep -} from '../lib/utils.js' -import { KillBehaviors, WorkerTypes } from '../lib/index.js' +} from '../lib/utils.cjs' +import { KillBehaviors, WorkerTypes } from '../lib/index.cjs' describe('Utils test suite', () => { it('Verify DEFAULT_TASK_NAME value', () => { diff --git a/tests/worker-files/cluster/asyncErrorWorker.js b/tests/worker-files/cluster/asyncErrorWorker.cjs similarity index 65% rename from tests/worker-files/cluster/asyncErrorWorker.js rename to tests/worker-files/cluster/asyncErrorWorker.cjs index f358fc3e..022b4536 100644 --- a/tests/worker-files/cluster/asyncErrorWorker.js +++ b/tests/worker-files/cluster/asyncErrorWorker.cjs @@ -1,6 +1,6 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils.js') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') +const { sleepTaskFunction } = require('../../test-utils.cjs') async function error (data) { return sleepTaskFunction( diff --git a/tests/worker-files/cluster/asyncWorker.js b/tests/worker-files/cluster/asyncWorker.cjs similarity index 58% rename from tests/worker-files/cluster/asyncWorker.js rename to tests/worker-files/cluster/asyncWorker.cjs index 3ec0d950..d6806891 100644 --- a/tests/worker-files/cluster/asyncWorker.js +++ b/tests/worker-files/cluster/asyncWorker.cjs @@ -1,6 +1,6 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils.js') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') +const { sleepTaskFunction } = require('../../test-utils.cjs') async function sleep (data) { return sleepTaskFunction(data, 2000) diff --git a/tests/worker-files/cluster/echoWorker.js b/tests/worker-files/cluster/echoWorker.cjs similarity index 64% rename from tests/worker-files/cluster/echoWorker.js rename to tests/worker-files/cluster/echoWorker.cjs index f9308c70..4534d985 100644 --- a/tests/worker-files/cluster/echoWorker.js +++ b/tests/worker-files/cluster/echoWorker.cjs @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') function echo (data) { return data diff --git a/tests/worker-files/cluster/emptyWorker.js b/tests/worker-files/cluster/emptyWorker.cjs similarity index 65% rename from tests/worker-files/cluster/emptyWorker.js rename to tests/worker-files/cluster/emptyWorker.cjs index 02a733da..9c6072af 100644 --- a/tests/worker-files/cluster/emptyWorker.js +++ b/tests/worker-files/cluster/emptyWorker.cjs @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') function test () {} diff --git a/tests/worker-files/cluster/errorWorker.js b/tests/worker-files/cluster/errorWorker.cjs similarity index 72% rename from tests/worker-files/cluster/errorWorker.js rename to tests/worker-files/cluster/errorWorker.cjs index b8e11d36..2dcfe625 100644 --- a/tests/worker-files/cluster/errorWorker.js +++ b/tests/worker-files/cluster/errorWorker.cjs @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') function error () { throw new Error('Error Message from ClusterWorker') diff --git a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js b/tests/worker-files/cluster/longRunningWorkerHardBehavior.cjs similarity index 58% rename from tests/worker-files/cluster/longRunningWorkerHardBehavior.js rename to tests/worker-files/cluster/longRunningWorkerHardBehavior.cjs index a95d6538..2d7de52e 100644 --- a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js +++ b/tests/worker-files/cluster/longRunningWorkerHardBehavior.cjs @@ -1,6 +1,6 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils.js') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') +const { sleepTaskFunction } = require('../../test-utils.cjs') async function sleep (data) { return sleepTaskFunction(data, 50000) diff --git a/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js b/tests/worker-files/cluster/longRunningWorkerSoftBehavior.cjs similarity index 56% rename from tests/worker-files/cluster/longRunningWorkerSoftBehavior.js rename to tests/worker-files/cluster/longRunningWorkerSoftBehavior.cjs index 0459acf7..91eb2b35 100644 --- a/tests/worker-files/cluster/longRunningWorkerSoftBehavior.js +++ b/tests/worker-files/cluster/longRunningWorkerSoftBehavior.cjs @@ -1,6 +1,6 @@ 'use strict' -const { ClusterWorker } = require('../../../lib') -const { sleepTaskFunction } = require('../../test-utils.js') +const { ClusterWorker } = require('../../../lib/index.cjs') +const { sleepTaskFunction } = require('../../test-utils.cjs') async function sleep (data) { return sleepTaskFunction(data, 50000) diff --git a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs similarity index 75% rename from tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js rename to tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs index 0777cecb..ef785aa1 100644 --- a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js +++ b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs @@ -1,10 +1,10 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') const { jsonIntegerSerialization, factorial, fibonacci -} = require('../../test-utils.js') +} = require('../../test-utils.cjs') module.exports = new ClusterWorker( { diff --git a/tests/worker-files/cluster/testWorker.js b/tests/worker-files/cluster/testWorker.cjs similarity index 58% rename from tests/worker-files/cluster/testWorker.js rename to tests/worker-files/cluster/testWorker.cjs index 57715266..fd6b2eb2 100644 --- a/tests/worker-files/cluster/testWorker.js +++ b/tests/worker-files/cluster/testWorker.cjs @@ -1,7 +1,7 @@ 'use strict' -const { ClusterWorker, KillBehaviors } = require('../../../lib') -const { executeTaskFunction } = require('../../test-utils.js') -const { TaskFunctions } = require('../../test-types.js') +const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs') +const { executeTaskFunction } = require('../../test-utils.cjs') +const { TaskFunctions } = require('../../test-types.cjs') function test (data) { data = data || {} diff --git a/tests/worker-files/thread/asyncErrorWorker.mjs b/tests/worker-files/thread/asyncErrorWorker.mjs index c7c9371c..9624b6d8 100644 --- a/tests/worker-files/thread/asyncErrorWorker.mjs +++ b/tests/worker-files/thread/asyncErrorWorker.mjs @@ -1,5 +1,5 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' -import { sleepTaskFunction } from '../../test-utils.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' +import { sleepTaskFunction } from '../../test-utils.cjs' /** * diff --git a/tests/worker-files/thread/asyncWorker.mjs b/tests/worker-files/thread/asyncWorker.mjs index 30442bfc..623d517d 100644 --- a/tests/worker-files/thread/asyncWorker.mjs +++ b/tests/worker-files/thread/asyncWorker.mjs @@ -1,5 +1,5 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' -import { sleepTaskFunction } from '../../test-utils.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' +import { sleepTaskFunction } from '../../test-utils.cjs' /** * diff --git a/tests/worker-files/thread/echoWorker.mjs b/tests/worker-files/thread/echoWorker.mjs index 04b6c996..9a8ae66e 100644 --- a/tests/worker-files/thread/echoWorker.mjs +++ b/tests/worker-files/thread/echoWorker.mjs @@ -1,4 +1,4 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' /** * diff --git a/tests/worker-files/thread/emptyWorker.mjs b/tests/worker-files/thread/emptyWorker.mjs index b129244c..ad4d52bc 100644 --- a/tests/worker-files/thread/emptyWorker.mjs +++ b/tests/worker-files/thread/emptyWorker.mjs @@ -1,4 +1,4 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' /** * diff --git a/tests/worker-files/thread/errorWorker.mjs b/tests/worker-files/thread/errorWorker.mjs index 101e4558..ec866743 100644 --- a/tests/worker-files/thread/errorWorker.mjs +++ b/tests/worker-files/thread/errorWorker.mjs @@ -1,4 +1,4 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' /** * diff --git a/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs b/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs index 01cf3c0e..3d58ab45 100644 --- a/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs +++ b/tests/worker-files/thread/longRunningWorkerHardBehavior.mjs @@ -1,5 +1,5 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' -import { sleepTaskFunction } from '../../test-utils.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' +import { sleepTaskFunction } from '../../test-utils.cjs' /** * diff --git a/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs b/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs index 9083e1d1..4b7c1500 100644 --- a/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs +++ b/tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs @@ -1,5 +1,5 @@ -import { ThreadWorker } from '../../../lib/index.js' -import { sleepTaskFunction } from '../../test-utils.js' +import { ThreadWorker } from '../../../lib/index.cjs' +import { sleepTaskFunction } from '../../test-utils.cjs' /** * diff --git a/tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs b/tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs index d559beb7..94e548ef 100644 --- a/tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs +++ b/tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs @@ -1,9 +1,9 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' import { factorial, fibonacci, jsonIntegerSerialization -} from '../../test-utils.js' +} from '../../test-utils.cjs' export default new ThreadWorker( { diff --git a/tests/worker-files/thread/testWorker.mjs b/tests/worker-files/thread/testWorker.mjs index 618a9ac0..8a74ae3a 100644 --- a/tests/worker-files/thread/testWorker.mjs +++ b/tests/worker-files/thread/testWorker.mjs @@ -1,6 +1,6 @@ -import { KillBehaviors, ThreadWorker } from '../../../lib/index.js' -import { executeTaskFunction } from '../../test-utils.js' -import { TaskFunctions } from '../../test-types.js' +import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' +import { executeTaskFunction } from '../../test-utils.cjs' +import { TaskFunctions } from '../../test-types.cjs' /** * diff --git a/tests/worker/abstract-worker.test.mjs b/tests/worker/abstract-worker.test.mjs index 4abbbeb1..3e5f5518 100644 --- a/tests/worker/abstract-worker.test.mjs +++ b/tests/worker/abstract-worker.test.mjs @@ -1,7 +1,7 @@ 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' +import { ClusterWorker, KillBehaviors, ThreadWorker } from '../../lib/index.cjs' +import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../lib/utils.cjs' describe('Abstract worker test suite', () => { class StubWorkerWithMainWorker extends ThreadWorker { diff --git a/tests/worker/cluster-worker.test.mjs b/tests/worker/cluster-worker.test.mjs index b785010e..33ddf374 100644 --- a/tests/worker/cluster-worker.test.mjs +++ b/tests/worker/cluster-worker.test.mjs @@ -1,7 +1,7 @@ import { expect } from 'expect' import { restore, stub } from 'sinon' -import { ClusterWorker } from '../../lib/index.js' -import { DEFAULT_TASK_NAME } from '../../lib/utils.js' +import { ClusterWorker } from '../../lib/index.cjs' +import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' describe('Cluster worker test suite', () => { afterEach(() => { diff --git a/tests/worker/thread-worker.test.mjs b/tests/worker/thread-worker.test.mjs index 81b096f2..77bb6c08 100644 --- a/tests/worker/thread-worker.test.mjs +++ b/tests/worker/thread-worker.test.mjs @@ -1,7 +1,7 @@ import { expect } from 'expect' import { restore, stub } from 'sinon' -import { ThreadWorker } from '../../lib/index.js' -import { DEFAULT_TASK_NAME } from '../../lib/utils.js' +import { ThreadWorker } from '../../lib/index.cjs' +import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' describe('Thread worker test suite', () => { afterEach(() => { -- 2.34.1