I'm not entirely sure if this is a fetch-cookie issue, or a Deno issue, but I thought I'd start here!
Running a test within Deno results in an error "A fetch response body was created during the test, but not consumed during the test. Consume or close the response body ReadableStream"
Steps to reproduce:
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* server.js: "deno run -N server.js" to start server */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
import * as http from 'jsr:@std/http@^1';
Deno.serve({ port: 8080 }, async (req) => {
console.info(req.method, req.url, http.getCookies(req.headers));
if (req.method == 'POST' && req.url == 'http://localhost:8080/sign-in') {
const res = new Response(null, { status: 302 }); // POST always redirects
const form = Object.fromEntries(await req.formData());
const location = (form.username == 'hello' && form.password == 'world') ? '/secure-page' : '/sign-in'
res.headers.append('location', location);
http.setCookie(res.headers, { name: 'auth', value: 'welcome' });
return res;
}
if (req.method == 'GET' && req.url == 'http://localhost:8080/secure-page') {
const cookies = http.getCookies(req.headers);
if (cookies.auth != 'welcome') {
return new Response(null, { status: 401 });
}
const res = new Response('Hello World');
http.setCookie(res.headers, { name: 'auth', value: cookies.auth });
return res;
}
});
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* test.js: "deno test -N test.js" to run test; expects server running on localhost:8080 */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
import { assert } from 'jsr:@std/assert@^1';
import makeFetchCookie from 'npm:fetch-cookie'
const fetchCookie = makeFetchCookie(fetch);
Deno.test('Sign-in with fetch redirect:follow', async function () {
const form = { username: 'hello', password: 'world' };
const options = { method: 'POST', body: new URLSearchParams(form), credentials: 'include' }; // uses redirect:follow
const response = await fetchCookie('http://localhost:8080/sign-in', options);
assert(response.status == 200, response.status);
assert(response.url == 'http://localhost:8080/secure-page');
assert(await response.text() == 'Hello World');
});
Result:

Neither using response.text() nor response.body.cancel() resolves this issue, though I cannot see why this should be.
Let me know if I should raise a Deno issue rather than here, but it seems that it should be resolved here?
I'm not entirely sure if this is a fetch-cookie issue, or a Deno issue, but I thought I'd start here!
Running a test within Deno results in an error "A fetch response body was created during the test, but not consumed during the test. Consume or close the response body
ReadableStream"Steps to reproduce:
Result:
Neither using
response.text()norresponse.body.cancel()resolves this issue, though I cannot see why this should be.Let me know if I should raise a Deno issue rather than here, but it seems that it should be resolved here?