-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcustom-reporter.js
More file actions
143 lines (125 loc) Β· 5.88 KB
/
custom-reporter.js
File metadata and controls
143 lines (125 loc) Β· 5.88 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import fs from 'fs-extra';
import os from 'os';
import { execSync } from 'child_process';
class BenchmarkSystemReporter {
onBegin(config, suite) {
const systemInfo = this.getSystemInfo();
const browserInfo = this.getBrowserInfo();
// Store comprehensive system info
const fullSystemInfo = {
...systemInfo,
browsers: browserInfo,
benchmarkRun: {
timestamp: new Date().toISOString(),
playwrightProjects: config.projects?.map(p => p.name) || [],
totalTests: suite.allTests().length
}
};
// Write detailed system info to file for benchmark results
fs.writeJsonSync('benchmark-system-info.json', fullSystemInfo, { spaces: 2 });
// Enhanced console output for benchmarks
console.log('\n' + '='.repeat(50));
console.log('π BENCHMARK SYSTEM INFORMATION');
console.log('='.repeat(50));
console.log(`π₯οΈ OS: ${systemInfo.os} ${systemInfo.osVersion} (${systemInfo.arch})`);
console.log(`πΎ RAM: ${systemInfo.totalMemory}GB (Available: ${systemInfo.freeMemory}GB)`);
console.log(`β‘ CPU: ${systemInfo.cpuModel} (${systemInfo.cpuCores} cores @ ${systemInfo.cpuSpeed}GHz)`);
console.log(`π¦ Node.js: ${systemInfo.nodeVersion}`);
console.log(`π Playwright: ${systemInfo.playwrightVersion}`);
if (browserInfo.chrome) console.log(`π Chrome: ${browserInfo.chrome}`);
if (browserInfo.firefox) console.log(`π¦ Firefox: ${browserInfo.firefox}`);
if (browserInfo.safari) console.log(`π§ Safari: ${browserInfo.safari}`);
console.log(`π Running ${suite.allTests().length} tests across ${config.projects?.length || 1} browsers`);
console.log('='.repeat(50) + '\n');
}
getSystemInfo() {
let osVersion = os.release();
let cpuModel = 'Unknown';
let cpuSpeed = 'Unknown';
// Get more detailed system info
try {
if (process.platform === 'darwin') {
osVersion = execSync('sw_vers -productVersion', { encoding: 'utf8' }).trim();
cpuModel = execSync('sysctl -n machdep.cpu.brand_string', { encoding: 'utf8' }).trim();
cpuSpeed = execSync('sysctl -n hw.cpufrequency_max', { encoding: 'utf8' }).trim();
cpuSpeed = cpuSpeed ? (parseInt(cpuSpeed) / 1000000000).toFixed(1) : 'Unknown';
} else if (process.platform === 'linux') {
const releaseInfo = execSync('cat /etc/os-release', { encoding: 'utf8' });
const versionMatch = releaseInfo.match(/VERSION="([^"]+)"/);
if (versionMatch) osVersion = versionMatch[1];
const cpuInfo = execSync('cat /proc/cpuinfo | grep "model name" | head -1', { encoding: 'utf8' });
const cpuMatch = cpuInfo.match(/model name\s*:\s*(.+)/);
if (cpuMatch) cpuModel = cpuMatch[1].trim();
} else if (process.platform === 'win32') {
osVersion = execSync('ver', { encoding: 'utf8' }).trim();
cpuModel = execSync('wmic cpu get name /value | findstr Name=', { encoding: 'utf8' }).replace('Name=', '').trim();
}
} catch (e) {
// Fallback to basic info
}
return {
os: this.getOSName(),
osVersion,
arch: process.arch,
platform: process.platform,
totalMemory: Math.round(os.totalmem() / (1024 ** 3)),
freeMemory: Math.round(os.freemem() / (1024 ** 3)),
cpuCores: os.cpus().length,
cpuModel,
cpuSpeed,
nodeVersion: process.version,
playwrightVersion: fs.readJsonSync('./node_modules/@playwright/test/package.json', 'utf8').version,
timestamp: new Date().toISOString(),
loadAverage: os.loadavg(),
uptime: Math.round(os.uptime() / 3600), // hours
};
}
getBrowserInfo() {
const browsers = {};
try {
// Chrome version
if (process.platform === 'darwin') {
browsers.chrome = execSync('"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" --version 2>/dev/null || echo "Not found"', { encoding: 'utf8' }).trim();
} else if (process.platform === 'linux') {
browsers.chrome = execSync('google-chrome --version 2>/dev/null || chromium-browser --version 2>/dev/null || echo "Not found"', { encoding: 'utf8' }).trim();
} else if (process.platform === 'win32') {
browsers.chrome = execSync('reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version 2>nul || echo "Not found"', { encoding: 'utf8' }).trim();
}
// Firefox version
if (process.platform === 'darwin') {
browsers.firefox = execSync('/Applications/Firefox.app/Contents/MacOS/firefox --version 2>/dev/null || echo "Not found"', { encoding: 'utf8' }).trim();
} else if (process.platform === 'linux') {
browsers.firefox = execSync('firefox --version 2>/dev/null || echo "Not found"', { encoding: 'utf8' }).trim();
} else if (process.platform === 'win32') {
browsers.firefox = execSync('firefox --version 2>nul || echo "Not found"', { encoding: 'utf8' }).trim();
}
// Safari (macOS only)
if (process.platform === 'darwin') {
browsers.safari = execSync('mdls -name kMDItemVersion /Applications/Safari.app 2>/dev/null || echo "Not found"', { encoding: 'utf8' }).trim();
if (browsers.safari !== 'Not found') {
browsers.safari = `Safari ${browsers.safari}`;
}
}
} catch (e) {
// Fallback - some browsers might not be installed
}
return browsers;
}
getOSName() {
const platform = process.platform;
switch (platform) {
case 'darwin': return 'macOS';
case 'win32': return 'Windows';
case 'linux': return 'Linux';
default: return platform;
}
}
onEnd(result) {
const duration = result.duration || 0;
console.log(`\n Benchmark completed in ${Math.round(duration / 1000)}s`);
console.log(`β
Passed: ${result.stats?.passed || 0}`);
console.log(`β Failed: ${result.stats?.failed || 0}`);
console.log(`βοΈ Skipped: ${result.stats?.skipped || 0}`);
}
}
export default BenchmarkSystemReporter;