Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,26 @@
"format:write": "prettier --write .",
"test:integration:api-tests": "node --test integrationTests/apiTests/tests/testSuite.mjs",
"test:integration": "node integrationTests/utils/scripts/run.ts",
"test:unit": "TSX_TSCONFIG_PATH=./unitTests/tsconfig.json npx mocha --config unitTests/.mocharc.json",
"test:unit:all": "npm run test:unit unitTests"
"test:unit": "mocha --config unitTests/.mocharc.json",
"test:unit:all": "npm run test:unit unitTests",
"test:unit:typestrip": "env NODE_OPTIONS='--conditions=typestrip' npm run test:unit",
"test:unit:typestrip:all": "npm run test:unit:typestrip unitTests"
},
"imports": {
"#src/*": {
"import": "./*.ts",
"require": {
"typestrip": "./*.ts",
"default": "./dist/*.js"
}
},
"#js/*": {
"import": "./*.js",
"require": {
"typestrip": "./*.js",
"default": "./dist/*.js"
}
}
},
"engines": {
"node": ">=20",
Expand Down
4 changes: 1 addition & 3 deletions unitTests/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"$schema": "https://json.schemastore.org/mocharc.json",
"require": "tsx",
"timeout": 0,
"ui": "bdd",
"extension": ["js", "mjs", "ts"],
"extension": ["js", "mjs"],
"recursive": true,
"exit": true
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'mocha';
import { Component, ComponentInvalidPatternError } from '@/components/Component';
import assert from 'node:assert/strict';
/* eslint-disable sonarjs/no-nested-functions */
const { Component, ComponentInvalidPatternError } = require('#src/components/Component');
const assert = require('node:assert/strict');

describe('Component', () => {
const name = 'test-component';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-require-imports, sonarjs/void-use, sonarjs/assertions-in-tests, sonarjs/no-nested-functions */
// Not sure why sonar cannot pick up the assertions within the tests. I think its because they are `async`.

import { tmpdir } from 'node:os';
import {
const { tmpdir } = require('node:os');
const {
processResourceExtensionComponent,
ComponentV1,
InvalidFilesOptionError,
Expand All @@ -13,13 +13,13 @@ import {
InvalidRootOptionError,
InvalidPathOptionError,
InvalidURLPathOptionError,
} from '@/components/ComponentV1';
import { Resources } from '@/resources/Resources';
import assert from 'node:assert/strict';
import { join } from 'node:path';
import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from 'node:fs';
import { fake, restore, replace } from 'sinon';
import fg from 'fast-glob';
} = require('#src/components/ComponentV1');
const { Resources } = require('#src/resources/Resources');
const assert = require('node:assert/strict');
const { join } = require('node:path');
const { mkdtempSync, writeFileSync, mkdirSync, rmSync } = require('node:fs');
const { fake, restore, replace } = require('sinon');
const fg = require('fast-glob');

const TEMP_DIR_PATH = join(tmpdir(), 'harper.unit-test.component-v1-');

Expand All @@ -45,7 +45,7 @@ function createTempFixture(fixture) {
describe('ComponentV1', () => {
const componentName = 'test-component';

const harperLogger = require('@/utility/logging/harper_logger');
const harperLogger = require('#js/utility/logging/harper_logger');

beforeEach(() => {
replace(harperLogger, 'warn', fake());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EntryHandler } from '@/components/EntryHandler';
import { EventEmitter, once } from 'node:events';
import assert from 'node:assert/strict';
import { join, basename } from 'node:path';
import { tmpdir } from 'node:os';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
import { writeFile, mkdir } from 'node:fs/promises';
import { spy } from 'sinon';
import { waitFor } from './waitFor';
const { EntryHandler } = require('#src/components/EntryHandler');
const { EventEmitter, once } = require('node:events');
const assert = require('node:assert/strict');
const { join, basename } = require('node:path');
const { tmpdir } = require('node:os');
const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = require('node:fs');
const { writeFile, mkdir } = require('node:fs/promises');
const { spy } = require('sinon');
const { waitFor } = require('./waitFor.js');

function generateFixture(dirPath, fixture) {
mkdirSync(dirPath, { recursive: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable sonarjs/no-nested-functions */
import { OptionsWatcher } from '@/components/OptionsWatcher';
import { EventEmitter, once } from 'node:events';
import assert from 'node:assert/strict';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
import { writeFile, rm } from 'node:fs/promises';
import { stringify } from 'yaml';
import { spy } from 'sinon';
import { DEFAULT_CONFIG } from '@/components/DEFAULT_CONFIG';
const { OptionsWatcher } = require('#src/components/OptionsWatcher');
const { EventEmitter, once } = require('node:events');
const assert = require('node:assert/strict');
const { join } = require('node:path');
const { tmpdir } = require('node:os');
const { mkdtempSync, writeFileSync, rmSync } = require('node:fs');
const { writeFile, rm } = require('node:fs/promises');
const { stringify } = require('yaml');
const { spy } = require('sinon');
const { DEFAULT_CONFIG } = require('#src/components/DEFAULT_CONFIG');

/**
* This function asserts that an event is emitted.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Scope, MissingDefaultFilesOptionError } from '@/components/Scope';
import { EventEmitter } from 'node:events';
import assert from 'node:assert/strict';
import { join, basename } from 'node:path';
import { tmpdir } from 'node:os';
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
import { stringify } from 'yaml';
import { spy } from 'sinon';
import { OptionsWatcher } from '@/components/OptionsWatcher';
import { Resources } from '@/resources/Resources';
import { EntryHandler } from '@/components/EntryHandler';
import { restartNeeded, resetRestartNeeded } from '@/components/requestRestart';
import { writeFile } from 'node:fs/promises';
import { waitFor } from './waitFor';
const { Scope, MissingDefaultFilesOptionError } = require('#src/components/Scope');
const { EventEmitter } = require('node:events');
const assert = require('node:assert/strict');
const { join, basename } = require('node:path');
const { tmpdir } = require('node:os');
const { mkdtempSync, writeFileSync, rmSync } = require('node:fs');
const { stringify } = require('yaml');
const { spy } = require('sinon');
const { OptionsWatcher } = require('#src/components/OptionsWatcher');
const { Resources } = require('#src/resources/Resources');
const { EntryHandler } = require('#src/components/EntryHandler');
const { restartNeeded, resetRestartNeeded } = require('#src/components/requestRestart');
const { writeFile } = require('node:fs/promises');
const { waitFor } = require('./waitFor.js');

describe('Scope', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { describe, it, before, beforeEach, after } from 'mocha';
import assert from 'node:assert/strict';
import sinon from 'sinon';
import path from 'path';
import { tmpdir } from 'os';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync, existsSync } from 'fs';
const assert = require('node:assert/strict');
const sinon = require('sinon');
const path = require('path');
const { tmpdir } = require('os');
const { mkdtempSync, mkdirSync, writeFileSync, rmSync, existsSync } = require('fs');

describe('ComponentLoader Status Integration', function () {
let componentStatusRegistry;
let tempDir;
let componentLoader;
let lifecycle;

before(() => {
before(function () {
// Create a temporary directory for test components
tempDir = mkdtempSync(path.join(tmpdir(), 'harper-test-components-'));

// Mock environment to use our temp directory
const env = require('@/utility/environment/environmentManager');
const env = require('#js/utility/environment/environmentManager');
sinon.stub(env, 'get').callsFake((key) => {
if (key === 'COMPONENTSROOT') {
return tempDir;
Expand All @@ -30,7 +29,7 @@ describe('ComponentLoader Status Integration', function () {
});

// Get both the lifecycle and internal objects
const statusModule = require('@/components/status');
const statusModule = require('#src/components/status/index');
const { internal } = statusModule;
lifecycle = statusModule.lifecycle;
componentStatusRegistry = internal.componentStatusRegistry;
Expand All @@ -48,14 +47,14 @@ describe('ComponentLoader Status Integration', function () {
sinon.spy(componentStatusRegistry, 'getStatus');

// Mock getConfigObj to avoid loading real config for root components
const configUtils = require('@/config/configUtils');
const configUtils = require('#js/config/configUtils');
sinon.stub(configUtils, 'getConfigObj').returns({});

// Clear the componentLoader from require cache to ensure it gets our spied lifecycle
delete require.cache[require.resolve('@/components/componentLoader')];
delete require.cache[require.resolve('#src/components/componentLoader')];

// Load componentLoader after setting up spies
componentLoader = require('@/components/componentLoader');
componentLoader = require('#src/components/componentLoader');
});

after(function () {
Expand Down Expand Up @@ -215,7 +214,7 @@ describe('ComponentLoader Status Integration', function () {

it('should handle component loading errors gracefully', async function () {
// Stub the dataLoader module's handleApplication method to throw an error
const dataLoaderModule = require('@/resources/dataLoader');
const dataLoaderModule = require('#src/resources/dataLoader');
const originalhandleApplication = dataLoaderModule.handleApplication;
sinon.stub(dataLoaderModule, 'handleApplication').throws(new Error('DataLoader failed to initialize'));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deriveCommonPatternBase } from '@/components/deriveCommonPatternBase';
import assert from 'node:assert/strict';
const { deriveCommonPatternBase } = require('#src/components/deriveCommonPatternBase');
const assert = require('node:assert/strict');

describe('deriveCommonPatternBase', () => {
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'node:assert/strict';
import { deriveGlobOptions } from '@/components/deriveGlobOptions';
const assert = require('node:assert/strict');
const { deriveGlobOptions } = require('#src/components/deriveGlobOptions');

// components/deriveGlobOptions.test.ts

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { requestRestart, restartNeeded } from '@/components/requestRestart';
import assert from 'node:assert/strict';
const { requestRestart, restartNeeded } = require('#src/components/requestRestart');
const assert = require('node:assert/strict');

describe('requestRestart', () => {
it('should update the shared buffer', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolveBaseURLPath, InvalidBaseURLPathError } from '@/components/resolveBaseURLPath';
import assert from 'node:assert/strict';
const { resolveBaseURLPath, InvalidBaseURLPathError } = require('#src/components/resolveBaseURLPath');
const assert = require('node:assert/strict');

describe('resolveBaseURLPath', () => {
const componentName = 'test-component';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import assert from 'node:assert/strict';
import sinon from 'sinon';
import { ComponentStatus } from '@/components/status/ComponentStatus';
import { COMPONENT_STATUS_LEVELS } from '@/components/status/types';
import { describe, it, beforeEach, afterEach } from 'mocha';
const assert = require('node:assert/strict');
const sinon = require('sinon');
const { ComponentStatus } = require('#src/components/status/ComponentStatus');
const { COMPONENT_STATUS_LEVELS } = require('#src/components/status/types');

describe('ComponentStatus', function () {
let clock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import assert from 'node:assert/strict';
import sinon from 'sinon';
import { ComponentStatusRegistry } from '@/components/status/ComponentStatusRegistry';
import { ComponentStatus } from '@/components/status/ComponentStatus';
import { COMPONENT_STATUS_LEVELS } from '@/components/status/types';
import { StatusAggregator } from '@/components/status/crossThread';
const assert = require('node:assert/strict');
const sinon = require('sinon');
const { ComponentStatusRegistry } = require('#src/components/status/ComponentStatusRegistry');
const { ComponentStatus } = require('#src/components/status/ComponentStatus');
const { COMPONENT_STATUS_LEVELS } = require('#src/components/status/types');
const { StatusAggregator } = require('#src/components/status/crossThread');
const itcModule = require('#js/server/threads/itc');
const manageThreadsModule = require('#js/server/threads/manageThreads');

describe('ComponentStatusRegistry', function () {
let registry;
Expand All @@ -14,8 +16,6 @@ describe('ComponentStatusRegistry', function () {
clock = sinon.useFakeTimers();

// Stub ITC functions
const itcModule = require('@/server/threads/itc');
const manageThreadsModule = require('@/server/threads/manageThreads');
sinon.stub(itcModule, 'sendItcEvent').resolves();
sinon.stub(manageThreadsModule, 'onMessageByType');
sinon.stub(manageThreadsModule, 'getWorkerIndex').returns(0);
Expand Down Expand Up @@ -504,7 +504,7 @@ describe('ComponentStatusRegistry', function () {
describe('static getAggregatedFromAllThreads method', function () {
it('should collect and aggregate statuses', async function () {
// Mock the crossThreadCollector to avoid actual ITC communication
const { crossThreadCollector } = require('@/components/status/crossThread');
const { crossThreadCollector } = require('#src/components/status/crossThread');
const originalCollect = crossThreadCollector.collect;

// Create a fresh registry for this test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { statusForComponent, lifecycle, reset, STATUS, internal } from '@/../components/status';
import { describe, it, afterEach } from 'mocha';
const assert = require('node:assert/strict');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is directly recopying the test from /harperdb, eliminating any .ts conversion or conversion to ESM, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

const { statusForComponent, lifecycle, reset, STATUS } = require('#src/components/status/index');
const { internal } = require('#src/components/status/index');

describe('Component Status Public API', function () {
afterEach(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import assert from 'node:assert/strict';
import sinon from 'sinon';
import { CrossThreadStatusCollector, StatusAggregator } from '@/components/status/crossThread';
import { ComponentStatusRegistry } from '@/components/status/ComponentStatusRegistry';
const assert = require('node:assert/strict');
const sinon = require('sinon');
const { CrossThreadStatusCollector, StatusAggregator } = require('#src/components/status/crossThread');
const { ComponentStatusRegistry } = require('#src/components/status/ComponentStatusRegistry');
const itcModule = require('#js/server/threads/itc');
const manageThreadsModule = require('#js/server/threads/manageThreads');

describe('CrossThread Module', function () {
let sendItcEventStub;
let onMessageByTypeStub;
let getWorkerIndexStub;
let itcModule;
let manageThreadsModule;

beforeEach(function () {
// Stub ITC functions
itcModule = require('@/server/threads/itc');
manageThreadsModule = require('@/server/threads/manageThreads');
sendItcEventStub = sinon.stub(itcModule, 'sendItcEvent').resolves();
onMessageByTypeStub = sinon.stub(manageThreadsModule, 'onMessageByType');
getWorkerIndexStub = sinon.stub(manageThreadsModule, 'getWorkerIndex').returns(0);
Expand Down Expand Up @@ -173,7 +171,7 @@ describe('CrossThread Module', function () {
getWorkerIndexStub.returns(0);

// Mock getWorkerCount to return 2 (expecting 2 worker responses)
const manageThreadsModule = require('@/server/threads/manageThreads');
const manageThreadsModule = require('#js/server/threads/manageThreads');
const getWorkerCountStub = sinon.stub(manageThreadsModule, 'getWorkerCount').returns(2);

// Track when collection completes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import assert from 'node:assert/strict';
import {
const assert = require('node:assert/strict');
const {
ComponentStatusError,
CrossThreadTimeoutError,
ITCError,
AggregationError,
ComponentStatusOperationError,
CrossThreadCollectionError,
} from '@/components/status/errors';
import { HTTP_STATUS_CODES } from '@/utility/errors/commonErrors';
import { describe, it } from 'mocha';
} = require('#src/components/status/errors');
const { HTTP_STATUS_CODES } = require('#js/utility/errors/commonErrors');

describe('Component Status Errors', function () {
describe('ComponentStatusError', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from 'node:assert/strict';
import { statusForComponent, reset, STATUS, internal } from '@/components/status/index';

const assert = require('node:assert/strict');
const { statusForComponent, reset, STATUS, internal } = require('#src/components/status/index');
const { ComponentStatus } = internal;

describe('Component Status API', function () {
Expand Down
Loading
Loading