Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(telemetry-utils): Merge MockLogger2 into MockLogger #23526

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -30,7 +30,7 @@ type PendingStateManager_WithPrivates = Omit<PendingStateManager, "initialMessag
};

describe("Pending State Manager", () => {
const mockLogger = new MockLogger2();
const mockLogger = new MockLogger();
const logger = createChildLogger({ logger: mockLogger });

afterEach("ThrowOnErrorLogs", () => {
Expand Down
1 change: 0 additions & 1 deletion packages/utils/telemetry-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export {
createMockLoggerExt,
type IMockLoggerExt,
MockLogger,
MockLogger2,
} from "./mockLogger.js";
export { ThresholdCounter } from "./thresholdCounter.js";
export {
Expand Down
42 changes: 17 additions & 25 deletions packages/utils/telemetry-utils/src/mockLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)}`);
}
}
}
Loading