Files
hose-use/scripts/sdk-example.test.ts
T
gitea 613fe3476c fix: 修复真实验收中的企业范围与草稿复制问题
显式企业身份核验只访问指定企业,避免回退到全量查询。
复制只清空源单存在的发票与附件字段,避免通用模板拒绝未知属性。
补充隔离回归与指定测试企业验收记录,测试数据已清理。

验证:929 项测试通过,类型检查及版本一致性检查通过。
2026-10-29 22:04:36 +08:00

20 lines
1.3 KiB
TypeScript

import { expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import ts from "typescript";
test("DataLink 公共 SDK 的 README 示例与实际导出一同编译", () => {
const root = resolve(import.meta.dir, "..");
const readme = readFileSync(resolve(root, "src/domains/datalink/README.datalink.md"), "utf8");
const code = readme.split("## 公共 SDK")[1]?.match(/```typescript\n([\s\S]*?)\n```/)?.[1];
expect(code).toBeDefined();
const file = resolve(root, "src/__sdk-readme-example__.ts");
const source = code!.replace('"hose-use/sdk"', '"./sdk.js"');
const options: ts.CompilerOptions = { noEmit: true, strict: true, skipLibCheck: true, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler, target: ts.ScriptTarget.ESNext, types: ["bun"] };
const host = ts.createCompilerHost(options);
const original = host.getSourceFile;
host.getSourceFile = (name, ...args) => resolve(name) === file ? ts.createSourceFile(file, source, ts.ScriptTarget.ESNext, true) : original(name, ...args);
const diagnostics = ts.getPreEmitDiagnostics(ts.createProgram([file], options, host));
expect(diagnostics.map(d => ts.flattenDiagnosticMessageText(d.messageText, "\n"))).toEqual([]);
}, 15000);