Skip to content

Commit

Permalink
perf-tests: fix JSON reporter (pouchdb#8876)
Browse files Browse the repository at this point in the history
Since runner.completed was removed in dc97aed,
env var JSON_REPORTER has not worked.

This also changes the exit status code for perf tests: previously the process
would always exit with status 0, even if there was a test failure.  Test
failure(s) will now result in an exit status of 0.

Co-authored-by: alxndrsn <alxndrsn>
  • Loading branch information
alxndrsn authored Mar 7, 2024
1 parent 6d9d5e1 commit 5cd750f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bin/test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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 @@ -120,20 +121,21 @@ class RemoteRunner {
}
}

async handleEnd(failed) {
async handleEnd() {
closeRequested = true;
await this.browser.close();
process.exit(!process.env.PERF && 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 +149,9 @@ function BenchmarkConsoleReporter(runner) {

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

const resultsDir = 'perf-test-results';
Expand All @@ -156,8 +160,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 5cd750f

Please sign in to comment.