Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: fixup diagnostic reporting #9704

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/diagnostic/server/bun/socket-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ export function buildHandler(config, state) {
await config.cleanup();
debug(`Configured cleanup hook completed`);
}
debug(`\n\nExiting with code ${exitCode}`);
// 1. We expect all cleanup to have happened after
// config.cleanup(), so exiting here should be safe.
// 2. We also want to forcibly exit with a success code in this
// case.
// eslint-disable-next-line n/no-process-exit
process.exit(exitCode);
}
} else {
console.log(`Waiting for ${state.expected - state.completed} more browsers to finish`);
}

break;
Expand Down
11 changes: 10 additions & 1 deletion packages/diagnostic/server/reporters/default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from 'chalk';
import fs from 'fs';
import path from 'path';
import { exit } from 'process';

const SLOW_TEST_COUNT = 50;
const DEFAULT_TIMEOUT = 8_000;
Expand Down Expand Up @@ -184,6 +185,13 @@ export default class CustomDotReporter {
)
);
}
if (this.globalFailures.length) {
this.write(
chalk.red(
`\n\n${this.globalFailures.length} Global Failures were detected.. Complete stack traces for failures will print at the end.`
)
);
}
this.write(`\n\n`);

this.reportPendingTests();
Expand Down Expand Up @@ -212,9 +220,10 @@ export default class CustomDotReporter {
)} ms\n${HEADER_STR}\n\n`
);

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

return this.failedTests.length ? 1 : 0;
return exitCode;
}

addLauncher(data) {
Expand Down
31 changes: 29 additions & 2 deletions packages/diagnostic/src/internals/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,20 @@ export async function runTest<TC extends TestContext>(
}

for (const hook of beforeChain) {
await hook.call(testContext, Assert);
try {
await hook.call(testContext, Assert);
} catch (err) {
Assert.pushResult({
message: `Unexpected Test Failure in beforeEach: ${(err as Error).message}`,
stack: (err as Error).stack!,
passed: false,
actual: false,
expected: true,
});
if (!Config.params.tryCatch.value) {
throw err;
}
}
}

try {
Expand All @@ -91,7 +104,21 @@ export async function runTest<TC extends TestContext>(
}
} finally {
for (const hook of afterChain) {
await hook.call(testContext, Assert);
try {
await hook.call(testContext, Assert);
} catch (e) {
Assert.pushResult({
message: `Unexpected Test Failure in afterEach: ${(e as Error).message}`,
stack: (e as Error).stack!,
passed: false,
actual: false,
expected: true,
});
if (!Config.params.tryCatch.value) {
// eslint-disable-next-line no-unsafe-finally
throw e;
}
}
}
Assert._finalize();

Expand Down
Loading