Skip to content

Commit

Permalink
🚧 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed May 22, 2024
1 parent a41906d commit dc90c70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User {
function example(oe: OnEmitFn) {
let user = new User();

let scope = diary(oe, {pid: Deno.pid});
let scope = diary(oe, { pid: Deno.pid });

scope('log', 'this is a log message');
scope('info', 'this is an info message');
Expand All @@ -32,7 +32,7 @@ function example(oe: OnEmitFn) {
scope('info', 'this {user} exists', { user });
scope('info', 'we call that user {name} with {id}', user);

scope('info', 'we also have inherited props like {pid}');
scope('info', 'we also have inherited props like {pid}');
}

console.log('============ PRETTY ============\n');
Expand Down
2 changes: 1 addition & 1 deletion migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let v5Events: any[] = [];
{
const log = v5.diary((level, event, props) => {
v5Events.push({ name, level, messages: [event, props] });
}, {name: 'v0.5'});
}, { name: 'v0.5' });

log('debug', 'hello');
log('log', 'hello {phrase}', { phrase: 'world', extra: ['extra', 'props'] });
Expand Down
25 changes: 24 additions & 1 deletion src/mod.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assertInstanceOf } from '@std/assert';
import { assertSpyCall, spy } from '@std/testing/mock';

import * as lib from './mod.ts';
import type { Level } from './mod.ts';
import * as lib from './mod.ts';

Deno.test('api', () => {
assertInstanceOf(lib.diary, Function);
Expand Down Expand Up @@ -69,3 +69,26 @@ Deno.test('should allow anything as prop value', () => {
args: ['info', 'hello {phrase}', { phrase: t }],
});
});

Deno.test('should allow merging of props', () => {
let emit = spy();
let log = lib.diary(emit, { foo: 'bar' });

log('info', 'hello {phrase}', { phrase: 'world' });
log('info', 'hello {foo}');
log('debug', 'hello {phrase} {foo}', { phrase: 'world' });

assertSpyCall(emit, 0, {
args: ['info', 'hello {phrase}', { phrase: 'world', foo: 'bar' }],
});
assertSpyCall(emit, 1, {
args: ['info', 'hello {foo}', { foo: 'bar' }],
});
assertSpyCall(emit, 2, {
args: [
'debug',
'hello {phrase} {foo}',
{ phrase: 'world', foo: 'bar' },
],
});
});

0 comments on commit dc90c70

Please sign in to comment.