mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 15:01:23 +00:00
test: dedupe and optimize test suites
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("./config.js", () => ({
|
||||
readLoggingConfig: () => undefined,
|
||||
@@ -27,6 +27,13 @@ type ConsoleSnapshot = {
|
||||
|
||||
let originalIsTty: boolean | undefined;
|
||||
let snapshot: ConsoleSnapshot;
|
||||
let logging: typeof import("../logging.js");
|
||||
let state: typeof import("./state.js");
|
||||
|
||||
beforeAll(async () => {
|
||||
logging = await import("../logging.js");
|
||||
state = await import("./state.js");
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
loadConfigCalls = 0;
|
||||
@@ -42,7 +49,7 @@ beforeEach(() => {
|
||||
Object.defineProperty(process.stdout, "isTTY", { value: false, configurable: true });
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
afterEach(() => {
|
||||
console.log = snapshot.log;
|
||||
console.info = snapshot.info;
|
||||
console.warn = snapshot.warn;
|
||||
@@ -50,14 +57,11 @@ afterEach(async () => {
|
||||
console.debug = snapshot.debug;
|
||||
console.trace = snapshot.trace;
|
||||
Object.defineProperty(process.stdout, "isTTY", { value: originalIsTty, configurable: true });
|
||||
const logging = await import("../logging.js");
|
||||
logging.setConsoleConfigLoaderForTests();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
async function loadLogging() {
|
||||
const logging = await import("../logging.js");
|
||||
const state = await import("./state.js");
|
||||
function loadLogging() {
|
||||
state.loggingState.cachedConsoleSettings = null;
|
||||
logging.setConsoleConfigLoaderForTests(() => {
|
||||
loadConfigCalls += 1;
|
||||
@@ -71,8 +75,8 @@ async function loadLogging() {
|
||||
}
|
||||
|
||||
describe("getConsoleSettings", () => {
|
||||
it("does not recurse when loadConfig logs during resolution", async () => {
|
||||
const { logging } = await loadLogging();
|
||||
it("does not recurse when loadConfig logs during resolution", () => {
|
||||
const { logging } = loadLogging();
|
||||
logging.setConsoleTimestampPrefix(true);
|
||||
logging.enableConsoleCapture();
|
||||
const { getConsoleSettings } = logging;
|
||||
@@ -80,8 +84,8 @@ describe("getConsoleSettings", () => {
|
||||
expect(loadConfigCalls).toBe(1);
|
||||
});
|
||||
|
||||
it("skips config fallback during re-entrant resolution", async () => {
|
||||
const { logging, state } = await loadLogging();
|
||||
it("skips config fallback during re-entrant resolution", () => {
|
||||
const { logging, state } = loadLogging();
|
||||
state.loggingState.resolvingConsoleSettings = true;
|
||||
logging.setConsoleTimestampPrefix(true);
|
||||
logging.enableConsoleCapture();
|
||||
|
||||
Reference in New Issue
Block a user