Skip to content

Commit

Permalink
fix: fixed bug when sealing from a sealed logger
Browse files Browse the repository at this point in the history
Sealed loggers were not previously using a Configuration class which meant it had no exportValues
method.
  • Loading branch information
Andrew Stacy committed Sep 12, 2024
1 parent 08ff280 commit 2624eea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '🪵',
Expand Down
4 changes: 2 additions & 2 deletions src/functions/seal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
Expand Down
31 changes: 31 additions & 0 deletions test/seal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { afterEach, describe, expect, test, vi } from 'vitest';
import adze, { setup, teardown } from '../src';

Check failure on line 2 in test/seal.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'setup' is defined but never used

/**
* @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.'
);
});
});

0 comments on commit 2624eea

Please sign in to comment.