Skip to content

Commit

Permalink
Fix JSON reporting properly
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Mar 6, 2024
1 parent eebee38 commit 164b08f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions bin/test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ArrayMap extends Map {

class RemoteRunner {
constructor(browser) {
this.failed = false;
this.browser = browser;
this.handlers = new ArrayMap();
this.onceHandlers = new ArrayMap();
Expand Down Expand Up @@ -119,21 +120,21 @@ class RemoteRunner {
}
}

async handleEnd(failed) {
async handleEnd() {
closeRequested = true;
await this.browser.close();
this.completedOk = !failed;
process.exit(failed ? 1 : 0);
process.exit(this.failed ? 1 : 0);
}

handleFailed() {
this.failed = true;
if (bail) {
try {
this.triggerHandlers('end');
} catch (e) {
console.log('An error occurred while bailing:', e);
} finally {
this.handleEnd(true);
this.handleEnd();
}
}
}
Expand All @@ -147,7 +148,9 @@ function BenchmarkConsoleReporter(runner) {

function BenchmarkJsonReporter(runner) {
runner.on('end', results => {
if (runner.completedOk) {
if (runner.failed) {
console.log('Runner failed; JSON will not be writted.');
} else {
const { mkdirSync, writeFileSync } = require('fs');

results.srcRoot = process.env.SRC_ROOT;
Expand All @@ -158,8 +161,6 @@ function BenchmarkJsonReporter(runner) {
const jsonPath = `${resultsDir}/${new Date().toISOString()}.json`;
writeFileSync(jsonPath, JSON.stringify(results, null, 2));
console.log('Wrote JSON results to:', jsonPath);
} else {
console.log('Runner failed; JSON will not be writted.');
}
});
}
Expand Down

0 comments on commit 164b08f

Please sign in to comment.