@@ -26,7 +26,7 @@ t.test('pre-commit', function (t) {
2626 } )
2727
2828 t . test ( '#parse' , function ( t ) {
29- t . plan ( 8 )
29+ t . plan ( 9 )
3030
3131 let hook
3232
@@ -143,7 +143,7 @@ t.test('pre-commit', function (t) {
143143 t . strictSame ( typeof hook . config . run , 'undefined' )
144144 } )
145145
146- t . test ( 'overrides the `pre-commit` config property in package.json with the config inside pre-commit.json if it exists' , function ( t ) {
146+ t . test ( 'overrides the `pre-commit` config property in package.json with the config inside `. pre-commit.json` if it exists' , function ( t ) {
147147 t . plan ( 1 )
148148
149149 const Hook = proxyquire ( '.' , {
@@ -163,6 +163,40 @@ t.test('pre-commit', function (t) {
163163 // ----
164164 t . same ( hook . config . run , [ 'lint' , 'bench' ] )
165165 } )
166+
167+ t . test ( 'should properly handle errors while trying to read and parse the contents of `.pre-commit.json`' , function ( t ) {
168+ t . plan ( 4 )
169+
170+ let Hook = proxyquire ( '.' , {
171+ fs : {
172+ existsSync ( ) {
173+ return true
174+ } ,
175+ readFileSync ( ) {
176+ throw new Error ( )
177+ }
178+ }
179+ } )
180+
181+ hook = new Hook ( exit )
182+
183+ Hook = proxyquire ( '.' , {
184+ fs : {
185+ existsSync ( ) { return true } ,
186+ readFileSync ( ) {
187+ return Buffer . from ( '{ "bad": [json }' )
188+ }
189+ }
190+ } )
191+
192+ hook = new Hook ( exit )
193+
194+ // *****************
195+ function exit ( code , lines ) {
196+ t . not ( lines . length , 0 )
197+ t . equal ( code , 1 )
198+ }
199+ } )
166200 } )
167201
168202 t . test ( '#log' , function ( t ) {
0 commit comments