Skip to content

Commit

Permalink
feat!: create levels as a tuple
Browse files Browse the repository at this point in the history
This might be a little bit more useful in usage than an array, especially where code might require a tuple as argument. As `levels` was recently introduced there is likely very little impact of this change, regardless, it is a breaking change.
  • Loading branch information
jdbruijn committed Apr 4, 2023
1 parent e2df5ea commit 1bae286
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/bunyan/levels.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import test from 'ava';
import {type LogLevelString} from 'bunyan';
import levels from './levels.js';

test('contains all Bunyan levels', (t) => {
t.deepEqual(levels, ['trace', 'debug', 'info', 'warn', 'error', 'fatal']);
});

const isValidLevel = test.macro<[(typeof levels)[number]]>({
exec(t, level) {
const bunaynLevel: LogLevelString = level;
t.is(level, bunaynLevel);
},
title: (_, level) => `"${level} is a valid Bunyan level`,
});

for (const level of levels) {
test(isValidLevel, level);
}
11 changes: 1 addition & 10 deletions src/bunyan/levels.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import {type LogLevelString} from 'bunyan';

const levels: readonly LogLevelString[] = [
'trace',
'debug',
'info',
'warn',
'error',
'fatal',
] as const;
const levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'] as const;

export default levels;

0 comments on commit 1bae286

Please sign in to comment.