@@ -4,9 +4,20 @@ import test from 'tape'
4
4
import split2 from 'split2'
5
5
import listStream from 'list-stream'
6
6
import { pipeline } from 'readable-stream'
7
+ import bl from 'bl'
7
8
8
- function gitToList ( gitCmd , callback ) {
9
+ function gitToList ( t , gitCmd , callback ) {
9
10
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
+ } )
10
21
pipeline (
11
22
child . stdout ,
12
23
split2 ( ) ,
@@ -30,10 +41,13 @@ test('git is runnable', (t) => {
30
41
} )
31
42
32
43
test ( 'current plain commit log' , ( t ) => {
33
- gitToList ( 'git log' , ( err , list ) => {
44
+ gitToList ( t , 'git log' , ( err , list ) => {
34
45
t . error ( err , 'no error' )
35
46
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
+ }
37
51
38
52
t . deepEqual (
39
53
list [ list . length - 9 ] ,
@@ -119,7 +133,7 @@ test('current plain commit log', (t) => {
119
133
t . deepEqual (
120
134
list [ list . length - 16 ] ,
121
135
{
122
- sha : list [ list . length - 16 ] . sha , // unknown at time of writing :)
136
+ sha : list [ list . length - 16 ] ? .sha , // unknown at time of writing :)
123
137
authorDate : 'Tue Jun 12 23:41:35 2018 +0200' ,
124
138
author :
{ name :
'Anna Henningsen' , email :
'[email protected] ' } ,
125
139
authors : [
@@ -130,19 +144,20 @@ test('current plain commit log', (t) => {
130
144
} ,
131
145
'got correct co-authored-by commit'
132
146
)
133
-
134
- t . end ( )
135
147
} )
136
148
} )
137
149
138
150
test ( 'current commit log with changes' , ( t ) => {
139
- gitToList ( 'git log --stat' , ( err , list ) => {
151
+ gitToList ( t , 'git log --stat' , ( err , list ) => {
140
152
t . error ( err , 'no errors' )
141
153
142
154
t . ok ( list ?. length > 0 , 'got a list' )
155
+ if ( ! list || ! list . length ) {
156
+ return
157
+ }
143
158
144
159
t . deepEqual (
145
- list [ list . length - 4 ] . changes ,
160
+ list [ list . length - 4 ] ? .changes ,
146
161
{
147
162
files : 1 ,
148
163
insertions : 0 ,
@@ -152,7 +167,7 @@ test('current commit log with changes', (t) => {
152
167
)
153
168
154
169
t . deepEqual (
155
- list [ list . length - 3 ] . changes ,
170
+ list [ list . length - 3 ] ? .changes ,
156
171
{
157
172
files : 1 ,
158
173
insertions : 1 ,
@@ -162,7 +177,7 @@ test('current commit log with changes', (t) => {
162
177
)
163
178
164
179
t . deepEqual (
165
- list [ list . length - 2 ] . changes ,
180
+ list [ list . length - 2 ] ? .changes ,
166
181
{
167
182
files : 1 ,
168
183
insertions : 49 ,
@@ -172,15 +187,13 @@ test('current commit log with changes', (t) => {
172
187
)
173
188
174
189
t . deepEqual (
175
- list [ list . length - 1 ] . changes ,
190
+ list [ list . length - 1 ] ? .changes ,
176
191
{
177
192
files : 1 ,
178
193
insertions : 28 ,
179
194
deletions : 0
180
195
} ,
181
196
'got correct first commit changes'
182
197
)
183
-
184
- t . end ( )
185
198
} )
186
199
} )
0 commit comments