Skip to content

Commit

Permalink
fix: make sure hook failures print outer status + attempts when the e…
Browse files Browse the repository at this point in the history
…rror is the hook itself.
  • Loading branch information
AtofStryker committed Sep 25, 2023
1 parent 3ec51b3 commit 63b6be7
Show file tree
Hide file tree
Showing 7 changed files with 824 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40285,6 +40285,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-and-pass-on-threshold',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down Expand Up @@ -40612,6 +40618,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down Expand Up @@ -40940,6 +40952,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6327,6 +6327,11 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-and-pass-on-threshold',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down Expand Up @@ -358,6 +364,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down Expand Up @@ -627,6 +639,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down Expand Up @@ -2167,6 +2185,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 6,
strategy: 'detect-flake-and-pass-on-threshold',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before each" hook for "test 1"',
hookName: 'before each',
Expand Down Expand Up @@ -4742,6 +4766,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 10,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before each" hook for "test 1"',
hookName: 'before each',
Expand Down Expand Up @@ -7317,6 +7347,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 10,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before each" hook for "test 1"',
hookName: 'before each',
Expand Down Expand Up @@ -7863,6 +7899,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-and-pass-on-threshold',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r4',
title: '"after all" hook for "test 2"',
hookName: 'after all',
Expand Down Expand Up @@ -8404,6 +8446,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r4',
title: '"after all" hook for "test 2"',
hookName: 'after all',
Expand Down Expand Up @@ -8945,6 +8993,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r4',
title: '"after all" hook for "test 2"',
hookName: 'after all',
Expand Down Expand Up @@ -10780,6 +10834,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 6,
strategy: 'detect-flake-and-pass-on-threshold',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"after each" hook for "test 1"',
hookName: 'after each',
Expand Down Expand Up @@ -13807,6 +13867,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 10,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"after each" hook for "test 1"',
hookName: 'after each',
Expand Down Expand Up @@ -16530,6 +16596,12 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 10,
strategy: 'detect-flake-but-always-fail',
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"after each" hook for "test 1"',
hookName: 'after each',
Expand Down
52 changes: 24 additions & 28 deletions packages/app/cypress/e2e/runner/runner.mochaEvents.snapshots.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
export const snapshots = {
'src/cypress/runner tests finish with correct state hook failures fail in [before] #1':
[
[
'mocha',
'start',
{
start: 'match.date',
},
],
['mocha', 'start', { start: 'match.date' }],
[
'mocha',
'suite',
Expand Down Expand Up @@ -95,6 +89,11 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before all" hook for "test 1"',
hookName: 'before all',
Expand Down Expand Up @@ -272,13 +271,7 @@ export const snapshots = {
_slow: 10000,
},
],
[
'mocha',
'end',
{
end: 'match.date',
},
],
['mocha', 'end', { end: 'match.date' }],
],

'src/cypress/runner tests finish with correct state hook failures fail in [beforeEach] #1':
Expand Down Expand Up @@ -388,6 +381,11 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"before each" hook for "test 1"',
hookName: 'before each',
Expand Down Expand Up @@ -609,13 +607,7 @@ export const snapshots = {

'src/cypress/runner tests finish with correct state hook failures fail in [after] #1':
[
[
'mocha',
'start',
{
start: 'match.date',
},
],
['mocha', 'start', { start: 'match.date' }],
[
'mocha',
'suite',
Expand Down Expand Up @@ -940,6 +932,11 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r4',
title: '"after all" hook for "test 2"',
hookName: 'after all',
Expand Down Expand Up @@ -1144,13 +1141,7 @@ export const snapshots = {
_slow: 10000,
},
],
[
'mocha',
'end',
{
end: 'match.date',
},
],
['mocha', 'end', { end: 'match.date' }],
],

'src/cypress/runner tests finish with correct state hook failures fail in [afterEach] #1':
Expand Down Expand Up @@ -1260,6 +1251,11 @@ export const snapshots = {
'mocha',
'fail',
{
_cypressTestStatusInfo: {
attempts: 1,
outerStatus: 'failed',
shouldAttemptsContinue: false,
},
id: 'r3',
title: '"after each" hook for "test 1"',
hookName: 'after each',
Expand Down
14 changes: 14 additions & 0 deletions packages/driver/src/cypress/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,20 @@ const _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, se
} else {
err = $errUtils.appendErrMsg(err, errMessage)
}

// If the test never failed and only the hooks did,
// we need to attach the metadata of the test to the hook to report the failure correctly to the server reporter.
// We calculate it fresh here since it may not be available on the test, which is the case with a beforeEach hook.
// as well as maybe incorrect (test passed on first attempt, but after hooks failed)
const testStatus = test.calculateTestStatus()

runnable._cypressTestStatusInfo = {
attempts: testStatus.attempts,
strategy: testStatus.strategy,
// regardless of the test state, we should ultimately fail the test here.
outerStatus: runnable.state,
shouldAttemptsContinue: false,
}
}

// always set runnable err so we can tap into
Expand Down
Loading

0 comments on commit 63b6be7

Please sign in to comment.