From e7d6fa8a7e8eba97d00f0bc4d3347a69e87dc195 Mon Sep 17 00:00:00 2001 From: Alex Villarreal <716334+alexvy86@users.noreply.github.com> Date: Sat, 11 Jan 2025 08:55:15 -0800 Subject: [PATCH 1/2] Merge MockLogger2 into MockLogger --- .../src/test/pendingStateManager.spec.ts | 4 +- packages/utils/telemetry-utils/src/index.ts | 1 - .../utils/telemetry-utils/src/mockLogger.ts | 42 ++++++++----------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/packages/runtime/container-runtime/src/test/pendingStateManager.spec.ts b/packages/runtime/container-runtime/src/test/pendingStateManager.spec.ts index 357b83e0866a..3a5523d7d836 100644 --- a/packages/runtime/container-runtime/src/test/pendingStateManager.spec.ts +++ b/packages/runtime/container-runtime/src/test/pendingStateManager.spec.ts @@ -10,7 +10,7 @@ import { MessageType, ISequencedDocumentMessage, } from "@fluidframework/driver-definitions/internal"; -import { MockLogger2, createChildLogger } from "@fluidframework/telemetry-utils/internal"; +import { MockLogger, createChildLogger } from "@fluidframework/telemetry-utils/internal"; import Deque from "double-ended-queue"; import type { InboundSequencedContainerRuntimeMessage } from "../messageTypes.js"; @@ -30,7 +30,7 @@ type PendingStateManager_WithPrivates = Omit { - const mockLogger = new MockLogger2(); + const mockLogger = new MockLogger(); const logger = createChildLogger({ logger: mockLogger }); afterEach("ThrowOnErrorLogs", () => { diff --git a/packages/utils/telemetry-utils/src/index.ts b/packages/utils/telemetry-utils/src/index.ts index 7df70caef4d1..9ae06cf34241 100644 --- a/packages/utils/telemetry-utils/src/index.ts +++ b/packages/utils/telemetry-utils/src/index.ts @@ -67,7 +67,6 @@ export { createMockLoggerExt, type IMockLoggerExt, MockLogger, - MockLogger2, } from "./mockLogger.js"; export { ThresholdCounter } from "./thresholdCounter.js"; export { diff --git a/packages/utils/telemetry-utils/src/mockLogger.ts b/packages/utils/telemetry-utils/src/mockLogger.ts index f2f3e3dceee0..13b3bf031b78 100644 --- a/packages/utils/telemetry-utils/src/mockLogger.ts +++ b/packages/utils/telemetry-utils/src/mockLogger.ts @@ -308,6 +308,23 @@ ${JSON.stringify(actualEvents)}`); } return matchObjects(actual, expected); } + + /** + * Throws if any errors were logged + */ + public assertNoErrors(message?: string, clearEventsAfterCheck: boolean = true): void { + const actualEvents = this.events; + const errors = actualEvents.filter((event) => event.category === "error"); + if (clearEventsAfterCheck) { + this.clear(); + } + if (errors.length > 0) { + throw new Error(`${message ?? "Errors found in logs"} + +error logs: +${JSON.stringify(errors)}`); + } + } } function matchObjects( @@ -370,28 +387,3 @@ export function createMockLoggerExt(minLogLevel?: LogLevel): IMockLoggerExt { }); return childLogger as IMockLoggerExt; } - -/** - * Temporary extension to add new functionality during breaking change freeze, - * since MockLogger wasn't able to be made internal yet. - * - * @internal - */ -export class MockLogger2 extends MockLogger { - /** - * Throws if any errors were logged - */ - public assertNoErrors(message?: string, clearEventsAfterCheck: boolean = true): void { - const actualEvents = this.events; - const errors = actualEvents.filter((event) => event.category === "error"); - if (clearEventsAfterCheck) { - this.clear(); - } - if (errors.length > 0) { - throw new Error(`${message ?? "Errors found in logs"} - -error logs: -${JSON.stringify(errors)}`); - } - } -} From c9e5e6ff526f262758d5e7dbe63f4739f1251214 Mon Sep 17 00:00:00 2001 From: Alex Villarreal <716334+alexvy86@users.noreply.github.com> Date: Mon, 13 Jan 2025 08:04:54 -0600 Subject: [PATCH 2/2] Fix type tests --- packages/utils/telemetry-utils/package.json | 6 +++++- .../test/types/validateTelemetryUtilsPrevious.generated.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/utils/telemetry-utils/package.json b/packages/utils/telemetry-utils/package.json index 288a1f30ad1c..8f0c89c67568 100644 --- a/packages/utils/telemetry-utils/package.json +++ b/packages/utils/telemetry-utils/package.json @@ -153,7 +153,11 @@ "typescript": "~5.4.5" }, "typeValidation": { - "broken": {}, + "broken": { + "Class_MockLogger": { + "forwardCompat": false + } + }, "entrypoint": "legacy" } } diff --git a/packages/utils/telemetry-utils/src/test/types/validateTelemetryUtilsPrevious.generated.ts b/packages/utils/telemetry-utils/src/test/types/validateTelemetryUtilsPrevious.generated.ts index e9b88f5e362a..1ea65cb59134 100644 --- a/packages/utils/telemetry-utils/src/test/types/validateTelemetryUtilsPrevious.generated.ts +++ b/packages/utils/telemetry-utils/src/test/types/validateTelemetryUtilsPrevious.generated.ts @@ -40,6 +40,7 @@ declare type current_as_old_for_Class_EventEmitterWithErrorHandling = requireAss * typeValidation.broken: * "Class_MockLogger": {"forwardCompat": false} */ +// @ts-expect-error compatibility expected to be broken declare type old_as_current_for_Class_MockLogger = requireAssignableTo, TypeOnly> /*