All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 25m33s
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// src/services/logger.server.test.ts
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
|
|
// Mock pino before importing the logger
|
|
const pinoMock = vi.fn(() => ({
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
debug: vi.fn(),
|
|
}));
|
|
vi.mock('pino', () => ({ default: pinoMock }));
|
|
|
|
describe('Server Logger', () => {
|
|
beforeEach(() => {
|
|
// Reset modules to ensure process.env changes are applied to new module instances
|
|
vi.resetModules();
|
|
vi.clearAllMocks();
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
it('should initialize pino with the correct level for production', async () => {
|
|
vi.stubEnv('NODE_ENV', 'production');
|
|
await import('./logger.server');
|
|
expect(pinoMock).toHaveBeenCalledWith(expect.objectContaining({ level: 'info' }));
|
|
});
|
|
|
|
it('should initialize pino with pretty-print transport for development', async () => {
|
|
vi.stubEnv('NODE_ENV', 'development');
|
|
await import('./logger.server');
|
|
expect(pinoMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({ transport: expect.any(Object) }),
|
|
);
|
|
});
|
|
});
|