feat: 更新UAT测试配置和修复数据库连接问题
refactor(测试): 重构用户数据加载逻辑以支持数组格式 fix(数据库): 修正数据库连接配置和凭证 test: 添加新的导航和用户管理测试场景 docs: 生成UAT测试报告和最终报告 ci: 更新Woodpecker CI配置和测试命令 build: 添加application-test.yml配置文件 chore: 清理旧的测试场景文件
This commit is contained in:
+37
-76
@@ -1,86 +1,47 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const resultsPath = path.join(__dirname, 'test-results', 'results.json');
|
||||
const qualityGateThresholds = {
|
||||
passRate: 95,
|
||||
flakyRate: 5,
|
||||
duration: 600000
|
||||
};
|
||||
console.log('🚦 Checking UAT Quality Gate...');
|
||||
|
||||
function loadTestResults() {
|
||||
if (!fs.existsSync(resultsPath)) {
|
||||
console.error('❌ Test results not found!');
|
||||
process.exit(1);
|
||||
}
|
||||
const resultsPath = path.join(__dirname, 'test-results');
|
||||
const lastRunPath = path.join(resultsPath, 'artifacts', '.last-run.json');
|
||||
|
||||
const data = fs.readFileSync(resultsPath, 'utf-8');
|
||||
return JSON.parse(data);
|
||||
console.log('📁 Looking for results in:', resultsPath);
|
||||
console.log('📄 Expected last-run file:', lastRunPath);
|
||||
|
||||
if (!fs.existsSync(resultsPath)) {
|
||||
console.log('❌ Test results directory not found!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function calculateMetrics(results) {
|
||||
const totalTests = results.stats.expected;
|
||||
const passedTests = results.stats.expected - results.stats.failed;
|
||||
const failedTests = results.stats.failed;
|
||||
const flakyTests = results.stats.flaky;
|
||||
const duration = results.stats.duration;
|
||||
|
||||
const passRate = (passedTests / totalTests) * 100;
|
||||
const flakyRate = (flakyTests / totalTests) * 100;
|
||||
|
||||
return {
|
||||
totalTests,
|
||||
passedTests,
|
||||
failedTests,
|
||||
flakyTests,
|
||||
duration,
|
||||
passRate: passRate.toFixed(2),
|
||||
flakyRate: flakyRate.toFixed(2)
|
||||
};
|
||||
if (!fs.existsSync(lastRunPath)) {
|
||||
console.log('❌ Last run results not found!');
|
||||
console.log('📁 Available files:', fs.readdirSync(resultsPath));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function checkQualityGate(metrics) {
|
||||
const failures = [];
|
||||
|
||||
if (metrics.passRate < qualityGateThresholds.passRate) {
|
||||
failures.push(`Pass rate (${metrics.passRate}%) is below threshold (${qualityGateThresholds.passRate}%)`);
|
||||
}
|
||||
|
||||
if (metrics.flakyRate > qualityGateThresholds.flakyRate) {
|
||||
failures.push(`Flaky rate (${metrics.flakyRate}%) is above threshold (${qualityGateThresholds.flakyRate}%)`);
|
||||
}
|
||||
|
||||
if (metrics.duration > qualityGateThresholds.duration) {
|
||||
failures.push(`Test duration (${metrics.duration}ms) exceeds threshold (${qualityGateThresholds.duration}ms)`);
|
||||
}
|
||||
|
||||
return failures;
|
||||
try {
|
||||
const lastRun = JSON.parse(fs.readFileSync(lastRunPath, 'utf-8'));
|
||||
|
||||
console.log('📊 UAT Test Results:');
|
||||
console.log(` Status: ${lastRun.status}`);
|
||||
console.log(` Failed Tests: ${lastRun.failedTests.length}`);
|
||||
|
||||
if (lastRun.failedTests.length > 0) {
|
||||
console.log('❌ Quality Gate FAILED:');
|
||||
console.log(` - ${lastRun.failedTests.length} test(s) failed`);
|
||||
lastRun.failedTests.forEach(test => console.log(` - ${test}`));
|
||||
process.exit(1);
|
||||
} else if (lastRun.status === 'passed') {
|
||||
console.log('✅ Quality Gate PASSED');
|
||||
console.log('🎉 All UAT tests meet quality standards!');
|
||||
} else {
|
||||
console.log('⚠️ Quality Gate WARNING:');
|
||||
console.log(` - Test status: ${lastRun.status}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log('❌ Error reading test results:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function main() {
|
||||
console.log('🚦 Checking UAT Quality Gate...\n');
|
||||
|
||||
const results = loadTestResults();
|
||||
const metrics = calculateMetrics(results);
|
||||
const failures = checkQualityGate(metrics);
|
||||
|
||||
console.log('📊 Test Metrics:');
|
||||
console.log(` Total Tests: ${metrics.totalTests}`);
|
||||
console.log(` Passed: ${metrics.passedTests}`);
|
||||
console.log(` Failed: ${metrics.failedTests}`);
|
||||
console.log(` Flaky: ${metrics.flakyTests}`);
|
||||
console.log(` Pass Rate: ${metrics.passRate}%`);
|
||||
console.log(` Flaky Rate: ${metrics.flakyRate}%`);
|
||||
console.log(` Duration: ${metrics.duration}ms\n`);
|
||||
|
||||
if (failures.length === 0) {
|
||||
console.log('✅ Quality Gate Passed!');
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.log('❌ Quality Gate Failed:');
|
||||
failures.forEach(failure => console.log(` - ${failure}`));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user