feat: 收口多品牌与模板构建基础

This commit is contained in:
que01 committed 2026-09-25 02:55:46 +08:00
1 parent 0425a1c672
commit 77224ea51f
317 files changed
+11290 -1158

No files matched your search

@@ -0,0 +1,45 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const vm = require("node:vm");
const source = fs.readFileSync(path.join(__dirname, "../utils/runtime-workspace.js"), "utf8");
function loadWithResponse(response) {
const module = { exports: {} };
const storage = {
getStorageSync() {
throw new Error("不应读取旧缓存");
},
setStorageSync() {
throw new Error("不应缓存公开内容");
},
};
vm.runInNewContext(source, {
module,
wx: storage,
require(id) {
if (id === "./request") return { request: () => Promise.resolve(response) };
if (id === "./module-registry") return { resolveRuntime: () => ({}) };
throw new Error(`意外依赖:${id}`);
},
});
return module.exports.loadWorkspaceWithFallback();
}
test("未发布品牌不会使用旧 workspace 缓存", async () => {
await assert.rejects(
loadWithResponse({ publication: { status: "unpublished" }, brand: null }),
/品牌尚未发布/,
);
});
test("已发布 workspace 正常返回", async () => {
const workspace = await loadWithResponse({
publication: { status: "published" },
brand: { name: "测试品牌" },
offerings: [],
});
assert.equal(workspace.brand.name, "测试品牌");
});