hostLog.test.ts 873 B

1234567891011121314151617181920212223242526
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. shouldReportHostConsoleError,
  4. stringifyHostLogArg,
  5. } from "../src/host/hostLog.js";
  6. describe("host log formatting", () => {
  7. it("serializes Error with message and stack instead of an empty object", () => {
  8. const error = new Error("Stream closed before handshake completed");
  9. const text = stringifyHostLogArg(error);
  10. expect(text).toContain("Stream closed before handshake completed");
  11. expect(text).toContain("stack");
  12. expect(text).not.toBe("{}");
  13. });
  14. it("Node warning 不应通过 console.error 再上报一条结构化 error", () => {
  15. expect(
  16. shouldReportHostConsoleError([
  17. "(node:71190) ExperimentalWarning: SQLite is an experimental feature",
  18. ]),
  19. ).toBe(false);
  20. expect(shouldReportHostConsoleError(["remote handshake failed"])).toBe(true);
  21. });
  22. });