新增: - 书库导入导出(library_import/library_export)及测试 - 图片变体生成(image_variants)与响应式图片(responsiveImage) - 书籍搜索(bookSearch)+ BookSearch/LibrarySearchGrid 组件 - 小组件运行时(widgetRuntime)与静态检查(widgetLint) - 上传缓存中间件(upload_cache)与字体 CSS 提取脚本 其它: - 后端 handlers/services 全量调整 - 前端页面、组件、库函数与配置更新
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import { mergeWidgetCode, parseMixedWidgetCode } from "./widgetCode.ts";
|
|
|
|
describe("parseMixedWidgetCode", () => {
|
|
it("拆分混写的 style/script 段", () => {
|
|
const r = parseMixedWidgetCode(
|
|
`<div class="a">hi</div>\n<style>.a { color: red; }</style>\n<script>console.log(1);</script>`
|
|
);
|
|
assert.equal(r.html, `<div class="a">hi</div>`);
|
|
assert.equal(r.css, `.a { color: red; }`);
|
|
assert.equal(r.js, `console.log(1);`);
|
|
});
|
|
|
|
it("多段 style/script 按序拼接", () => {
|
|
const r = parseMixedWidgetCode(`<style>.a{}</style><style>.b{}</style><p>x</p><script>a();</script><script>b();</script>`);
|
|
assert.equal(r.css, ".a{}\n\n.b{}");
|
|
assert.equal(r.js, "a();\n\nb();");
|
|
assert.equal(r.html, "<p>x</p>");
|
|
});
|
|
|
|
it("纯 HTML 不误伤", () => {
|
|
const r = parseMixedWidgetCode(`<p>hello</p>`);
|
|
assert.deepEqual(r, { html: "<p>hello</p>", css: "", js: "" });
|
|
});
|
|
|
|
it("外链与非 JS type 的 script 留在 html", () => {
|
|
const code = `<script src="https://x/y.js"></script><script type="application/json">{"a":1}</script><script>z();</script>`;
|
|
const r = parseMixedWidgetCode(code);
|
|
assert.equal(r.js, "z();");
|
|
assert.equal(
|
|
r.html,
|
|
`<script src="https://x/y.js"></script><script type="application/json">{"a":1}</script>`
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("mergeWidgetCode", () => {
|
|
it("合并后再解析可还原三字段", () => {
|
|
const parts = { html: "<b>go</b>", css: "b { font-size: 18px; }", js: "x();" };
|
|
assert.deepEqual(parseMixedWidgetCode(mergeWidgetCode(parts)), parts);
|
|
});
|
|
|
|
it("空段不产生标签", () => {
|
|
assert.equal(mergeWidgetCode({ html: "hi", css: "", js: "" }), "hi");
|
|
});
|
|
});
|