mirror of
https://github.com/sinanyuntu/trade-message-center.git
synced 2026-09-17 13:22:11 +08:00
46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
// 验证开发启动的产物边界与顺序
|
|
|
|
import assert from "node:assert/strict";
|
|
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import test from "node:test";
|
|
|
|
import { cleanGeneratedDist, GENERATED_DIST_RELATIVE_PATHS } from "./clean-generated-dist.mjs";
|
|
|
|
const contractBuildCommand = "pnpm --filter @trade-message-center/onetalk-contract build";
|
|
|
|
test("cleans only the explicit workspace package dist directories", () => {
|
|
const rootDir = mkdtempSync(join(tmpdir(), "tmc-dev-dist-"));
|
|
const retainedPath = join(rootDir, "retain.txt");
|
|
try {
|
|
for (const relativePath of GENERATED_DIST_RELATIVE_PATHS) {
|
|
const distPath = join(rootDir, relativePath);
|
|
mkdirSync(distPath, { recursive: true });
|
|
writeFileSync(join(distPath, "artifact.js"), "generated");
|
|
}
|
|
writeFileSync(retainedPath, "keep");
|
|
|
|
cleanGeneratedDist(rootDir);
|
|
|
|
for (const relativePath of GENERATED_DIST_RELATIVE_PATHS) {
|
|
assert.equal(existsSync(join(rootDir, relativePath)), false);
|
|
}
|
|
assert.equal(existsSync(retainedPath), true);
|
|
} finally {
|
|
rmSync(rootDir, { force: true, recursive: true });
|
|
}
|
|
});
|
|
|
|
test("builds the shared contract before starting core development apps", async () => {
|
|
const rootPackage = await import("../package.json", { with: { type: "json" } });
|
|
const rootDev = rootPackage.default.scripts.dev;
|
|
|
|
assert.match(rootDev, /^pnpm run clean:dist && /u);
|
|
assert.match(rootDev, /&& pnpm run version:ensure && /u);
|
|
assert.match(
|
|
rootDev,
|
|
new RegExp(`&& ${contractBuildCommand} && node scripts/with-build-hash\\.mjs`),
|
|
);
|
|
});
|