11import parser from './parser'
22
33describe ( 'parser' , ( ) => {
4- test ( 'shoulddetect success' , ( ) => {
4+ test ( 'shouldpass single success' , ( ) => {
55const example = `
6- 1..2
6+ 1..1
77ok 1 - Should pass
8- ok 2 - Should also pass
98`
10- expect ( parser ( example ) ) . toEqual ( { ok :true } )
9+ expect ( parser ( example ) ) . toEqual ( { ok :true , passed : [ { message : 'Should pass' } ] , failed : [ ] } )
1110} )
12- test ( 'should detectfailure ' , ( ) => {
11+ test ( 'should detectmultiple successes ' , ( ) => {
1312const example = `
14- 1..3
13+ 1..2
1514ok 1 - Should pass
16- not ok 2 - This one fails
17- ok 3 - Also passes
15+ ok 2 - Should also pass
1816`
19- expect ( parser ( example ) . ok ) . toBe ( false )
17+ const result = parser ( example )
18+ expect ( result ) . toEqual ( {
19+ ok :true ,
20+ passed :[ { message :'Should pass' } , { message :'Should also pass' } ] ,
21+ failed :[ ] ,
22+ } )
2023} )
2124test ( 'should detect failure if no tests passed' , ( ) => {
2225const example = `
@@ -26,6 +29,15 @@ ok 3 - Also passes
2629# FAIL __tests__/sum.test.js
2730
2831not ok 1 ● sum › should add two numbers together
32+ `
33+ expect ( parser ( example ) . ok ) . toBe ( false )
34+ } )
35+ test ( 'should detect single failure among successes' , ( ) => {
36+ const example = `
37+ 1..3
38+ ok 1 - Should pass
39+ not ok 2 - This one fails
40+ ok 3 - Also passes
2941`
3042expect ( parser ( example ) . ok ) . toBe ( false )
3143} )
@@ -37,7 +49,7 @@ not ok 2 - First to fail
3749ok 3 - Also passes
3850not ok 4 - Second to fail
3951`
40- expect ( parser ( example ) . message ) . toBe ( 'First to fail' )
52+ expect ( parser ( example ) . failed ) . toEqual ( [ { message : 'First to fail' } , { message : 'Second to fail' } ] )
4153} )
4254
4355test ( 'should parse mocha tap example' , ( ) => {
@@ -65,6 +77,68 @@ ok 3 sumItems should total numbers accurately
6577# fail 1
6678# skip 0
6779`
68- expect ( parser ( example ) . message ) . toBe ( "sumItems shouldn't return NaN" )
80+ expect ( parser ( example ) . failed ) . toEqual ( [ { message :"sumItems shouldn't return NaN" } ] )
81+ } )
82+ test ( 'should capture single error details' , ( ) => {
83+ const example = `
84+ not ok 1 package.json should have a valid "author" key
85+ # AssertionError [ERR_ASSERTION]: no "author" key provided
86+ # at Context.<anonymous> (test/packagejson.test.js:11:12)
87+ # at processImmediate (internal/timers.js:439:21)
88+ # tests 1
89+ # pass 0
90+ # fail 1
91+ # skip 0
92+ `
93+ const result = parser ( example )
94+ expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
95+ expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
96+ at Context.<anonymous> (test/packagejson.test.js:11:12)
97+ at processImmediate (internal/timers.js:439:21)` )
98+ } )
99+ test ( 'should capture multiple error details' , ( ) => {
100+ const example = `
101+ not ok 1 package.json should have a valid "author" key
102+ # AssertionError [ERR_ASSERTION]: no "author" key provided
103+ # at Context.<anonymous> (test/packagejson.test.js:11:12)
104+ # at processImmediate (internal/timers.js:439:21)
105+ not ok 2 package.json should have a valid "description" key
106+ # AssertionError [ERR_ASSERTION]: no "description" key provided
107+ # tests 1
108+ # pass 0
109+ # fail 1
110+ # skip 0
111+ `
112+ const result = parser ( example )
113+ expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
114+ expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
115+ at Context.<anonymous> (test/packagejson.test.js:11:12)
116+ at processImmediate (internal/timers.js:439:21)` )
117+ expect ( result . failed [ 1 ] . message ) . toBe ( 'package.json should have a valid "description" key' )
118+ expect ( result . failed [ 1 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "description" key provided` )
119+ } )
120+ test ( 'should capture multiple error details between successes' , ( ) => {
121+ const example = `
122+ ok 1 first passing test
123+ not ok 2 package.json should have a valid "author" key
124+ # AssertionError [ERR_ASSERTION]: no "author" key provided
125+ # at Context.<anonymous> (test/packagejson.test.js:11:12)
126+ # at processImmediate (internal/timers.js:439:21)
127+ ok 3 some passing test
128+ not ok 4 package.json should have a valid "description" key
129+ # AssertionError [ERR_ASSERTION]: no "description" key provided
130+ ok 5 some passing test
131+ # tests 1
132+ # pass 0
133+ # fail 1
134+ # skip 0
135+ `
136+ const result = parser ( example )
137+ expect ( result . failed [ 0 ] . message ) . toBe ( 'package.json should have a valid "author" key' )
138+ expect ( result . failed [ 0 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "author" key provided
139+ at Context.<anonymous> (test/packagejson.test.js:11:12)
140+ at processImmediate (internal/timers.js:439:21)` )
141+ expect ( result . failed [ 1 ] . message ) . toBe ( 'package.json should have a valid "description" key' )
142+ expect ( result . failed [ 1 ] . details ) . toBe ( `AssertionError [ERR_ASSERTION]: no "description" key provided` )
69143} )
70144} )