@@ -4,9 +4,20 @@ import test from 'tape'
44import split2 from 'split2'
55import listStream from 'list-stream'
66import { pipeline } from 'readable-stream'
7+ import bl from 'bl'
78
8- function gitToList ( gitCmd , callback ) {
9+ function gitToList ( t , gitCmd , callback ) {
910 const child = spawn ( 'bash' , [ '-c' , gitCmd ] )
11+ child . stderr . pipe ( bl ( ( _ , out ) => {
12+ t . strictEqual ( out . toString ( ) , '' )
13+ } ) )
14+ child . on ( 'error' , ( err ) => {
15+ t . error ( err , 'error from child' )
16+ } )
17+ child . on ( 'close' , ( code ) => {
18+ t . strictEqual ( code , 0 , 'exit code zero' )
19+ setImmediate ( t . end . bind ( t ) )
20+ } )
1021 pipeline (
1122 child . stdout ,
1223 split2 ( ) ,
@@ -30,10 +41,13 @@ test('git is runnable', (t) => {
3041} )
3142
3243test ( 'current plain commit log' , ( t ) => {
33- gitToList ( 'git log' , ( err , list ) => {
44+ gitToList ( t , 'git log' , ( err , list ) => {
3445 t . error ( err , 'no error' )
3546
36- t . ok ( list ?. length > 1 , 'got a list' )
47+ t . ok ( list ?. length > 0 , 'got a list' )
48+ if ( ! list || ! list . length ) {
49+ return
50+ }
3751
3852 t . deepEqual (
3953 list [ list . length - 9 ] ,
@@ -119,7 +133,7 @@ test('current plain commit log', (t) => {
119133 t . deepEqual (
120134 list [ list . length - 16 ] ,
121135 {
122- sha : list [ list . length - 16 ] . sha , // unknown at time of writing :)
136+ sha : list [ list . length - 16 ] ? .sha , // unknown at time of writing :)
123137 authorDate : 'Tue Jun 12 23:41:35 2018 +0200' ,
124138 author : { name : 'Anna Henningsen' , email : 'anna@addaleax.net' } ,
125139 authors : [
@@ -130,19 +144,20 @@ test('current plain commit log', (t) => {
130144 } ,
131145 'got correct co-authored-by commit'
132146 )
133-
134- t . end ( )
135147 } )
136148} )
137149
138150test ( 'current commit log with changes' , ( t ) => {
139- gitToList ( 'git log --stat' , ( err , list ) => {
151+ gitToList ( t , 'git log --stat' , ( err , list ) => {
140152 t . error ( err , 'no errors' )
141153
142154 t . ok ( list ?. length > 0 , 'got a list' )
155+ if ( ! list || ! list . length ) {
156+ return
157+ }
143158
144159 t . deepEqual (
145- list [ list . length - 4 ] . changes ,
160+ list [ list . length - 4 ] ? .changes ,
146161 {
147162 files : 1 ,
148163 insertions : 0 ,
@@ -152,7 +167,7 @@ test('current commit log with changes', (t) => {
152167 )
153168
154169 t . deepEqual (
155- list [ list . length - 3 ] . changes ,
170+ list [ list . length - 3 ] ? .changes ,
156171 {
157172 files : 1 ,
158173 insertions : 1 ,
@@ -162,7 +177,7 @@ test('current commit log with changes', (t) => {
162177 )
163178
164179 t . deepEqual (
165- list [ list . length - 2 ] . changes ,
180+ list [ list . length - 2 ] ? .changes ,
166181 {
167182 files : 1 ,
168183 insertions : 49 ,
@@ -172,15 +187,13 @@ test('current commit log with changes', (t) => {
172187 )
173188
174189 t . deepEqual (
175- list [ list . length - 1 ] . changes ,
190+ list [ list . length - 1 ] ? .changes ,
176191 {
177192 files : 1 ,
178193 insertions : 28 ,
179194 deletions : 0
180195 } ,
181196 'got correct first commit changes'
182197 )
183-
184- t . end ( )
185198 } )
186199} )
0 commit comments