Why am i not seeing my console.log

Why am i not seeing my console.log output in tests? I'm building a cloudflare worker using Hono and using vitest for testing. I have a simple test file but the second 'console.log' isn't showing. Why not? When I remove the call to "request" it does show. (p.s. createExecutionContext/waitOnExecutionContext doesn't make a difference)
const myapp = new Hono();
myapp.get('/', () => (<p>Hello world</p>));

describe('my-test', () => {
it('should work', async () => {
console.log('BEFORE');
myapp.request('/');
console.log('AFTER');
});
});

// vitest.config.ts
{ .... singleWorker: true .... }
const myapp = new Hono();
myapp.get('/', () => (<p>Hello world</p>));

describe('my-test', () => {
it('should work', async () => {
console.log('BEFORE');
myapp.request('/');
console.log('AFTER');
});
});

// vitest.config.ts
{ .... singleWorker: true .... }
4 Replies
MrBBot
MrBBot•8mo ago
Hey! 👋 Could you double check that request() isn't throwing by wrapping it with a try/catch? Could you try awaiting myapp.request() too?
Silvain
SilvainOP•8mo ago
I simplified it a bit too much 😉 Below is corrected code. But I think it's an issue with vitest handling of console.log. When I use "vitest --run" it doesn't show either of the console.log results. When I use "vitest --watch" it doesn't show the output either, or sometimes only the first (after repeats). But when I place a "expect(1).toBe(0)" after the second console.log, both outputs are shown. Probably a vitest thingie that it only shows console.log in case of failure or something like that .. weird. (i'm used to jest)
/* myapp.tsx */
import { Hono } from 'hono';

const myapp = new Hono();
myapp.get('/', (c) => c.html(<p>Hello world</p>));

export default myapp;

/* app.test.ts */
import myapp from './myapp';

describe('my-test', () => {
it('should work', async () => {
console.log('BEFORE');
await myapp.request('/');
console.log('AFTER');
// expect(1).toBe(0)
});
});

/* vitest.config.ts */
{ .... singleWorker: true .... }

/* run vitest */
npx vitest --no-file-parallelism --disable-console-intercept --run
/* myapp.tsx */
import { Hono } from 'hono';

const myapp = new Hono();
myapp.get('/', (c) => c.html(<p>Hello world</p>));

export default myapp;

/* app.test.ts */
import myapp from './myapp';

describe('my-test', () => {
it('should work', async () => {
console.log('BEFORE');
await myapp.request('/');
console.log('AFTER');
// expect(1).toBe(0)
});
});

/* vitest.config.ts */
{ .... singleWorker: true .... }

/* run vitest */
npx vitest --no-file-parallelism --disable-console-intercept --run
MrBBot
MrBBot•8mo ago
Ah ok, does --silent=false help? You could also try --reporter=basic maybe?
Silvain
SilvainOP•8mo ago
sorry for late reply, i figured it out. Added to my vitest.config.ts: ... fileParallelism: false, reporters: ['basic'], ... That fixed it. Thank you for your help!
Want results from more Discord servers?
Add your server