-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathperformance-test.js
More file actions
79 lines (67 loc) · 2.6 KB
/
performance-test.js
File metadata and controls
79 lines (67 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { test as base } from 'appwright';
import { PerformanceTracker } from '../reporters/PerformanceTracker.js';
import QualityGatesValidator from '../utils/QualityGatesValidator.js';
// Create a custom test fixture that handles performance tracking and cleanup
export const test = base.extend({
// eslint-disable-next-line no-empty-pattern
performanceTracker: async ({}, use, testInfo) => {
const performanceTracker = new PerformanceTracker();
// Provide the tracker to the test
await use(performanceTracker);
// After test completes, handle performance metrics and session cleanup
console.log('🔍 Post-test cleanup: attaching performance metrics...');
console.log(
`📊 Found ${performanceTracker.timers.length} timers in tracker`,
);
if (performanceTracker.timers.length === 0) {
console.log('⚠️ No timers found in performance tracker');
}
// Always try to attach performance metrics, even if test failed
try {
const metrics = await performanceTracker.attachToTest(testInfo);
console.log(
`✅ Performance metrics attached: ${
metrics.steps.length
} steps, ${metrics.total.toFixed(2)}s total`,
);
} catch (error) {
console.error('❌ Failed to attach performance metrics:', error.message);
}
// Validate quality gates if any timer has thresholds defined
const hasThresholds = performanceTracker.timers.some((t) =>
t.hasThreshold(),
);
if (hasThresholds) {
console.log('🔍 Validating quality gates...');
QualityGatesValidator.assertThresholds(
testInfo.title,
performanceTracker.timers,
);
console.log('✅ Quality gates PASSED');
}
console.log('🔍 Looking for session ID...');
let sessionId = null;
if (testInfo && testInfo.annotations) {
sessionId = testInfo.annotations.find(
(annotation) => annotation.type === 'sessionId',
)?.description;
}
if (sessionId) {
// Store session data as a test attachment for the reporter to find
await testInfo.attach('session-data', {
body: JSON.stringify({
sessionId,
testTitle: testInfo.title,
projectName: testInfo.project.name,
timestamp: new Date().toISOString(),
}),
contentType: 'application/json',
});
await performanceTracker.storeSessionData(sessionId, testInfo.title);
console.log(`✅ Session data stored: ${sessionId}`);
} else {
console.log('⚠️ No session ID found - video URL cannot be retrieved');
}
},
});
export { expect } from 'appwright';