@@ -4,7 +4,7 @@ class Hook {
44 constructor ( context , error ) {
55 this . suite = context . suite
66 this . test = context . test
7- this . runnable = context . ctx . test
7+ this . runnable = context ? .ctx ? .test
88 this . ctx = context . ctx
99 this . error = error
1010 }
@@ -17,6 +17,10 @@ class Hook {
1717 return this . toString ( ) + '()'
1818 }
1919
20+ retry ( n ) {
21+ // must be implemented for each hook
22+ }
23+
2024 get title ( ) {
2125 return this . ctx ?. test ?. title || this . name
2226 }
@@ -26,13 +30,29 @@ class Hook {
2630 }
2731}
2832
29- class BeforeHook extends Hook { }
33+ class BeforeHook extends Hook {
34+ retry ( n ) {
35+ this . suite . opts [ 'retryBefore' ] = n
36+ }
37+ }
3038
31- class AfterHook extends Hook { }
39+ class AfterHook extends Hook {
40+ retry ( n ) {
41+ this . suite . opts [ 'retryAfter' ] = n
42+ }
43+ }
3244
33- class BeforeSuiteHook extends Hook { }
45+ class BeforeSuiteHook extends Hook {
46+ retry ( n ) {
47+ this . suite . opts [ 'retryBeforeSuite' ] = n
48+ }
49+ }
3450
35- class AfterSuiteHook extends Hook { }
51+ class AfterSuiteHook extends Hook {
52+ retry ( n ) {
53+ this . suite . opts [ 'retryAfterSuite' ] = n
54+ }
55+ }
3656
3757function fireHook ( eventType , suite , error ) {
3858 const hook = suite . ctx ?. test ?. title ?. match ( / " ( [ ^ " ] * ) " / ) [ 1 ]
@@ -54,10 +74,22 @@ function fireHook(eventType, suite, error) {
5474 }
5575}
5676
77+ class HookConfig {
78+ constructor ( hook ) {
79+ this . hook = hook
80+ }
81+
82+ retry ( n ) {
83+ this . hook . retry ( n )
84+ return this
85+ }
86+ }
87+
5788module . exports = {
5889 BeforeHook,
5990 AfterHook,
6091 BeforeSuiteHook,
6192 AfterSuiteHook,
6293 fireHook,
94+ HookConfig,
6395}
0 commit comments