feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
@@ -0,0 +1,40 @@
|
||||
const { randomBytes } = require("node:crypto");
|
||||
const { spawnSync } = require("node:child_process");
|
||||
const { PrismaClient } = require("@prisma/client");
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
if (!databaseUrl) throw new Error("DATABASE_URL is required for integration tests");
|
||||
|
||||
const schema = `pb_test_${randomBytes(8).toString("hex")}`;
|
||||
const testUrl = new URL(databaseUrl);
|
||||
testUrl.searchParams.set("schema", schema);
|
||||
const testEnvironment = { ...process.env, DATABASE_URL: testUrl.toString(), NODE_ENV: "test" };
|
||||
const administrator = new PrismaClient();
|
||||
|
||||
function run(command, args) {
|
||||
const result = spawnSync(command, args, { stdio: "inherit", env: testEnvironment });
|
||||
if (result.error) throw result.error;
|
||||
return result.status ?? 1;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let created = false;
|
||||
let status = 1;
|
||||
try {
|
||||
await administrator.$executeRawUnsafe(`CREATE SCHEMA "${schema}"`);
|
||||
created = true;
|
||||
if (run("pnpm", ["exec", "prisma", "migrate", "deploy"]) !== 0) return status;
|
||||
if (run("pnpm", ["db:seed"]) !== 0) return status;
|
||||
status = run(process.execPath, ["--test", "test/http.integration.test.js"]);
|
||||
return status;
|
||||
} finally {
|
||||
if (created) await administrator.$executeRawUnsafe(`DROP SCHEMA "${schema}" CASCADE`);
|
||||
await administrator.$disconnect();
|
||||
process.exitCode = status;
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in new issue
Block a user