Skip to content

Commit 5cd750f

Browse files
authored
perf-tests: fix JSON reporter (#8876)
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>
1 parent 6d9d5e1 commit 5cd750f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bin/test-browser.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class ArrayMap extends Map {
7272

7373
class RemoteRunner {
7474
constructor(browser) {
75+
this.failed = false;
7576
this.browser = browser;
7677
this.handlers = new ArrayMap();
7778
this.onceHandlers = new ArrayMap();
@@ -120,20 +121,21 @@ class RemoteRunner {
120121
}
121122
}
122123

123-
async handleEnd(failed) {
124+
async handleEnd() {
124125
closeRequested = true;
125126
await this.browser.close();
126-
process.exit(!process.env.PERF && failed ? 1 : 0);
127+
process.exit(this.failed ? 1 : 0);
127128
}
128129

129130
handleFailed() {
131+
this.failed = true;
130132
if (bail) {
131133
try {
132134
this.triggerHandlers('end');
133135
} catch (e) {
134136
console.log('An error occurred while bailing:', e);
135137
} finally {
136-
this.handleEnd(true);
138+
this.handleEnd();
137139
}
138140
}
139141
}
@@ -147,7 +149,9 @@ function BenchmarkConsoleReporter(runner) {
147149

148150
function BenchmarkJsonReporter(runner) {
149151
runner.on('end', results => {
150-
if (runner.completed) {
152+
if (runner.failed) {
153+
console.log('Runner failed; JSON will not be writted.');
154+
} else {
151155
const { mkdirSync, writeFileSync } = require('fs');
152156

153157
const resultsDir = 'perf-test-results';
@@ -156,8 +160,6 @@ function BenchmarkJsonReporter(runner) {
156160
const jsonPath = `${resultsDir}/${new Date().toISOString()}.json`;
157161
writeFileSync(jsonPath, JSON.stringify(results, null, 2));
158162
console.log('Wrote JSON results to:', jsonPath);
159-
} else {
160-
console.log('Runner failed; JSON will not be writted.');
161163
}
162164
});
163165
}

0 commit comments

Comments
 (0)