Initial commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
async function loadPlugin() {
|
||||
vi.resetModules()
|
||||
vi.stubGlobal('defineNuxtPlugin', (setup: unknown) => setup)
|
||||
|
||||
return (await import('../app/plugins/logger')).default
|
||||
}
|
||||
|
||||
describe('logger plugin', () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('logs messages with the expected prefix and payload', async () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date('2026-03-29T12:00:00.000Z'))
|
||||
|
||||
const infoSpy = vi.spyOn(console, 'info').mockImplementation(() => {})
|
||||
|
||||
const plugin = await loadPlugin()
|
||||
const { provide } = plugin()
|
||||
|
||||
provide.logger.info('Action completed', { section: 'home' })
|
||||
|
||||
expect(infoSpy).toHaveBeenCalledWith(
|
||||
'[template:info] 2026-03-29T12:00:00.000Z Action completed',
|
||||
{ section: 'home' }
|
||||
)
|
||||
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('logs messages without payload as a single console argument', async () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date('2026-03-29T12:00:00.000Z'))
|
||||
|
||||
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
|
||||
const plugin = await loadPlugin()
|
||||
const { provide } = plugin()
|
||||
|
||||
provide.logger.warn('Missing optional data')
|
||||
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
'[template:warn] 2026-03-29T12:00:00.000Z Missing optional data'
|
||||
)
|
||||
|
||||
vi.useRealTimers()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user