You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 lines
1.9 KiB

#!/usr/bin/env node
/**
* 数据库模块测试运行脚本
* 用于验证数据库优化效果
*/
import { exec } from 'child_process'
import { promisify } from 'util'
const execAsync = promisify(exec)
async function runDatabaseTests() {
console.log('开始运行数据库模块测试...\n')
try {
// 运行数据库相关测试
console.log('1. 运行 BaseModel 测试...')
await execAsync('bun test tests/db/BaseModel.test.js', { stdio: 'inherit' })
console.log('✓ BaseModel 测试通过\n')
console.log('2. 运行 UserModel 测试...')
await execAsync('bun test tests/db/UserModel.test.js', { stdio: 'inherit' })
console.log('✓ UserModel 测试通过\n')
console.log('3. 运行缓存测试...')
await execAsync('bun test tests/db/cache.test.js', { stdio: 'inherit' })
console.log('✓ 缓存测试通过\n')
console.log('4. 运行事务测试...')
await execAsync('bun test tests/db/transaction.test.js', { stdio: 'inherit' })
console.log('✓ 事务测试通过\n')
console.log('5. 运行性能测试...')
await execAsync('bun test tests/db/performance.test.js', { stdio: 'inherit' })
console.log('✓ 性能测试通过\n')
console.log('🎉 所有数据库模块测试都已通过!')
console.log('\n测试总结:')
console.log('- BaseModel 功能正常')
console.log('- UserModel 功能正常')
console.log('- 缓存机制工作正常')
console.log('- 事务处理功能正常')
console.log('- 性能监控功能正常')
} catch (error) {
console.error('测试运行失败:', error.message)
process.exit(1)
}
}
// 如果直接运行此脚本,则执行测试
if (import.meta.url === `file://${process.argv[1]}`) {
runDatabaseTests()
}
export default runDatabaseTests