@@ -889,6 +889,16 @@ const create = function (specWindow, mocha, Cypress, cy) {
889
889
return _testsById [ id ]
890
890
}
891
891
892
+ function hasTestAlreadyRun ( test ) {
893
+ if ( Cypress . _RESUMED_AT_TEST ) {
894
+ if ( + test . id . slice ( 1 ) < + Cypress . _RESUMED_AT_TEST . slice ( 1 ) ) {
895
+ return true
896
+ }
897
+ }
898
+
899
+ return false
900
+ }
901
+
892
902
overrideRunnerHook ( Cypress , _runner , getTestById , getTest , setTest , getTests )
893
903
894
904
return {
@@ -962,6 +972,27 @@ const create = function (specWindow, mocha, Cypress, cy) {
962
972
break
963
973
}
964
974
975
+ // if this isnt a hook, then the name is 'test'
976
+ const hookName = runnable . type === 'hook' ? getHookName ( runnable ) : 'test'
977
+
978
+ // extract out the next(fn) which mocha uses to
979
+ // move to the next runnable - this will be our async seam
980
+ const _next = args [ 0 ]
981
+
982
+ if ( hasTestAlreadyRun ( test ) ) {
983
+ // NOTE: this is a hack to work around another cypress bug
984
+ // where the currentTest of a global after hook
985
+ // can be the wrong test after top navigation occurs
986
+ // (no open issue since it isn't user-facing for the most part)
987
+
988
+ // A failing after hook will also not show up as a failing test in open mode
989
+ // (only a visual bug - does not affect run mode)
990
+ // https://github.com/cypress-io/cypress/issues/2296
991
+ if ( ! ( hookName === 'after all' && runnable . parent . root ) ) {
992
+ return _next ( )
993
+ }
994
+ }
995
+
965
996
// closure for calculating the actual
966
997
// runtime of a runnables fn exection duration
967
998
// and also the run of the runnable:after:run:async event
@@ -986,9 +1017,6 @@ const create = function (specWindow, mocha, Cypress, cy) {
986
1017
test . wallClockStartedAt = wallClockStartedAt
987
1018
}
988
1019
989
- // if this isnt a hook, then the name is 'test'
990
- const hookName = runnable . type === 'hook' ? getHookName ( runnable ) : 'test'
991
-
992
1020
// if we haven't yet fired this event for this test
993
1021
// that means that we need to reset the previous state
994
1022
// of cy - since we now have a new 'test' and all of the
@@ -997,10 +1025,6 @@ const create = function (specWindow, mocha, Cypress, cy) {
997
1025
fire ( TEST_BEFORE_RUN_EVENT , test , Cypress )
998
1026
}
999
1027
1000
- // extract out the next(fn) which mocha uses to
1001
- // move to the next runnable - this will be our async seam
1002
- const _next = args [ 0 ]
1003
-
1004
1028
const next = function ( err ) {
1005
1029
// now set the duration of the after runnable run async event
1006
1030
afterFnDurationEnd = ( wallClockEnd = new Date ( ) )
0 commit comments