|
| 1 | +import { afterEach, describe, expect, it, vi } from 'vitest'; |
| 2 | +import { Log, logCyan, logGreen, logMagneta, logRed } from '../src/Log'; |
| 3 | + |
| 4 | +describe('kitql - helper - Log', () => { |
| 5 | + afterEach(() => { |
| 6 | + vi.restoreAllMocks(); |
| 7 | + }); |
| 8 | + |
| 9 | + it('Minimal config', async () => { |
| 10 | + let log = new Log('tool name'); |
| 11 | + expect(log).to.have.property('toolName', 'tool name'); |
| 12 | + |
| 13 | + const spy = vi.spyOn(log, 'info'); |
| 14 | + log.info('Minimal config'); |
| 15 | + expect(spy).toHaveBeenCalledOnce(); |
| 16 | + }); |
| 17 | + |
| 18 | + it('Config with sync', async () => { |
| 19 | + let log = new Log('tool name', { sync: true }); |
| 20 | + expect(log).to.have.property('toolName', 'tool name'); |
| 21 | + |
| 22 | + const spy = vi.spyOn(log, 'info'); |
| 23 | + log.info('Config with sync'); |
| 24 | + expect(spy).toHaveBeenCalledOnce(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('Config without sync', async () => { |
| 28 | + let log = new Log('tool name', { sync: false }); |
| 29 | + expect(log).to.have.property('toolName', 'tool name'); |
| 30 | + |
| 31 | + const spy = vi.spyOn(log, 'info'); |
| 32 | + log.info('Config without sync'); |
| 33 | + expect(spy).toHaveBeenCalledOnce(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('Config with time', async () => { |
| 37 | + let log = new Log('tool name', { withTime: true }); |
| 38 | + expect(log).to.have.property('toolName', 'tool name'); |
| 39 | + |
| 40 | + const spy = vi.spyOn(log, 'info'); |
| 41 | + log.info('Config with time'); |
| 42 | + expect(spy).toHaveBeenCalledOnce(); |
| 43 | + }); |
| 44 | + |
| 45 | + it('Config with withlevelKey: false, should not print level', async () => { |
| 46 | + let log = new Log('tool name', { withlevelKey: false, sync: true }); |
| 47 | + expect(log).to.have.property('toolName', 'tool name'); |
| 48 | + |
| 49 | + const spy = vi.spyOn(log, 'info'); |
| 50 | + log.info('Config with key level'); |
| 51 | + expect(spy).toHaveBeenCalledOnce(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('with an error', async () => { |
| 55 | + let log = new Log('tool name'); |
| 56 | + expect(log).to.have.property('toolName', 'tool name'); |
| 57 | + |
| 58 | + const spy = vi.spyOn(log, 'error'); |
| 59 | + log.error('with an error'); |
| 60 | + expect(spy).toHaveBeenCalledOnce(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('with all colors', async () => { |
| 64 | + let log = new Log('tool name'); |
| 65 | + expect(log).to.have.property('toolName', 'tool name'); |
| 66 | + |
| 67 | + const spy = vi.spyOn(log, 'info'); |
| 68 | + log.info( |
| 69 | + `with all colors: ${logGreen('green')}, ${logMagneta('magneta')}, ${logRed('red')}, ${logCyan( |
| 70 | + 'cyan' |
| 71 | + )}, ` |
| 72 | + ); |
| 73 | + expect(spy).toHaveBeenCalledOnce(); |
| 74 | + }); |
| 75 | +}); |
0 commit comments