Skip to content

Commit

Permalink
Prefix subcase recorder error stacks with the subcase name (#2086)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
austinEng authored Dec 16, 2022
1 parent 17522c8 commit 7a679a3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/common/internal/test_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,21 @@ class RunCaseSpecific implements RunCase {
// Make a recorder that will defer all calls until `allPreviousSubcasesFinalizedPromise`
// resolves. Waiting on `allPreviousSubcasesFinalizedPromise` ensures that
// logs from all the previous subcases have been flushed before flushing new logs.
const subcasePrefix = 'subcase: ' + stringifyPublicParams(subParams);
const subRec = new Proxy(rec, {
get: (target, k: keyof TestCaseRecorder) => {
const prop = TestCaseRecorder.prototype[k];
if (typeof prop === 'function') {
testHeartbeatCallback();
return function (...args: Parameters<typeof prop>) {
void allPreviousSubcasesFinalizedPromise.then(() => {
// Prepend the subcase name to all error messages.
for (const arg of args) {
if (arg instanceof Error) {
arg.message = subcasePrefix + '\n' + arg.message;
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const rv = (prop as any).apply(target, args);
// Because this proxy executes functions in a deferred manner,
Expand All @@ -544,8 +552,6 @@ class RunCaseSpecific implements RunCase {
},
});

subRec.info(new Error('subcase: ' + stringifyPublicParams(subParams)));

const params = mergeParams(this.params, subParams);
const subcaseQuery = new TestQuerySingleCase(
selfQuery.suite,
Expand Down Expand Up @@ -573,6 +579,9 @@ class RunCaseSpecific implements RunCase {
/* throwSkip */ true,
getExpectedStatus(subcaseQuery)
)
.then(() => {
subRec.info(new Error('OK'));
})
.catch(ex => {
if (ex instanceof SkipTestCase) {
// Convert SkipTestCase to info messages
Expand Down

0 comments on commit 7a679a3

Please sign in to comment.