diff --git a/apps/package-manager/packages/generic/src/packageManager.ts b/apps/package-manager/packages/generic/src/packageManager.ts index 36be244b..10a412f0 100644 --- a/apps/package-manager/packages/generic/src/packageManager.ts +++ b/apps/package-manager/packages/generic/src/packageManager.ts @@ -84,7 +84,7 @@ export class PackageManagerHandler { expectedPackages: [], } private _triggerUpdatedExpectedPackagesTimeout: NodeJS.Timeout | null = null - public monitoredPackages: Map = new Map() + public monitoredPackages: Map> = new Map() settings: PackageManagerSettings = { delayRemoval: 0, useTemporaryFilePath: false, @@ -289,11 +289,13 @@ export class PackageManagerHandler { // Add from Monitors: { - for (const [monitorId, monitorExpectedPackages] of this.monitoredPackages.entries()) { - expectedPackageSources.push({ - sourceName: `monitor_${monitorId}`, - expectedPackages: monitorExpectedPackages, - }) + for (const monitors of this.monitoredPackages.values()) { + for (const [monitorId, monitorExpectedPackages] of monitors.entries()) { + expectedPackageSources.push({ + sourceName: `monitor_${monitorId}`, + expectedPackages: monitorExpectedPackages, + }) + } } } @@ -676,7 +678,7 @@ class ExpectationManagerCallbacksHandler implements ExpectationManagerCallbacks ) } case 'reportFromMonitorPackages': - this.reportMonitoredPackages(...message.arguments) + this.onReportMonitoredPackages(...message.arguments) break default: @@ -992,8 +994,8 @@ class ExpectationManagerCallbacksHandler implements ExpectationManagerCallbacks .catch((e) => this.logger.error(`Error in updateCoreStatus : ${stringifyError(e)}`)) } - private reportMonitoredPackages( - _containerId: PackageContainerId, + private onReportMonitoredPackages( + containerId: PackageContainerId, monitorId: MonitorId, expectedPackages: ExpectedPackage.Any[] ) { @@ -1010,7 +1012,12 @@ class ExpectationManagerCallbacksHandler implements ExpectationManagerCallbacks `reportMonitoredPackages: ${expectedPackages.length} packages, ${expectedPackagesWraps.length} wraps` ) - this.packageManager.monitoredPackages.set(monitorId, expectedPackagesWraps) + let monitors = this.packageManager.monitoredPackages.get(containerId) + if (!monitors) { + monitors = new Map() + this.packageManager.monitoredPackages.set(containerId, monitors) + } + monitors.set(monitorId, expectedPackagesWraps) this.packageManager.triggerUpdatedExpectedPackages() } diff --git a/shared/packages/api/src/logger.ts b/shared/packages/api/src/logger.ts index e1ac9c28..6d4d64f8 100644 --- a/shared/packages/api/src/logger.ts +++ b/shared/packages/api/src/logger.ts @@ -134,7 +134,10 @@ export function setupLogger( transports: [transportConsole], }) } - if (handleProcess) logger.info('Logging to Console') + if (handleProcess && process.env.JEST_WORKER_ID === undefined) { + // Is not running in Jest + logger.info('Logging to Console') + } if (initialLogLevel) setLogLevel(initialLogLevel, true) } // Somewhat of a hack, inject the category method: diff --git a/tests/internal-tests/src/__mocks__/@parcel/watcher.ts b/tests/internal-tests/src/__mocks__/@parcel/watcher.ts new file mode 100644 index 00000000..11131650 --- /dev/null +++ b/tests/internal-tests/src/__mocks__/@parcel/watcher.ts @@ -0,0 +1,33 @@ +export async function getEventsSince(_dir: FilePath, _snapshot: FilePath, _opts?: Options): Promise { + // not implemented + return [] +} +export async function subscribe(_dir: FilePath, _fn: SubscribeCallback, _opts?: Options): Promise { + return new AsyncSubscription() +} +export async function unsubscribe(_dir: FilePath, _fn: SubscribeCallback, _opts?: Options): Promise { + // not implemented +} +export async function writeSnapshot(_dir: FilePath, _snapshot: FilePath, _opts?: Options): Promise { + // not implemented + return './mock-snapshot' +} + +type FilePath = string +type GlobPattern = string +type BackendType = 'fs-events' | 'watchman' | 'inotify' | 'windows' | 'brute-force' +type EventType = 'create' | 'update' | 'delete' +interface Options { + ignore?: (FilePath | GlobPattern)[] + backend?: BackendType +} +type SubscribeCallback = (err: Error | null, events: Event[]) => unknown +interface Event { + path: FilePath + type: EventType +} +class AsyncSubscription { + async unsubscribe(): Promise { + // not implemented + } +} diff --git a/tests/internal-tests/src/__tests__/basic.spec.ts b/tests/internal-tests/src/__tests__/basic.spec.ts index dcc17eb3..4b29ada1 100644 --- a/tests/internal-tests/src/__tests__/basic.spec.ts +++ b/tests/internal-tests/src/__tests__/basic.spec.ts @@ -30,6 +30,7 @@ jest.mock('mkdirp') jest.mock('child_process') jest.mock('windows-network-drive') jest.mock('tv-automation-quantel-gateway-client') +jest.mock('@parcel/watcher') const fs = fsOrg as any as typeof fsMockType const WND = WNDOrg as any as typeof WNDType diff --git a/tests/internal-tests/src/__tests__/issues.spec.ts b/tests/internal-tests/src/__tests__/issues.spec.ts index 5667ff60..a3202e75 100644 --- a/tests/internal-tests/src/__tests__/issues.spec.ts +++ b/tests/internal-tests/src/__tests__/issues.spec.ts @@ -22,6 +22,7 @@ jest.mock('mkdirp') jest.mock('child_process') jest.mock('windows-network-drive') jest.mock('tv-automation-quantel-gateway-client') +jest.mock('@parcel/watcher') const fs = fsOrg as any as typeof fsMockType diff --git a/tests/internal-tests/src/__tests__/quantel.spec.ts b/tests/internal-tests/src/__tests__/quantel.spec.ts index ad40aefb..ed087d05 100644 --- a/tests/internal-tests/src/__tests__/quantel.spec.ts +++ b/tests/internal-tests/src/__tests__/quantel.spec.ts @@ -17,6 +17,7 @@ import { describeForAllPlatforms, waitUntil } from './lib/lib' import { getQuantelSource, getQuantelTarget } from './lib/containers' jest.mock('child_process') jest.mock('tv-automation-quantel-gateway-client') +jest.mock('@parcel/watcher') const QGatewayClient = QGatewayClientOrg as any as typeof QGatewayClientType