Skip to content

Commit

Permalink
Test internal modifications by cacheable-request
Browse files Browse the repository at this point in the history
Fixes #1567
  • Loading branch information
szmarczak committed Apr 13, 2021
1 parent 77df9c3 commit 313ae89
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import test from 'ava';
import * as pEvent from 'p-event';
import * as getStream from 'get-stream';
import {Handler} from 'express';
import * as nock from 'nock';
import CacheableLookup from 'cacheable-lookup';
import * as delay from 'delay';
import got, {CacheError, Response} from '../source/index';
Expand Down Expand Up @@ -375,3 +376,27 @@ test('http-cache-semantics typings', t => {

t.is(instance.defaults.options.cacheOptions.shared, false);
});

test('allows internal modifications', async t => {
nock('http://example.com').get('/test').reply(401);
nock('http://example.com').get('/test').reply(200, JSON.stringify({
wat: ['123']
}));

const client = got.extend({
cache: new Map(),
hooks: {
afterResponse: [
async (response, retryWithMergedOptions) => {
if (response.statusCode === 401) {
return retryWithMergedOptions({});
}

return response;
}
]
}
});

await t.notThrowsAsync(client.get('http://example.com/test'));
});

0 comments on commit 313ae89

Please sign in to comment.