import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { devMessages, skipDevMessages } from '../src/dev'; describe('DevMessages', () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); const traceSpy = vi.spyOn(console, 'trace').mockImplementation(() => {}); beforeEach(() => { // Reset state before each test devMessages.displayed = []; devMessages.skipped = []; skipDevMessages(false); // Ensure skipping is off by default warnSpy.mockClear(); traceSpy.mockClear(); }); afterEach(() => { // Restore default behavior after each test skipDevMessages(false); }); it('should display warning messages by default', () => { devMessages.warn('Test warning'); expect(warnSpy).toHaveBeenCalledWith('Test warning'); expect(devMessages.displayed.length).toBe(1); expect(devMessages.displayed[0]).toEqual({ type: 'warn', args: ['Test warning'] }); expect(devMessages.skipped.length).toBe(0); }); it('should display notice messages by default', () => { devMessages.notice('Test notice'); expect(traceSpy).toHaveBeenCalledWith('⚠️', 'Test notice'); expect(devMessages.displayed.length).toBe(1); expect(devMessages.displayed[0]).toEqual({ type: 'notice', args: ['Test notice'] }); expect(devMessages.skipped.length).toBe(0); }); it('should skip warning messages when skip(true) is called', () => { skipDevMessages(true); devMessages.warn('Skipped warning'); expect(warnSpy).not.toHaveBeenCalled(); expect(devMessages.displayed.length).toBe(0); expect(devMessages.skipped.length).toBe(1); expect(devMessages.skipped[0]).toEqual({ type: 'warn', args: ['Skipped warning'] }); }); it('should skip notice messages when skip(true) is called', () => { skipDevMessages(true); devMessages.notice('Skipped notice'); expect(traceSpy).not.toHaveBeenCalled(); expect(devMessages.displayed.length).toBe(0); expect(devMessages.skipped.length).toBe(1); expect(devMessages.skipped[0]).toEqual({ type: 'notice', args: ['Skipped notice'] }); }); it('should allow checking the skip status without changing it', () => { expect(skipDevMessages()).toBe(false); skipDevMessages(true); expect(skipDevMessages()).toBe(true); skipDevMessages(false); expect(skipDevMessages()).toBe(false); }); it('should re-enable messages after skip(false)', () => { skipDevMessages(true); devMessages.warn('Should be skipped'); expect(warnSpy).not.toHaveBeenCalled(); expect(devMessages.skipped.length).toBe(1); skipDevMessages(false); devMessages.warn('Should be displayed'); expect(warnSpy).toHaveBeenCalledWith('Should be displayed'); expect(devMessages.displayed.length).toBe(1); expect(devMessages.displayed[0]).toEqual({ type: 'warn', args: ['Should be displayed'] }); // Skipped count remains from previous state expect(devMessages.skipped.length).toBe(1); }); });