Skip to content

Commit

Permalink
fix: return response data for cache hits (#62)
Browse files Browse the repository at this point in the history
Return only the response data on cache hits for consistency with
non-cache hits.
  • Loading branch information
richardlau authored Aug 24, 2021
1 parent 611aeb0 commit 4b8f540
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fetch = async (url) => {

const fetchGithub = async (target, token, override = false) => {
// check if we already have the response in cache
if (cache.has(target)) return cache.get(target);
if (cache.has(target)) return cache.get(target).data;

const github = 'https://api.github.com';
const url = override ? target : `${github}${target}`;
Expand Down
5 changes: 3 additions & 2 deletions test/lib/fetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ it('should use the cache on requests with the same target', async () => {
};
});

await network.fetchGithub('https://sample.com/test/test');
await network.fetchGithub('https://sample.com/test/test');
const content1 = await network.fetchGithub('https://sample.com/test/test');
const content2 = await network.fetchGithub('https://sample.com/test/test');

expect(axios.get).toHaveBeenCalledTimes(1);
expect(content2).toBe(content1);
});

0 comments on commit 4b8f540

Please sign in to comment.