@@ -5,6 +5,7 @@ var fs = require('fs');
5
5
var path = require ( 'path' ) ;
6
6
var run = require ( './helpers' ) . runMocha ;
7
7
var runJSON = require ( './helpers' ) . runMochaJSON ;
8
+ var map = require ( '../../lib/utils' ) . map ;
8
9
9
10
describe ( 'regressions' , function ( ) {
10
11
it ( 'issue-1327: should run all 3 specs exactly once' , function ( done ) {
@@ -54,17 +55,118 @@ describe('regressions', function () {
54
55
} ) ;
55
56
} ) ;
56
57
57
- describe ( 'issue-2286: after doesn\'t execute if test was skipped in beforeEach' , function ( ) {
58
- var afterWasRun = false ;
59
- describe ( 'suite with skipped test for meta test' , function ( ) {
60
- beforeEach ( function ( ) { this . skip ( ) ; } ) ;
61
- after ( function ( ) { afterWasRun = true ; } ) ;
62
- it ( 'should be pending' , function ( ) { } ) ;
63
- } ) ;
64
- after ( 'meta test' , function ( ) {
65
- afterWasRun . should . be . ok ( ) ;
58
+ describe (
59
+ "issue-2286: after doesn't execute if test was skipped in beforeEach" ,
60
+ function ( ) {
61
+ /**
62
+ * Generates tests for behavior of `this.skip()`
63
+ * @param {string } name - Name of Runnable abort via `this.skip()`
64
+ * @param {Array.<boolean> } expected - For each of the Runnable types,
65
+ * whether or not the Runnable should have been run. The order is
66
+ * "beforeAll" x 2, "beforeEach" x 2, "test" x 2, "afterEach" x 2, then
67
+ * "afterAll" x 2. There should be 10 items in this array.
68
+ */
69
+ function testPendingRunnables ( name , expected ) {
70
+ var spies = [ ] ;
71
+
72
+ function spy ( skip ) {
73
+ function wrapped ( ) {
74
+ wrapped . wasRun = true ;
75
+ if ( skip ) {
76
+ this . skip ( ) ;
77
+ }
78
+ }
79
+
80
+ wrapped . wasRun = false ;
81
+ spies . push ( wrapped ) ;
82
+ return wrapped ;
83
+ }
84
+
85
+ describe ( name , function ( ) {
86
+ describe ( 'meta' , function ( ) {
87
+ before ( spy ( name === 'beforeAll' ) ) ;
88
+ before ( spy ( name === 'beforeAll' ) ) ;
89
+ beforeEach ( spy ( name === 'beforeEach' ) ) ;
90
+ beforeEach ( spy ( name === 'beforeEach' ) ) ;
91
+ it ( 'should be pending' , spy ( name === 'test' ) ) ;
92
+ it ( 'should be pending' , spy ( name === 'test' ) ) ;
93
+ afterEach ( spy ( name === 'afterEach' ) ) ;
94
+ afterEach ( spy ( name === 'afterEach' ) ) ;
95
+ after ( spy ( name === 'afterAll' ) ) ;
96
+ after ( spy ( name === 'afterAll' ) ) ;
97
+ } ) ;
98
+
99
+ after ( name , function ( ) {
100
+ map ( spies , function ( spy ) {
101
+ return spy . wasRun ;
102
+ } )
103
+ . should
104
+ . deepEqual ( expected ) ;
105
+ } ) ;
106
+ } ) ;
107
+ }
108
+
109
+ testPendingRunnables ( 'beforeAll' , [
110
+ true , // beforeAll
111
+ true ,
112
+ false , // beforeEach
113
+ false ,
114
+ false , // test
115
+ false ,
116
+ false , // afterEach
117
+ false ,
118
+ true , // afterAll
119
+ true
120
+ ] ) ;
121
+ testPendingRunnables ( 'beforeEach' , [
122
+ true , // beforeAll
123
+ true ,
124
+ true , // beforeEach
125
+ true ,
126
+ false , // test
127
+ false ,
128
+ true , // afterEach
129
+ true ,
130
+ true , // afterAll
131
+ true
132
+ ] ) ;
133
+ testPendingRunnables ( 'test' , [
134
+ true , // beforeAll
135
+ true ,
136
+ true , // beforeEach
137
+ true ,
138
+ true , // test
139
+ true ,
140
+ true , // afterEach
141
+ true ,
142
+ true , // afterAll
143
+ true
144
+ ] ) ;
145
+ testPendingRunnables ( 'afterEach' , [
146
+ true , // beforeAll
147
+ true ,
148
+ true , // beforeEach
149
+ true ,
150
+ true , // test
151
+ false ,
152
+ true , // afterEach
153
+ true ,
154
+ true , // afterAll
155
+ true
156
+ ] ) ;
157
+ testPendingRunnables ( 'afterAll' , [
158
+ true , // beforeAll
159
+ true ,
160
+ true , // beforeEach
161
+ true ,
162
+ true , // test
163
+ true ,
164
+ true , // afterEach
165
+ true ,
166
+ true , // afterAll
167
+ true
168
+ ] ) ;
66
169
} ) ;
67
- } ) ;
68
170
69
171
it ( 'issue-2315: cannot read property currentRetry of undefined' , function ( done ) {
70
172
runJSON ( 'regression/issue-2315.js' , [ ] , function ( err , res ) {
0 commit comments