test: 修复 Windows Prisma 测试启动
This commit is contained in:
parent
5a679569ea
commit
e0b0457b8b
@ -8,11 +8,12 @@ const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const testPrefix = 'yyd-notification-center-test-'
|
||||
const testRoot = mkdtempSync(join(tmpdir(), testPrefix))
|
||||
const databasePath = join(testRoot, 'notifications.db')
|
||||
const databaseUrl = `file:${databasePath}`
|
||||
// Prisma 的 SQLite file URL 必须使用正斜杠;Windows 原生反斜杠会让 schema-engine 无细节退出。
|
||||
const databaseUrl = `file:${databasePath.split(sep).join('/')}`
|
||||
const childEnv = { ...process.env, DATABASE_URL: databaseUrl }
|
||||
// Prisma 5.22 的 Windows schema-engine 在部分主机未初始化 Rust 日志时会无细节提前退出。
|
||||
// 只在 Windows 测试子进程中启用;Linux/Docker 不受影响,也不会记录数据库内容或密钥。
|
||||
if (process.platform === 'win32' && !childEnv.RUST_LOG) childEnv.RUST_LOG = 'trace'
|
||||
if (process.platform === 'win32') childEnv.RUST_LOG = 'trace'
|
||||
|
||||
const runNode = (args) => {
|
||||
const result = spawnSync(process.execPath, args, {
|
||||
@ -38,7 +39,8 @@ const removeTestRoot = () => {
|
||||
let exitCode = 0
|
||||
try {
|
||||
const prismaCli = resolve(repoRoot, 'node_modules', 'prisma', 'build', 'index.js')
|
||||
const schema = resolve(repoRoot, 'prisma', 'schema.prisma')
|
||||
// cwd 已固定为 repoRoot;避免 Windows schema-engine 处理含空格的绝对 schema 路径失败。
|
||||
const schema = 'prisma/schema.prisma'
|
||||
exitCode = runNode([prismaCli, 'migrate', 'deploy', '--schema', schema])
|
||||
if (exitCode === 0) {
|
||||
const tsxCli = resolve(repoRoot, 'node_modules', 'tsx', 'dist', 'cli.mjs')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user