1
1
import parser from './parser'
2
2
3
3
describe ( 'parser' , ( ) => {
4
- test ( 'should pass single success' , ( ) => {
5
- const example = `
4
+ describe ( 'mocha' , ( ) => {
5
+ test ( 'should pass single success' , ( ) => {
6
+ const example = `
6
7
1..1
7
8
ok 1 - Should pass
8
9
`
9
- expect ( parser ( example ) ) . toEqual ( {
10
- ok : true ,
11
- passed : [ { message : 'Should pass' } ] ,
12
- failed : [ ] ,
13
- logs : [ ] ,
14
- summary : { 'Should pass' : true } ,
10
+ expect ( parser ( example ) ) . toEqual ( {
11
+ ok : true ,
12
+ passed : [ { message : 'Should pass' } ] ,
13
+ failed : [ ] ,
14
+ logs : [ ] ,
15
+ summary : { 'Should pass' : true } ,
16
+ } )
15
17
} )
16
- } )
17
- test ( 'should detect multiple successes' , ( ) => {
18
- const example = `
18
+ test ( 'should detect multiple successes' , ( ) => {
19
+ const example = `
19
20
1..2
20
21
ok 1 - Should pass
21
22
ok 2 - Should also pass
22
23
`
23
- const result = parser ( example )
24
- expect ( result ) . toEqual ( {
25
- ok : true ,
26
- passed : [ { message : 'Should pass' } , { message : 'Should also pass' } ] ,
27
- failed : [ ] ,
28
- logs : [ ] ,
29
- summary : {
30
- 'Should pass' : true ,
31
- 'Should also pass' : true ,
32
- } ,
24
+ const result = parser ( example )
25
+ expect ( result ) . toEqual ( {
26
+ ok : true ,
27
+ passed : [ { message : 'Should pass' } , { message : 'Should also pass' } ] ,
28
+ failed : [ ] ,
29
+ logs : [ ] ,
30
+ summary : {
31
+ 'Should pass' : true ,
32
+ 'Should also pass' : true ,
33
+ } ,
34
+ } )
33
35
} )
34
- } )
35
- test ( 'should detect failure if no tests passed' , ( ) => {
36
- const example = `
36
+ test ( 'should detect failure if no tests passed' , ( ) => {
37
+ const example = `
37
38
# Starting...
38
39
# 1 test suites found.
39
40
40
41
# FAIL __tests__/sum.test.js
41
42
42
43
not ok 1 ● sum › should add two numbers together
43
44
`
44
- expect ( parser ( example ) . ok ) . toBe ( false )
45
- } )
46
- test ( 'should detect single failure among successes' , ( ) => {
47
- const example = `
45
+ expect ( parser ( example ) . ok ) . toBe ( false )
46
+ } )
47
+ test ( 'should detect single failure among successes' , ( ) => {
48
+ const example = `
48
49
1..3
49
50
ok 1 - Should pass
50
51
not ok 2 - This one fails
51
52
ok 3 - Also passes
52
53
`
53
- expect ( parser ( example ) . ok ) . toBe ( false )
54
- } )
55
- test ( 'should return failure message' , ( ) => {
56
- const example = `
54
+ expect ( parser ( example ) . ok ) . toBe ( false )
55
+ } )
56
+ test ( 'should return failure message' , ( ) => {
57
+ const example = `
57
58
1..4
58
59
ok 1 - Should pass
59
60
not ok 2 - First to fail
60
61
ok 3 - Also passes
61
62
not ok 4 - Second to fail
62
63
`
63
- expect ( parser ( example ) . failed ) . toEqual ( [ { message : 'First to fail' } , { message : 'Second to fail' } ] )
64
- } )
64
+ expect ( parser ( example ) . failed ) . toEqual ( [ { message : 'First to fail' } , { message : 'Second to fail' } ] )
65
+ } )
65
66
66
- test ( 'should parse mocha tap example' , ( ) => {
67
- const example = `
67
+ test ( 'should parse mocha tap example' , ( ) => {
68
+ const example = `
68
69
1..3
69
70
ok 1 itemList data should not be changed
70
71
ok 2 sumItems shouldn't return NaN
@@ -74,11 +75,11 @@ ok 3 sumItems should total numbers accurately
74
75
# fail 0
75
76
# skip 0
76
77
`
77
- expect ( parser ( example ) . ok ) . toBe ( true )
78
- } )
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,104 @@ 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 : 'add no numbers' } ,
205
+ { message : 'add one number' } ,
206
+ { message : 'add three numbers' } ,
207
+ { message : 'add two numbers' } ,
208
+ ] ,
209
+ failed : [ ] ,
210
+ logs : [ ] ,
211
+ summary : {
212
+ 'add no numbers' : true ,
213
+ 'add one number' : true ,
214
+ 'add three numbers' : true ,
215
+ '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 : false ,
229
+ passed : [ ] ,
230
+ failed : [
231
+ {
232
+ message : 'add no numbers' ,
233
+ details :
234
+ 'Traceback (most recent call last):\nFail Message\nAssertionError: 42 != 0 : Should return 0 with no params' ,
235
+ } ,
236
+ ] ,
237
+ logs : [ ] ,
238
+ summary : {
239
+ '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 : false ,
255
+ passed : [ { message : 'add no numbers' } ] ,
256
+ failed : [
257
+ {
258
+ message : 'add one number' ,
259
+ details :
260
+ 'Traceback (most recent call last):\nFail Message\nAssertionError: 2 != 1 : Should add one number to 0' ,
261
+ } ,
262
+ ] ,
263
+ logs : [ ] ,
264
+ summary : {
265
+ 'add no numbers' : true ,
266
+ 'add one number' : false ,
180
267
} ,
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
- } ,
268
+ } )
187
269
} )
188
270
} )
189
271
} )
0 commit comments