64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { existsSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { test } from "node:test";
|
|
import {
|
|
miniappArtifactRoot,
|
|
miniappProjectPath,
|
|
miniappReleaseProjectPath,
|
|
miniappReleaseOutputRoot,
|
|
REPOSITORY_ROOT,
|
|
} from "../src/modules/admin/miniapp-artifact.js";
|
|
|
|
test("小程序产物根目录锚定仓库根目录,不随 API 进程工作目录变化", () => {
|
|
const configured = process.env.MINIAPP_ARTIFACT_ROOT;
|
|
delete process.env.MINIAPP_ARTIFACT_ROOT;
|
|
try {
|
|
assert.ok(existsSync(resolve(REPOSITORY_ROOT, "pnpm-workspace.yaml")));
|
|
assert.equal(miniappArtifactRoot(), resolve(REPOSITORY_ROOT, "apps/taro/dist"));
|
|
assert.ok(!miniappArtifactRoot().includes(resolve(REPOSITORY_ROOT, "apps/api")));
|
|
} finally {
|
|
if (configured !== undefined) process.env.MINIAPP_ARTIFACT_ROOT = configured;
|
|
}
|
|
});
|
|
|
|
test("按模板包 key 生成唯一的微信小程序产物目录", () => {
|
|
const configured = process.env.MINIAPP_ARTIFACT_ROOT;
|
|
delete process.env.MINIAPP_ARTIFACT_ROOT;
|
|
try {
|
|
assert.equal(
|
|
miniappProjectPath("linjing-editorial"),
|
|
resolve(REPOSITORY_ROOT, "apps/taro/dist/linjing-editorial/weapp"),
|
|
);
|
|
} finally {
|
|
if (configured !== undefined) process.env.MINIAPP_ARTIFACT_ROOT = configured;
|
|
}
|
|
});
|
|
|
|
test("显式配置的产物根目录按仓库根目录解析相对路径", () => {
|
|
assert.equal(
|
|
miniappArtifactRoot("custom/artifacts"),
|
|
resolve(REPOSITORY_ROOT, "custom/artifacts"),
|
|
);
|
|
assert.equal(miniappArtifactRoot("/srv/miniapp"), resolve("/srv/miniapp"));
|
|
});
|
|
|
|
test("发布产物路径隔离品牌、模板版本和 attempt", () => {
|
|
const root = miniappReleaseOutputRoot("brand-a", "linjing-editorial", "1.0.4", "attempt-1");
|
|
assert.equal(
|
|
root,
|
|
resolve(REPOSITORY_ROOT, "apps/taro/dist/releases/brand-a/linjing-editorial@1.0.4/attempt-1"),
|
|
);
|
|
assert.equal(
|
|
miniappReleaseProjectPath("brand-a", "linjing-editorial", "1.0.4", "attempt-1"),
|
|
`${root}/weapp`,
|
|
);
|
|
});
|
|
|
|
test("发布产物路径拒绝可能越界的品牌或模板字段", () => {
|
|
assert.throws(
|
|
() => miniappReleaseOutputRoot("../brand", "food", "1.0.0", "attempt-1"),
|
|
/Invalid brand slug/,
|
|
);
|
|
});
|