Skip to content

Commit

Permalink
chore: test our types as well
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Oct 25, 2022
1 parent 2ed3e9c commit 707d687
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"scripts": {
"bench": "cross-env DEBUG=standard ROARR_LOG=true node -r tsm bench/index.ts",
"build": "bundt --minify",
"format": "prettier --write --list-different \"{*,bench/**/*,.github/**/*,test/*,src/*.spec}.+(ts|json|yml|md)\"",
"format": "prettier --write --list-different \"{*,bench/**/*,.github/**/*,test/**/*,src/*.spec}.+(ts|json|yml|md)\"",
"test": "uvu -r tsm -r test/helpers/setup.js src \".spec.ts$\"",
"typecheck": "tsc --noEmit"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ export const error: LogFn;
export const warn: LogFn;
export const debug: LogFn;
export const info: LogFn;
export const log: LogFn;
export const log: LogFn;
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Diary, LogEvent, LogLevels, Reporter } from 'diary';
import type { Diary, LogLevels, Reporter } from 'diary';

let allows: RegExp[] = [];

Expand Down Expand Up @@ -33,7 +33,7 @@ const loglevel_strings: Record<LogLevels, string> = /*#__PURE__*/ {
log: '◆ log ',
} as const;

export const default_reporter = (event: LogEvent) => {
export const default_reporter: Reporter = (event) => {
let label = '';
const fn = console[event.level === 'fatal' ? 'error' : event.level];

Expand Down
41 changes: 41 additions & 0 deletions test/types/diary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
type Diary,
type Reporter,
type LogLevels,
type LogEvent,
diary,
enable,
} from 'diary';

let scope = diary('name');
enable('*');

assert<Diary>(scope);
assert<Function>(enable);

scope.info('string');
scope.info(1);
scope.info([]);
scope.info({});
scope.info('string', {});

scope.info(new Error());
scope.fatal(new Error());
scope.warn(new Error());

diary('name');

// @ts-expect-error
diary({});

const reporter: Reporter = (event) => {
assert<LogEvent>(event);

assert<string>(event.name);
assert<unknown[]>(event.messages);
assert<LogLevels>(event.level);

assert<void>(event.blah); // allows other things
};

diary('name', reporter);
1 change: 1 addition & 0 deletions test/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare function assert<T>(type: T): void;

0 comments on commit 707d687

Please sign in to comment.