fix: stabilize tests and logging
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import os from "node:os";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import * as logging from "../logging.js";
|
||||
|
||||
const createService = vi.fn();
|
||||
const shutdown = vi.fn();
|
||||
@@ -23,14 +25,6 @@ vi.mock("../logger.js", () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../logging.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../logging.js")>("../logging.js");
|
||||
return {
|
||||
...actual,
|
||||
getLogger: () => ({ info: (...args: unknown[]) => getLoggerInfo(...args) }),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@homebridge/ciao", () => {
|
||||
return {
|
||||
Protocol: { TCP: "tcp" },
|
||||
@@ -60,6 +54,12 @@ describe("gateway bonjour advertiser", () => {
|
||||
|
||||
const prevEnv = { ...process.env };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(logging, "getLogger").mockReturnValue({
|
||||
info: (...args: unknown[]) => getLoggerInfo(...args),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
for (const key of Object.keys(process.env)) {
|
||||
if (!(key in prevEnv)) delete process.env[key];
|
||||
|
||||
@@ -90,7 +90,7 @@ describe("exec approvals command resolution", () => {
|
||||
const script = path.join(cwd, "bin", "tool");
|
||||
fs.mkdirSync(path.dirname(script), { recursive: true });
|
||||
fs.writeFileSync(script, "");
|
||||
const res = resolveCommandResolution("\"./bin/tool\" --version", cwd, undefined);
|
||||
const res = resolveCommandResolution('"./bin/tool" --version', cwd, undefined);
|
||||
expect(res?.resolvedPath).toBe(script);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +86,12 @@ export async function requestExecHostViaSocket(params: {
|
||||
idx = buffer.indexOf("\n");
|
||||
if (!line) continue;
|
||||
try {
|
||||
const msg = JSON.parse(line) as { type?: string; ok?: boolean; payload?: unknown; error?: unknown };
|
||||
const msg = JSON.parse(line) as {
|
||||
type?: string;
|
||||
ok?: boolean;
|
||||
payload?: unknown;
|
||||
error?: unknown;
|
||||
};
|
||||
if (msg?.type === "exec-res") {
|
||||
clearTimeout(timer);
|
||||
if (msg.ok === true && msg.payload) {
|
||||
|
||||
Reference in New Issue
Block a user