Skip to content

Commit

Permalink
fix(cdnjs): handle empty 200 ok response
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Apr 23, 2020
1 parent f61c416 commit e79319d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/datasource/cdnjs/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ describe('datasource/cdnjs', () => {
got.mockRejectedValueOnce({ statusCode: 404 });
expect(await getReleases({ lookupName: 'foo/bar' })).toBeNull();
});
it('returns null for empty 200 OK', async () => {
got.mockResolvedValueOnce({ body: {} });
expect(
await getReleases({ lookupName: 'doesnotexist/doesnotexist' })
).toBeNull();
});
it('throws for 401', async () => {
got.mockRejectedValueOnce({ statusCode: 401 });
await expect(getReleases({ lookupName: 'foo/bar' })).rejects.toThrowError(
Expand Down
3 changes: 3 additions & 0 deletions lib/datasource/cdnjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export async function getReleases({
lookup: library,
cb: downloadLibrary,
});
if (!assets) {
return null;
}
const assetName = lookupName.replace(`${library}/`, '');
const releases = assets
.filter(({ files }) => files.includes(assetName))
Expand Down

0 comments on commit e79319d

Please sign in to comment.