Skip to content

Commit

Permalink
Follow-up commit
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Apr 15, 2020
1 parent 407d597 commit 9eb8407
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions source/core/index.ts
Expand Up @@ -717,8 +717,9 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}

// `options.cookieJar`
if (options.cookieJar) {
let {setCookie, getCookieString} = options.cookieJar;
const {cookieJar} = options;
if (cookieJar) {
let {setCookie, getCookieString} = cookieJar;

assert.function_(setCookie);
assert.function_(getCookieString);
Expand All @@ -727,9 +728,12 @@ export default class Request extends Duplex implements RequestEvents<Request> {
if (setCookie.length === 4 && getCookieString.length === 0) {
setCookie = promisify(setCookie.bind(options.cookieJar));
getCookieString = promisify(getCookieString.bind(options.cookieJar));
}

options.cookieJar = {setCookie, getCookieString};
options.cookieJar = {
setCookie: setCookie.bind(cookieJar),
getCookieString: getCookieString.bind(getCookieString)
};
}
}

// `options.searchParams`
Expand Down
5 changes: 3 additions & 2 deletions test/cookies.ts
Expand Up @@ -89,15 +89,16 @@ test('does not throw on invalid cookies when options.ignoreInvalidCookies is set
test('catches store errors', async t => {
const error = 'Some error';
const cookieJar = new toughCookie.CookieJar({
findCookies: (_, __, callback) => {
findCookies: (_, __, ___, callback) => {
callback(new Error(error), []);
},
findCookie: () => {},
getAllCookies: () => {},
putCookie: () => {},
removeCookies: () => {},
removeCookie: () => {},
updateCookie: () => {}
updateCookie: () => {},
synchronous: false
});

await t.throwsAsync(got('https://example.com', {cookieJar}), {message: error});
Expand Down

0 comments on commit 9eb8407

Please sign in to comment.