Skip to content

Commit 7d874a1

Browse files
authored
perf-tests: add option to save benchmarks to file (#8759)
1 parent cb5cd95 commit 7d874a1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ package-lock.json
2525
yarn.lock
2626
/.eslintcache
2727
release-todo.txt
28+
/perf-test-results/

bin/test-browser.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,44 @@ class RemoteRunner {
136136
}
137137
}
138138

139-
function BenchmarkReporter(runner) {
139+
function BenchmarkConsoleReporter(runner) {
140140
runner.on('benchmark:result', function (obj) {
141141
console.log(' ', obj);
142142
});
143143
}
144144

145+
function BenchmarkJsonReporter(runner) {
146+
runner.on('end', results => {
147+
if (runner.completed) {
148+
const { mkdirSync, writeFileSync } = require('fs');
149+
150+
const resultsDir = 'perf-test-results';
151+
mkdirSync(resultsDir, { recursive: true });
152+
153+
const jsonPath = `${resultsDir}/${new Date().toISOString()}.json`;
154+
writeFileSync(jsonPath, JSON.stringify(results, null, 2));
155+
console.log('Wrote JSON results to:', jsonPath);
156+
} else {
157+
console.log('Runner failed; JSON will not be writted.');
158+
}
159+
});
160+
}
161+
145162
async function startTest() {
146163

147164
console.log('Starting', browserName, 'on', testUrl);
148165

149166
const runner = new RemoteRunner();
150167
new MochaSpecReporter(runner);
151-
new BenchmarkReporter(runner);
168+
new BenchmarkConsoleReporter(runner);
169+
170+
if (process.env.JSON_REPORTER) {
171+
if (!process.env.PERF) {
172+
console.log('!!! JSON_REPORTER should only be set if PERF is also set.');
173+
process.exit(1);
174+
}
175+
new BenchmarkJsonReporter(runner);
176+
}
152177

153178
const options = {
154179
headless: true,

0 commit comments

Comments
 (0)