Files
photo-live/apps/admin/e2e/global-setup.ts
T

25 lines
943 B
TypeScript
Raw Normal View History

// e2e 全局夹具:幂等种子管理员账号(复用 services/api 官方路径)。
// `pnpm --filter @photo/api-cn seed` 读仓库根 .env 的 ADMIN_ACCOUNT/ADMIN_PASSWORD;
// 账号已存在则跳过且绝不改写密码(seed-admin.ts 语义),重复跑 e2e 安全。
import { execSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const repoRoot = fileURLToPath(new URL('../../..', import.meta.url))
const envFile = join(repoRoot, '.env')
export default function globalSetup(): void {
if (!existsSync(envFile)) {
throw new Error(
`[admin e2e] 仓库根 .env 不存在(${envFile}):请参考 .env.example 配置开发环境`
)
}
// shell:true 兼容 Windows(pnpm 是 .cmd)
execSync('pnpm --filter @photo/api-cn seed', {
cwd: dirname(envFile),
stdio: 'inherit',
shell: true
})
}