mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
perf(test): fold qr-image tests into web login suite
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resetLogger, setLoggerOverride } from "../logging.js";
|
||||
import { renderQrPngBase64 } from "./qr-image.js";
|
||||
|
||||
vi.mock("./session.js", () => {
|
||||
const ev = new EventEmitter();
|
||||
@@ -47,3 +50,20 @@ describe("web login", () => {
|
||||
expect(close).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("renderQrPngBase64", () => {
|
||||
it("renders a PNG data payload", async () => {
|
||||
const b64 = await renderQrPngBase64("openclaw");
|
||||
const buf = Buffer.from(b64, "base64");
|
||||
expect(buf.subarray(0, 8).toString("hex")).toBe("89504e470d0a1a0a");
|
||||
});
|
||||
|
||||
it("avoids dynamic require of qrcode-terminal vendor modules", async () => {
|
||||
const sourcePath = resolve(process.cwd(), "src/web/qr-image.ts");
|
||||
const source = await readFile(sourcePath, "utf-8");
|
||||
expect(source).not.toContain("createRequire(");
|
||||
expect(source).not.toContain('require("qrcode-terminal/vendor/QRCode")');
|
||||
expect(source).toContain("qrcode-terminal/vendor/QRCode/index.js");
|
||||
expect(source).toContain("qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderQrPngBase64 } from "./qr-image.js";
|
||||
|
||||
describe("renderQrPngBase64", () => {
|
||||
it("renders a PNG data payload", async () => {
|
||||
const b64 = await renderQrPngBase64("openclaw");
|
||||
const buf = Buffer.from(b64, "base64");
|
||||
expect(buf.subarray(0, 8).toString("hex")).toBe("89504e470d0a1a0a");
|
||||
});
|
||||
|
||||
it("avoids dynamic require of qrcode-terminal vendor modules", async () => {
|
||||
const sourcePath = resolve(process.cwd(), "src/web/qr-image.ts");
|
||||
const source = await readFile(sourcePath, "utf-8");
|
||||
expect(source).not.toContain("createRequire(");
|
||||
expect(source).not.toContain('require("qrcode-terminal/vendor/QRCode")');
|
||||
expect(source).toContain("qrcode-terminal/vendor/QRCode/index.js");
|
||||
expect(source).toContain("qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user