Skip to content

Commit 141c142

Browse files
committed
internal: fixup diagnostic reporting
1 parent 3d5b96c commit 141c142

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

packages/diagnostic/server/reporters/default.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ export default class CustomDotReporter {
184184
)
185185
);
186186
}
187+
if (this.globalFailures.length) {
188+
this.write(
189+
chalk.red(
190+
`\n\n${this.globalFailures.length} Global Failures were detected.. Complete stack traces for failures will print at the end.`
191+
)
192+
);
193+
}
187194
this.write(`\n\n`);
188195

189196
this.reportPendingTests();
@@ -214,7 +221,7 @@ export default class CustomDotReporter {
214221

215222
this.clearState();
216223

217-
return this.failedTests.length ? 1 : 0;
224+
return this.globalFailures.length || this.failedTests.length ? 1 : 0;
218225
}
219226

220227
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)