87 lines
2.6 KiB
JavaScript
87 lines
2.6 KiB
JavaScript
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
|
|
};
|
|
|
|
function loadTestResults() {
|
|
if (!fs.existsSync(resultsPath)) {
|
|
console.error('❌ Test results not found!');
|
|
process.exit(1);
|
|
}
|
|
|
|
const data = fs.readFileSync(resultsPath, 'utf-8');
|
|
return JSON.parse(data);
|
|
}
|
|
|
|
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)
|
|
};
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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();
|