Skip to content

Commit

Permalink
Bubble up cypress step errors to test (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjduffy authored Nov 21, 2023
1 parent 04d357b commit 41be0e6
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/cypress/src/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,35 @@ function groupStepsByTest(tests: Test[], steps: StepEvent[]): Test[] {
});
});

// If a test fails in the beforeAll hook phase, Cypress will mark the first
// test as failed and the rest as unknown. For consistency, try to detect this
// first case and set it to unknown as well.
tests.forEach(t => {
// If a test fails in the beforeAll hook phase, Cypress will mark the first
// test as failed and the rest as unknown. For consistency, try to detect this
// first case and set it to unknown as well.
if (t.result === "failed" && t.events.main.length === 0) {
if (!steps.some(s => s.event === "test:start" && isTestForStep(t, s))) {
t.result = "unknown";
}
}

// Cypress doesn't always bubble up step errors to the test so if a test
// failed and it is missing an error, we find the last error and set that on
// the test
if (t.result === "failed" && t.error == null) {
const phases: (keyof Test["events"])[] = [
"afterAll",
"afterEach",
"main",
"beforeEach",
"beforeAll",
];
for (const phase of phases) {
const stepWithError = t.events[phase].reverse().find(t => t.data.error);
if (stepWithError) {
t.error = stepWithError.data.error;
break;
}
}
}
});

return tests;
Expand Down

0 comments on commit 41be0e6

Please sign in to comment.