UNPKG

@alexaegis/logging

Version:

Minimal logging tools

1 lines 1.85 kB
{"version":3,"file":"mocks.cjs","names":[],"sources":["../src/mocks.ts"],"sourcesContent":["import type { vi } from 'vitest';\nimport type { Logger } from './index.js';\n\nexport interface MockLogger {\n\tsilly: ReturnType<typeof vi.fn>;\n\ttrace: ReturnType<typeof vi.fn>;\n\tdebug: ReturnType<typeof vi.fn>;\n\tlog: ReturnType<typeof vi.fn>;\n\tinfo: ReturnType<typeof vi.fn>;\n\twarn: ReturnType<typeof vi.fn>;\n\tfatal: ReturnType<typeof vi.fn>;\n\terror: ReturnType<typeof vi.fn>;\n\tattachTransport: ReturnType<typeof vi.fn>;\n\tgetSubLogger: ReturnType<typeof vi.fn>;\n}\n\n/**\n * The vi object is passed because if there's a version mismatch in a pnpm\n * workspace between this package and its consumer, a different vitest will\n * initialize these mock functions and you wouldn't be able to reset/clear\n * mocks\n *\n * It will return a logger wrapped in an object, under two keys:\n * one with the mock type to let you use them as mocks, and one with the real\n * Logger type so you can pass it around. Both are the same object instance.\n */\nexport const createMockLogger = (\n\tvi: typeof import('vitest').vi,\n): { mockLogger: MockLogger; logger: Logger<unknown> } => {\n\tconst mockLogger: MockLogger = {\n\t\tsilly: vi.fn(),\n\t\ttrace: vi.fn(),\n\t\tdebug: vi.fn(),\n\t\tlog: vi.fn(),\n\t\tinfo: vi.fn(),\n\t\twarn: vi.fn(),\n\t\tfatal: vi.fn(),\n\t\terror: vi.fn(),\n\t\tattachTransport: vi.fn(),\n\t\tgetSubLogger: vi.fn(),\n\t};\n\n\treturn { logger: mockLogger as unknown as Logger<unknown>, mockLogger };\n};\n"],"mappings":";;;;;;;;;;;;AA0BA,IAAa,oBACZ,OACyD;CACzD,MAAM,aAAyB;EAC9B,OAAO,GAAG,GAAG;EACb,OAAO,GAAG,GAAG;EACb,OAAO,GAAG,GAAG;EACb,KAAK,GAAG,GAAG;EACX,MAAM,GAAG,GAAG;EACZ,MAAM,GAAG,GAAG;EACZ,OAAO,GAAG,GAAG;EACb,OAAO,GAAG,GAAG;EACb,iBAAiB,GAAG,GAAG;EACvB,cAAc,GAAG,GAAG;CACrB;CAEA,OAAO;EAAE,QAAQ;EAA0C;CAAW;AACvE"}