@@ -42,71 +42,79 @@ function callWithFlag(previous, flag, args) {
42
42
} while ( previous ) ;
43
43
}
44
44
45
- function createHookChain ( hook , isAfterHook ) {
45
+ function createHookChain ( { allowCallbacks , isAfterHook = false } , hook ) {
46
46
// Hook chaining rules:
47
47
// * `always` comes immediately after "after hooks"
48
48
// * `skip` must come at the end
49
49
// * no `only`
50
50
// * no repeating
51
- extendChain ( hook , 'cb' , 'callback' ) ;
52
51
extendChain ( hook , 'skip' , 'skipped' ) ;
53
- extendChain ( hook . cb , 'skip' , 'skipped' ) ;
54
52
if ( isAfterHook ) {
55
53
extendChain ( hook , 'always' ) ;
56
- extendChain ( hook . always , 'cb' , 'callback' ) ;
57
54
extendChain ( hook . always , 'skip' , 'skipped' ) ;
58
- extendChain ( hook . always . cb , 'skip' , 'skipped' ) ;
55
+ }
56
+
57
+ if ( allowCallbacks ) {
58
+ extendChain ( hook , 'cb' , 'callback' ) ;
59
+ extendChain ( hook . cb , 'skip' , 'skipped' ) ;
60
+ if ( isAfterHook ) {
61
+ extendChain ( hook . always , 'cb' , 'callback' ) ;
62
+ extendChain ( hook . always . cb , 'skip' , 'skipped' ) ;
63
+ }
59
64
}
60
65
61
66
return hook ;
62
67
}
63
68
64
- function createChain ( fn , defaults , meta ) {
69
+ function createChain ( { allowCallbacks = true , declare , defaults, meta} ) {
65
70
// Test chaining rules:
66
71
// * `serial` must come at the start
67
72
// * `only` and `skip` must come at the end
68
73
// * `failing` must come at the end, but can be followed by `only` and `skip`
69
74
// * `only` and `skip` cannot be chained together
70
75
// * no repeating
71
- const root = startChain ( 'test' , fn , { ...defaults , type : 'test' } ) ;
72
- extendChain ( root , 'cb' , 'callback' ) ;
76
+ const root = startChain ( 'test' , declare , { ...defaults , type : 'test' } ) ;
73
77
extendChain ( root , 'failing' ) ;
74
78
extendChain ( root , 'only' , 'exclusive' ) ;
75
79
extendChain ( root , 'serial' ) ;
76
80
extendChain ( root , 'skip' , 'skipped' ) ;
77
- extendChain ( root . cb , 'failing' ) ;
78
- extendChain ( root . cb , 'only' , 'exclusive' ) ;
79
- extendChain ( root . cb , 'skip' , 'skipped' ) ;
80
- extendChain ( root . cb . failing , 'only' , 'exclusive' ) ;
81
- extendChain ( root . cb . failing , 'skip' , 'skipped' ) ;
82
81
extendChain ( root . failing , 'only' , 'exclusive' ) ;
83
82
extendChain ( root . failing , 'skip' , 'skipped' ) ;
84
- extendChain ( root . serial , 'cb' , 'callback' ) ;
85
83
extendChain ( root . serial , 'failing' ) ;
86
84
extendChain ( root . serial , 'only' , 'exclusive' ) ;
87
85
extendChain ( root . serial , 'skip' , 'skipped' ) ;
88
- extendChain ( root . serial . cb , 'failing' ) ;
89
- extendChain ( root . serial . cb , 'only' , 'exclusive' ) ;
90
- extendChain ( root . serial . cb , 'skip' , 'skipped' ) ;
91
- extendChain ( root . serial . cb . failing , 'only' , 'exclusive' ) ;
92
- extendChain ( root . serial . cb . failing , 'skip' , 'skipped' ) ;
93
86
extendChain ( root . serial . failing , 'only' , 'exclusive' ) ;
94
87
extendChain ( root . serial . failing , 'skip' , 'skipped' ) ;
95
88
96
- root . after = createHookChain ( startChain ( 'test.after' , fn , { ...defaults , type : 'after' } ) , true ) ;
97
- root . afterEach = createHookChain ( startChain ( 'test.afterEach' , fn , { ...defaults , type : 'afterEach' } ) , true ) ;
98
- root . before = createHookChain ( startChain ( 'test.before' , fn , { ...defaults , type : 'before' } ) , false ) ;
99
- root . beforeEach = createHookChain ( startChain ( 'test.beforeEach' , fn , { ...defaults , type : 'beforeEach' } ) , false ) ;
89
+ if ( allowCallbacks ) {
90
+ extendChain ( root , 'cb' , 'callback' ) ;
91
+ extendChain ( root . cb , 'failing' ) ;
92
+ extendChain ( root . cb , 'only' , 'exclusive' ) ;
93
+ extendChain ( root . cb , 'skip' , 'skipped' ) ;
94
+ extendChain ( root . cb . failing , 'only' , 'exclusive' ) ;
95
+ extendChain ( root . cb . failing , 'skip' , 'skipped' ) ;
96
+ extendChain ( root . serial , 'cb' , 'callback' ) ;
97
+ extendChain ( root . serial . cb , 'failing' ) ;
98
+ extendChain ( root . serial . cb , 'only' , 'exclusive' ) ;
99
+ extendChain ( root . serial . cb , 'skip' , 'skipped' ) ;
100
+ extendChain ( root . serial . cb . failing , 'only' , 'exclusive' ) ;
101
+ extendChain ( root . serial . cb . failing , 'skip' , 'skipped' ) ;
102
+ }
103
+
104
+ root . after = createHookChain ( { allowCallbacks, isAfterHook : true } , startChain ( 'test.after' , declare , { ...defaults , type : 'after' } ) ) ;
105
+ root . afterEach = createHookChain ( { allowCallbacks, isAfterHook : true } , startChain ( 'test.afterEach' , declare , { ...defaults , type : 'afterEach' } ) ) ;
106
+ root . before = createHookChain ( { allowCallbacks} , startChain ( 'test.before' , declare , { ...defaults , type : 'before' } ) ) ;
107
+ root . beforeEach = createHookChain ( { allowCallbacks} , startChain ( 'test.beforeEach' , declare , { ...defaults , type : 'beforeEach' } ) ) ;
100
108
101
- root . serial . after = createHookChain ( startChain ( 'test.after' , fn , { ...defaults , serial : true , type : 'after' } ) , true ) ;
102
- root . serial . afterEach = createHookChain ( startChain ( 'test.afterEach' , fn , { ...defaults , serial : true , type : 'afterEach' } ) , true ) ;
103
- root . serial . before = createHookChain ( startChain ( 'test.before' , fn , { ...defaults , serial : true , type : 'before' } ) , false ) ;
104
- root . serial . beforeEach = createHookChain ( startChain ( 'test.beforeEach' , fn , { ...defaults , serial : true , type : 'beforeEach' } ) , false ) ;
109
+ root . serial . after = createHookChain ( { allowCallbacks , isAfterHook : true } , startChain ( 'test.after' , declare , { ...defaults , serial : true , type : 'after' } ) ) ;
110
+ root . serial . afterEach = createHookChain ( { allowCallbacks , isAfterHook : true } , startChain ( 'test.afterEach' , declare , { ...defaults , serial : true , type : 'afterEach' } ) ) ;
111
+ root . serial . before = createHookChain ( { allowCallbacks } , startChain ( 'test.before' , declare , { ...defaults , serial : true , type : 'before' } ) ) ;
112
+ root . serial . beforeEach = createHookChain ( { allowCallbacks } , startChain ( 'test.beforeEach' , declare , { ...defaults , serial : true , type : 'beforeEach' } ) ) ;
105
113
106
114
// "todo" tests cannot be chained. Allow todo tests to be flagged as needing
107
115
// to be serial.
108
- root . todo = startChain ( 'test.todo' , fn , { ...defaults , type : 'test' , todo : true } ) ;
109
- root . serial . todo = startChain ( 'test.serial.todo' , fn , { ...defaults , serial : true , type : 'test' , todo : true } ) ;
116
+ root . todo = startChain ( 'test.todo' , declare , { ...defaults , type : 'test' , todo : true } ) ;
117
+ root . serial . todo = startChain ( 'test.serial.todo' , declare , { ...defaults , serial : true , type : 'test' , todo : true } ) ;
110
118
111
119
root . meta = meta ;
112
120
0 commit comments