mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 12:11:20 +00:00
test(logging): reuse suite temp root tracker in console capture tests
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import crypto from "node:crypto";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
enableConsoleCapture,
|
||||
resetLogger,
|
||||
@@ -10,6 +9,7 @@ import {
|
||||
setLoggerOverride,
|
||||
} from "../logging.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { createSuiteTempRootTracker } from "../test-helpers/temp-dir.js";
|
||||
import { loggingState } from "./state.js";
|
||||
import {
|
||||
captureConsoleSnapshot,
|
||||
@@ -18,6 +18,15 @@ import {
|
||||
} from "./test-helpers/console-snapshot.js";
|
||||
|
||||
let snapshot: ConsoleSnapshot;
|
||||
let logRoot = "";
|
||||
const logRootTracker = createSuiteTempRootTracker({
|
||||
prefix: "openclaw-log-",
|
||||
});
|
||||
|
||||
beforeAll(async () => {
|
||||
await logRootTracker.setup();
|
||||
logRoot = await logRootTracker.make("case");
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
snapshot = captureConsoleSnapshot();
|
||||
@@ -39,6 +48,11 @@ afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await logRootTracker.cleanup();
|
||||
logRoot = "";
|
||||
});
|
||||
|
||||
describe("enableConsoleCapture", () => {
|
||||
it("swallows EIO from stderr writes", () => {
|
||||
setLoggerOverride({ level: "info", file: tempLogPath() });
|
||||
@@ -151,7 +165,7 @@ describe("enableConsoleCapture", () => {
|
||||
});
|
||||
|
||||
function tempLogPath() {
|
||||
return path.join(os.tmpdir(), `openclaw-log-${crypto.randomUUID()}.log`);
|
||||
return path.join(logRoot, `${crypto.randomUUID()}.log`);
|
||||
}
|
||||
|
||||
function eioError() {
|
||||
|
||||
Reference in New Issue
Block a user