From 2624eeae3fa815d156c41aad060b2274fc68bc11 Mon Sep 17 00:00:00 2001 From: Andrew Stacy <astacy@stratacache.com> Date: Thu, 12 Sep 2024 13:20:16 -0400 Subject: [PATCH] fix: fixed bug when sealing from a sealed logger Sealed loggers were not previously using a Configuration class which meant it had no exportValues method. --- src/constants.ts | 3 ++- src/functions/seal.ts | 4 ++-- test/seal.test.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 test/seal.test.ts diff --git a/src/constants.ts b/src/constants.ts index fdde793..2cbd75f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -246,7 +246,8 @@ export function getLogConfig(overrides: Partial<LevelConfiguration> = {}): Level return { levelName: 'log', level: 6, - style: `font-size: 12px; border-radius: 4px; padding-right: 51px; background: linear-gradient(to right, #ecedef, #d9dce0); color: #333435; border-color: #bfc1c5;`, + style: + 'font-size: 12px; border-radius: 4px; padding-right: 51px; background: linear-gradient(to right, #ecedef, #d9dce0); color: #333435; border-color: #bfc1c5;', terminalStyle: ['white', 'bgGray'], method: 'log', emoji: '🪵', diff --git a/src/functions/seal.ts b/src/functions/seal.ts index f5878e3..3c8ba52 100644 --- a/src/functions/seal.ts +++ b/src/functions/seal.ts @@ -21,11 +21,11 @@ export function SealedLog<N extends string, Msg, TBase extends Constructor = Con ) { const { formatters, middleware = [], ...cfgWithoutFormatters } = cfg.exportValues(); const sealing: unknown = class Sealing extends Base { - _cfg = { + _cfg = new Configuration({ ...structuredClone(cfgWithoutFormatters), formatters: { ...formatters }, middleware: [...middleware], - }; + }); _modifierData = structuredClone(mods); modifierQueue = [...modifierQueue]; }; diff --git a/test/seal.test.ts b/test/seal.test.ts new file mode 100644 index 0000000..7b5c22c --- /dev/null +++ b/test/seal.test.ts @@ -0,0 +1,31 @@ +import { afterEach, describe, expect, test, vi } from 'vitest'; +import adze, { setup, teardown } from '../src'; + +/** + * @vitest-environment happy-dom + */ + +describe('Configuration', () => { + afterEach(() => { + delete globalThis.$ADZE_ENV; + window.location.search = ''; + teardown(); + }); + + test('can seal an already sealed logger', () => { + console.log = vi.fn(); + + const logger1 = adze.withEmoji.seal(); + const logger2 = logger1.ns('sealed').seal(); + + logger2.log('This is a log from a twice sealed logger.'); + + expect(console.log).toHaveBeenCalledWith( + '%c🪵 %c Log', + 'font-size: 12px;', + 'font-size: 12px; border-radius: 4px; padding-right: 51px; background: linear-gradient(to right, #ecedef, #d9dce0); color: #333435; border-color: #bfc1c5;', + '#sealed ', + 'This is a log from a twice sealed logger.' + ); + }); +});