File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,14 @@ function request(url, options) {
61
61
const match = json . value . match ( / ^ ( \d + ) % $ / ) ;
62
62
63
63
return match ? Number ( match [ 1 ] ) / 100 : null ;
64
+ } )
65
+ . catch ( ( err ) => {
66
+ // Swallow ParseErrors (i.e. invalid json payloads, but valid responses) and return null
67
+ if ( err instanceof got . ParseError ) {
68
+ return null ;
69
+ }
70
+
71
+ throw err ;
64
72
} ) ;
65
73
}
66
74
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ afterEach(() => {
8
8
nock . cleanAll ( ) ;
9
9
} ) ;
10
10
11
- it ( 'should return null if repository is not supported or if the URL is malformed' , async ( ) => {
11
+ it ( 'should return null if repository is not supported or if the URL is malformed or response is not json ' , async ( ) => {
12
12
nock . disableNetConnect ( ) ;
13
13
14
14
let promise = fetchCoverage ( 'git@foo.com:user/project.git' ) ;
@@ -22,6 +22,16 @@ it('should return null if repository is not supported or if the URL is malformed
22
22
23
23
expect ( promise instanceof Promise ) . toBe ( true ) ;
24
24
expect ( coverage ) . toBe ( null ) ;
25
+
26
+ nock ( 'https://img.shields.io' )
27
+ . get ( '/codecov/c/github/user/project.json' )
28
+ . reply ( 200 , '<this is not json>' ) ;
29
+
30
+ promise = fetchCoverage ( 'git@github.com:user/project.git' , { services : [ 'codecov' ] } ) ;
31
+ coverage = await promise ;
32
+
33
+ expect ( promise instanceof Promise ) . toBe ( true ) ;
34
+ expect ( coverage ) . toBe ( null ) ;
25
35
} ) ;
26
36
27
37
it ( 'should try appropriate services for GitHub repositories' , async ( ) => {
You can’t perform that action at this time.
0 commit comments