78
+ expect ( parser ( example ) . ok ) . toBe ( true )
79
+ } )
79
80
80
- test ( 'should return failure message for mocha tap example' , ( ) => {
81
- const example = `
81
+ test ( 'should return failure message for mocha tap example' , ( ) => {
82
+ const example = `
82
83
1..3
83
84
ok 1 itemList data should not be changed
84
85
not ok 2 sumItems shouldn't return NaN
@@ -88,10 +89,10 @@ ok 3 sumItems should total numbers accurately
88
89
# fail 1
89
90
# skip 0
90
91
`
91
- expect ( parser ( example ) . failed ) . toEqual ( [ { message : "sumItems shouldn't return NaN" } ] )
92
- } )
93
- test ( 'should capture single error details' , ( ) => {
94
- const example = `
92
+ expect ( parser ( example ) . failed ) . toEqual ( [ { message : "sumItems shouldn't return NaN" } ] )
93
+ } )
94
+ test ( 'should capture single error details' , ( ) => {
95
+ const example = `
95
96
not ok 1 package.json should have a valid "author" key
96
97
# AssertionError [ERR_ASSERTION]: no "author" key provided
97
98
# at Context.<anonymous> (test/packagejson.test.js:11:12)
@@ -101,14 +102,14 @@ not ok 1 package.json should have a valid "author" key
101
102
# fail 1
102
103
# skip 0
103
104
`
104
- const result = parser ( example )
105
- expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
106
- expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
105
+ const result = parser ( example )
106
+ expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
107
+ expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
107
108
at Context.<anonymous> (test/packagejson.test.js:11:12)
108
109
at processImmediate (internal/timers.js:439:21)` )
109
- } )
110
- test ( 'should capture multiple error details' , ( ) => {
111
- const example = `
110
+ } )
111
+ test ( 'should capture multiple error details' , ( ) => {
112
+ const example = `
112
113
not ok 1 package.json should have a valid "author" key
113
114
# AssertionError [ERR_ASSERTION]: no "author" key provided
114
115
# at Context.<anonymous> (test/packagejson.test.js:11:12)
@@ -120,16 +121,16 @@ not ok 2 package.json should have a valid "description" key
120
121
# fail 1
121
122
# skip 0
122
123
`
123
- const result = parser ( example )
124
- expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
125
- expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
124
+ const result = parser ( example )
125
+ expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
126
+ expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
126
127
at Context.<anonymous> (test/packagejson.test.js:11:12)
127
128
at processImmediate (internal/timers.js:439:21)` )
128
- expect ( result . failed [ 1 ] . message ) . toBe ( 'package.json should have a valid "description" key' )
129
- expect ( result . failed [ 1 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "description" key provided` )
130
- } )
131
- test ( 'should capture multiple error details between successes' , ( ) => {
132
- const example = `
129
+ expect ( result . failed [ 1 ] . message ) . toBe ( 'package.json should have a valid "description" key' )
130
+ expect ( result . failed [ 1 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "description" key provided` )
131
+ } )
132
+ test ( 'should capture multiple error details between successes' , ( ) => {
133
+ const example = `
133
134
ok 1 first passing test
134
135
not ok 2 package.json should have a valid "author" key
135
136
# AssertionError [ERR_ASSERTION]: no "author" key provided
@@ -144,16 +145,16 @@ ok 5 some passing test
144
145
# fail 1
145
146
# skip 0
146
147
`
147
- const result = parser ( example )
148
- expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
149
- expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
148
+ const result = parser ( example )
149
+ expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
150
+ expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
150
151
at Context.<anonymous> (test/packagejson.test.js:11:12)
151
152
at processImmediate (internal/timers.js:439:21)` )
152
- expect ( result . failed [ 1 ] . message ) . toBe ( 'package.json should have a valid "description" key' )
153
- expect ( result . failed [ 1 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "description" key provided` )
154
- } )
155
- test ( 'should capture logs' , ( ) => {
156
- const example = `
153
+ expect ( result . failed [ 1 ] . message ) . toBe ( 'package.json should have a valid "description" key' )
154
+ expect ( result . failed [ 1 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "description" key provided` )
155
+ } )
156
+ test ( 'should capture logs' , ( ) => {
157
+ const example = `
157
158
1..2
158
159
ok 1 package.json should have "express" installed
159
160
log 1
@@ -167,23 +168,106 @@ not ok 2 server should log "Hello World"
167
168
# fail 1
168
169
# skip 0
169
170
`
170
- expect ( parser ( example ) ) . toEqual ( {
171
- ok : false ,
172
- passed : [ { message : 'package.json should have "express" installed' } ] ,
173
- failed : [
174
- {
175
- message : 'server should log "Hello World"' ,
176
- details : `AssertionError [ERR_ASSERTION]: \"Hello World was not logged
171
+ expect ( parser ( example ) ) . toEqual ( {
172
+ ok : false ,
173
+ passed : [ { message : 'package.json should have "express" installed' } ] ,
174
+ failed : [
175
+ {
176
+ message : 'server should log "Hello World"' ,
177
+ details : `AssertionError [ERR_ASSERTION]: \"Hello World was not logged
177
178
at Context.<anonymous> (test/server.test.js:15:12)
178
179
at processImmediate (internal/timers.js:439:21)` ,
179
- logs : [ 'log 1' , 'log 2' ] ,
180
+ logs : [ 'log 1' , 'log 2' ] ,
181
+ } ,
182
+ ] ,
183
+ logs : [ 'log 1' , 'log 2' ] ,
184
+ summary : {
185
+ 'package.json should have "express" installed' : true ,
186
+ 'server should log "Hello World"' : false ,
187
+ } ,
188
+ } )
189
+ } )
190
+ } )
191
+ describe ( 'tap.py' , ( ) => {
192
+ test ( 'should pass with success messages' , ( ) => {
193
+ const example = `
194
+ # TAP results for MathTest
195
+ ok 1 test_add_no_numbers (tests.math_test.MathTest)
196
+ ok 2 test_add_one_number (tests.math_test.MathTest)
197
+ ok 3 test_add_three_numbers (tests.math_test.MathTest)
198
+ ok 4 test_add_two_numbers (tests.math_test.MathTest)
199
+ 1..4
200
+ `
201
+ expect ( parser ( example ) ) . toEqual ( {
202
+ ok : true ,
203
+ passed : [
204
+ { message : 'test_add_no_numbers' } ,
205
+ { message : 'test_add_one_number' } ,
206
+ { message : 'test_add_three_numbers' } ,
207
+ { message : 'test_add_two_numbers' } ,
208
+ ] ,
209
+ failed : [ ] ,
210
+ logs : [ ] ,
211
+ summary : {
212
+ test_add_no_numbers : true ,
213
+ test_add_one_number : true ,
214
+ test_add_three_numbers : true ,
215
+ test_add_two_numbers : true ,
216
+ } ,
217
+ } )
218
+ } )
219
+ test ( 'should handle fail messages' , ( ) => {
220
+ const example = `
221
+ # TAP results for MathTest
222
+ not ok 1 test_add_no_numbers (tests.math_test.MathTest)
223
+ # Traceback (most recent call last):
224
+ # Fail Message
225
+ # AssertionError: 42 != 0 : Should return 0 with no params
226
+ 1..1`
227
+ expect ( parser ( example ) ) . toEqual ( {
228
+ ok : true ,
229
+ passed : [ ] ,
230
+ failed : [
231
+ {
232
+ message : 'test_add_no_numbers' ,
233
+ details :
234
+ 'Traceback (most recent call last):\n Fail Message\nAssertionError: 42 != 0 : Should return 0 with no params' ,
235
+ } ,
236
+ ] ,
237
+ logs : [ ] ,
238
+ summary : {
239
+ test_add_no_numbers : false ,
240
+ } ,
241
+ } )
242
+ } )
243
+ test ( 'should handle both success and fail messages' , ( ) => {
244
+ const example = `
245
+ # TAP results for MathTest
246
+ ok 1 test_add_no_numbers (tests.math_test.MathTest)
247
+ not ok 2 test_add_one_number (tests.math_test.MathTest)
248
+ # Traceback (most recent call last):
249
+ # Fail Message
250
+ # AssertionError: 2 != 1 : Should add one number to 0
251
+ 1..2
252
+ `
253
+ expect ( parser ( example ) ) . toEqual ( {
254
+ ok : true ,
255
+ passed : [ { message : 'test_add_no_numbers' } ] ,
256
+ failed : [
257
+ {
258
+ message : 'test_add_one_number' ,
259
+ details :
260
+ 'Traceback (most recent call last):\n Fail Message\nAssertionError: 2 != 1 : Should add one number to 0' ,
261
+ } ,
262
+ ] ,
263
+ logs : [ ] ,
264
+ summary : {
265
+ test_add_no_numbers : true ,
266
+ test_add_one_number : true ,
267
+ test_add_three_numbers : true ,
268
+ test_add_two_numbers : true ,
180
269
} ,
181
- ] ,
182
- logs : [ 'log 1' , 'log 2' ] ,
183
- summary : {
184
- 'package.json should have "express" installed' : true ,
185
- 'server should log "Hello World"' : false ,
186
- } ,
270
+ } )
187
271
} )
188
272
} )
189
273
} )
0 commit comments