package.json test:e2e:prepare 现在是 migrate reset --force && prisma generate && seed 为 seed 运行时补充 JS Prisma client 生成器: schema.prisma 修复 seed 在 ESM/CJS 下的 Prisma 导入兼容: seed.mjs 修复 Jest 环境未加载 .env 导致连到 127.0.0.1 的问题: e2e-app.helper.ts 修复夹具依赖“名称”导致被组织测试改名后失效的问题(改为按 seed openId 反查): e2e-fixtures.helper.ts 修复组织测试的状态污染与清理逻辑,并收敛 afterAll 资源释放: organization.e2e-spec.ts e2e-context.helper.ts
39 lines
932 B
TypeScript
39 lines
932 B
TypeScript
import type { INestApplication } from '@nestjs/common';
|
|
import { PrismaService } from '../../../src/prisma.service.js';
|
|
import { loginAllRoles, type E2EAccessTokenMap } from './e2e-auth.helper.js';
|
|
import { createE2eApp } from './e2e-app.helper.js';
|
|
import {
|
|
loadSeedFixtures,
|
|
type E2ESeedFixtures,
|
|
} from './e2e-fixtures.helper.js';
|
|
|
|
export interface E2EContext {
|
|
app: INestApplication;
|
|
prisma: PrismaService;
|
|
tokens: E2EAccessTokenMap;
|
|
fixtures: E2ESeedFixtures;
|
|
}
|
|
|
|
export async function createE2EContext(): Promise<E2EContext> {
|
|
const app = await createE2eApp();
|
|
const prisma = app.get(PrismaService);
|
|
const fixtures = await loadSeedFixtures(prisma);
|
|
const tokens = await loginAllRoles(app);
|
|
|
|
return {
|
|
app,
|
|
prisma,
|
|
fixtures,
|
|
tokens,
|
|
};
|
|
}
|
|
|
|
export async function closeE2EContext(ctx?: E2EContext) {
|
|
if (!ctx) {
|
|
return;
|
|
}
|
|
|
|
await ctx.prisma.$disconnect();
|
|
await ctx.app.close();
|
|
}
|