文件
PRA-only-demo/packages/rpa-core/src/capabilities/register-all.test.ts
T

36 行
1.6 KiB
TypeScript
原始文件 Blame 文件历史

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
import { describe, expect, it } from "vitest";
import { createEngine } from "../engine/engine";
import { capabilityCount, capabilityIds, getCapabilityMeta } from "../engine/registry";
import { isKnownErrorCode } from "../engine/error-codes";
import { capabilityDomains, registerAll } from "./register-all";
import "./index";
describe("registerAll 显式注册入口", () => {
it("副作用入口已注册全量包内能力,registerAll 全量幂等", async () => {
// 包内 capabilities/index 注册 719 个 id(909 快照 = 包内 + 宿主浏览器能力)
const before = capabilityCount();
expect(before).toBeGreaterThan(700);
const engine = await registerAll(createEngine());
expect(engine).toBeDefined();
expect(capabilityCount()).toBe(before);
});
it("按子集注册:只拉起指定域,未知域报错", async () => {
expect(capabilityDomains).toContain("excelCom");
await expect(registerAll(createEngine(), ["excelCom", "no-such-domain"])).rejects.toThrow("未知能力域");
await registerAll(createEngine(), ["files"]);
expect(getCapabilityMeta).toBeDefined();
});
it("meta(任务 4.1):老能力允许缺省;已声明 meta 的能力错误码必须在稳定清单内", () => {
// 全量注册后的每个 meta,其 errorCodes 都必须落在 RUNTIME_ERROR_CODES 清单内
for (const id of capabilityIds()) {
const meta = getCapabilityMeta(id);
if (!meta) continue;
for (const code of meta.errorCodes ?? []) {
expect(isKnownErrorCode(code), `${id} 的错误码 ${code} 未登记 error-codes.ts`).toBe(true);
}
}
});
});