Integration testing with test client and HTTP only cookies

Hello, I have an API with HTTP only cookies built with Hono (Behind Next.js https://hono.dev/docs/getting-started/vercel). I tried to do some integration testing with Hono test client and vitest. I ran into a big issue that is my HTTP only cookies aren't send back to the server. It's normal since HTTP only behavior is handle by the browser and not Node or bun. So I was wondering what tooling or how could i do this integration testing. I want to run it in my CI CD. Any idea or recommendation is welcome ^^
import { config } from 'dotenv';
import { testClient } from 'hono/testing';
import { describe, expect, test } from 'vitest';

import app, { AppRoutes } from './app/api/[[...route]]/route';

describe('demo', () => {
config();
test('should work', async () => {
const client = testClient<AppRoutes>(app);
const res = await client.api.auth.login.$post(
{
json: {
password: '#Password123',
},
},
{
init: {
credentials: 'include',
},
}
);
console.log(await res.json());
const res2 = await client.api.auth.me.$get(undefined, {
init: {
credentials: 'include',
},
});
//Work !
expect(res.status).toBe(201);
// 401 No cookies has been send
expect(res2.status).toBe(200);

});
});
import { config } from 'dotenv';
import { testClient } from 'hono/testing';
import { describe, expect, test } from 'vitest';

import app, { AppRoutes } from './app/api/[[...route]]/route';

describe('demo', () => {
config();
test('should work', async () => {
const client = testClient<AppRoutes>(app);
const res = await client.api.auth.login.$post(
{
json: {
password: '#Password123',
},
},
{
init: {
credentials: 'include',
},
}
);
console.log(await res.json());
const res2 = await client.api.auth.me.$get(undefined, {
init: {
credentials: 'include',
},
});
//Work !
expect(res.status).toBe(201);
// 401 No cookies has been send
expect(res2.status).toBe(200);

});
});
And with a console log in my middleware i seed that my cookie is not being send
4 Replies
Steven-sensei
Steven-senseiOP2mo ago
I can provide the repo with the project if needed, I just need to migrate it to testcontainers for the database
Aditya Mathur
Aditya Mathur2mo ago
You can pass the cookies in the header
Steven-sensei
Steven-senseiOP2mo ago
yes but since it's and http cookies i recieve it from the login but has no way to access it with javascript Oh way maybe I said something stupid xd
Aditya Mathur
Aditya Mathur2mo ago
I think if you are getting it from the server you can check the response for the Set-Cookie header to get the cookie
Want results from more Discord servers?
Add your server