Skip to content

Commit 7a679a3

Browse files
authored
Prefix subcase recorder error stacks with the subcase name (#2086)
The deferred nature of subcases makes it hard to tell which failures came from which subcases. Prefix all error messages from subcases with their subcase name.
1 parent 17522c8 commit 7a679a3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/common/internal/test_group.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,21 @@ class RunCaseSpecific implements RunCase {
525525
// Make a recorder that will defer all calls until `allPreviousSubcasesFinalizedPromise`
526526
// resolves. Waiting on `allPreviousSubcasesFinalizedPromise` ensures that
527527
// logs from all the previous subcases have been flushed before flushing new logs.
528+
const subcasePrefix = 'subcase: ' + stringifyPublicParams(subParams);
528529
const subRec = new Proxy(rec, {
529530
get: (target, k: keyof TestCaseRecorder) => {
530531
const prop = TestCaseRecorder.prototype[k];
531532
if (typeof prop === 'function') {
532533
testHeartbeatCallback();
533534
return function (...args: Parameters<typeof prop>) {
534535
void allPreviousSubcasesFinalizedPromise.then(() => {
536+
// Prepend the subcase name to all error messages.
537+
for (const arg of args) {
538+
if (arg instanceof Error) {
539+
arg.message = subcasePrefix + '\n' + arg.message;
540+
}
541+
}
542+
535543
// eslint-disable-next-line @typescript-eslint/no-explicit-any
536544
const rv = (prop as any).apply(target, args);
537545
// Because this proxy executes functions in a deferred manner,
@@ -544,8 +552,6 @@ class RunCaseSpecific implements RunCase {
544552
},
545553
});
546554

547-
subRec.info(new Error('subcase: ' + stringifyPublicParams(subParams)));
548-
549555
const params = mergeParams(this.params, subParams);
550556
const subcaseQuery = new TestQuerySingleCase(
551557
selfQuery.suite,
@@ -573,6 +579,9 @@ class RunCaseSpecific implements RunCase {
573579
/* throwSkip */ true,
574580
getExpectedStatus(subcaseQuery)
575581
)
582+
.then(() => {
583+
subRec.info(new Error('OK'));
584+
})
576585
.catch(ex => {
577586
if (ex instanceof SkipTestCase) {
578587
// Convert SkipTestCase to info messages

0 commit comments

Comments
 (0)