Skip to content

Commit ddaa34c

Browse files
authored
internal: fixup diagnostic reporting (#9704)
* internal: fixup diagnostic reporting * fix exit code
1 parent 3d5b96c commit ddaa34c

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/diagnostic/server/bun/socket-handler.js

+3
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ export function buildHandler(config, state) {
6363
await config.cleanup();
6464
debug(`Configured cleanup hook completed`);
6565
}
66+
debug(`\n\nExiting with code ${exitCode}`);
6667
// 1. We expect all cleanup to have happened after
6768
// config.cleanup(), so exiting here should be safe.
6869
// 2. We also want to forcibly exit with a success code in this
6970
// case.
7071
// eslint-disable-next-line n/no-process-exit
7172
process.exit(exitCode);
7273
}
74+
} else {
75+
console.log(`Waiting for ${state.expected - state.completed} more browsers to finish`);
7376
}
7477

7578
break;

packages/diagnostic/server/reporters/default.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import chalk from 'chalk';
22
import fs from 'fs';
33
import path from 'path';
4+
import { exit } from 'process';
45

56
const SLOW_TEST_COUNT = 50;
67
const DEFAULT_TIMEOUT = 8_000;
@@ -184,6 +185,13 @@ export default class CustomDotReporter {
184185
)
185186
);
186187
}
188+
if (this.globalFailures.length) {
189+
this.write(
190+
chalk.red(
191+
`\n\n${this.globalFailures.length} Global Failures were detected.. Complete stack traces for failures will print at the end.`
192+
)
193+
);
194+
}
187195
this.write(`\n\n`);
188196

189197
this.reportPendingTests();
@@ -212,9 +220,10 @@ export default class CustomDotReporter {
212220
)} ms\n${HEADER_STR}\n\n`
213221
);
214222

223+
const exitCode = this.globalFailures.length || this.failedTests.length ? 1 : 0;
215224
this.clearState();
216225

217-
return this.failedTests.length ? 1 : 0;
226+
return exitCode;
218227
}
219228

220229
addLauncher(data) {

packages/diagnostic/src/internals/run.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,20 @@ export async function runTest<TC extends TestContext>(
6767
}
6868

6969
for (const hook of beforeChain) {
70-
await hook.call(testContext, Assert);
70+
try {
71+
await hook.call(testContext, Assert);
72+
} catch (err) {
73+
Assert.pushResult({
74+
message: `Unexpected Test Failure in beforeEach: ${(err as Error).message}`,
75+
stack: (err as Error).stack!,
76+
passed: false,
77+
actual: false,
78+
expected: true,
79+
});
80+
if (!Config.params.tryCatch.value) {
81+
throw err;
82+
}
83+
}
7184
}
7285

7386
try {
@@ -91,7 +104,21 @@ export async function runTest<TC extends TestContext>(
91104
}
92105
} finally {
93106
for (const hook of afterChain) {
94-
await hook.call(testContext, Assert);
107+
try {
108+
await hook.call(testContext, Assert);
109+
} catch (e) {
110+
Assert.pushResult({
111+
message: `Unexpected Test Failure in afterEach: ${(e as Error).message}`,
112+
stack: (e as Error).stack!,
113+
passed: false,
114+
actual: false,
115+
expected: true,
116+
});
117+
if (!Config.params.tryCatch.value) {
118+
// eslint-disable-next-line no-unsafe-finally
119+
throw e;
120+
}
121+
}
95122
}
96123
Assert._finalize();
97124

0 commit comments

Comments
 (0)