49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
/**
|
||
* R9/R35 测试:Prisma 连接池配置
|
||
*
|
||
* 验证:
|
||
* 1. 生产环境只记录 error 和 warn
|
||
* 2. 开发环境记录 query、error、warn
|
||
*/
|
||
|
||
describe('R9/R35: Prisma 连接池配置', () => {
|
||
afterEach(() => {
|
||
// 清除模块缓存
|
||
jest.resetModules()
|
||
})
|
||
|
||
it('生产环境应该只记录 error 和 warn', () => {
|
||
// 读取 prisma.ts 源代码,检查配置逻辑
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
const prismaPath = path.join(__dirname, '..', 'prisma.ts')
|
||
const content = fs.readFileSync(prismaPath, 'utf-8')
|
||
|
||
// 验证生产环境日志配置
|
||
expect(content).toContain("process.env.NODE_ENV === 'production'")
|
||
expect(content).toContain("['error', 'warn']")
|
||
})
|
||
|
||
it('开发环境应该记录 query、error、warn', () => {
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
const prismaPath = path.join(__dirname, '..', 'prisma.ts')
|
||
const content = fs.readFileSync(prismaPath, 'utf-8')
|
||
|
||
// 验证开发环境日志配置
|
||
expect(content).toContain("['query', 'error', 'warn']")
|
||
})
|
||
|
||
it('应该有连接池配置说明', () => {
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
const prismaPath = path.join(__dirname, '..', 'prisma.ts')
|
||
const content = fs.readFileSync(prismaPath, 'utf-8')
|
||
|
||
// 验证有连接池配置说明
|
||
expect(content).toContain('R9/R35修复')
|
||
expect(content).toContain('connection_limit')
|
||
expect(content).toContain('pool_timeout')
|
||
})
|
||
})
|