-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce basic pre/post processor logic (#96)
* Intorduce pro/post processors * Implement tests * Fix lint * Fix test coverage and remove method scope processors * Fix generics * More options for processors * JsDocs
- Loading branch information
1 parent
c2a4707
commit fd9f1ef
Showing
5 changed files
with
140 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import chalk from 'chalk'; | ||
|
||
import { createLogger, Logger } from '../src'; | ||
|
||
const logFunction = jest.fn(); | ||
|
||
describe('Post Process Logging', () => { | ||
let logger: Logger<'ok'>; | ||
|
||
beforeAll(() => { | ||
logger = createLogger( | ||
{ | ||
ok: { | ||
label: chalk.greenBright`[OK]`, | ||
newLine: '| ', | ||
newLineEnd: '\\-', | ||
}, | ||
}, | ||
{ | ||
padding: 'PREPEND', | ||
color: false, | ||
postProcessors: [ | ||
(lines, { name }) => { | ||
let index = 0; | ||
|
||
return lines.map(it => `[Called ${name} ${++index} times] ${it}`); | ||
} | ||
] | ||
}, | ||
logFunction | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should log with pre-processor', () => { | ||
logger.ok( | ||
'This is the best logging library', | ||
'It\'s not even a question', | ||
'It even supports multi\nline logs' | ||
); | ||
expect(logFunction).toBeCalledWith( | ||
`[Called ok 1 times] ${chalk.greenBright('[OK]')} This is the best logging library\n` + | ||
'[Called ok 2 times] | It\'s not even a question\n' + | ||
'[Called ok 3 times] | It even supports multi\n' + | ||
'[Called ok 4 times] \\- line logs' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import chalk from 'chalk'; | ||
|
||
import { createLogger, Logger } from '../src'; | ||
|
||
const logFunction = jest.fn(); | ||
|
||
describe('Pre Process Logging', () => { | ||
let logger: Logger<'ok'>; | ||
|
||
beforeAll(() => { | ||
logger = createLogger( | ||
{ | ||
ok: { | ||
label: chalk.greenBright`[OK]`, | ||
newLine: '| ', | ||
newLineEnd: '\\-', | ||
}, | ||
}, | ||
{ | ||
padding: 'PREPEND', | ||
color: false, | ||
preProcessors: [ | ||
(inputs, { name }) => { | ||
let index = 0; | ||
|
||
return inputs.map(it => `[Called ${name} ${++index} times] ${it}`); | ||
} | ||
] | ||
}, | ||
logFunction | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should log with pre-processor', () => { | ||
logger.ok( | ||
'This is the best logging library', | ||
'It\'s not even a question', | ||
'It even supports multi\nline logs' | ||
); | ||
expect(logFunction).toBeCalledWith( | ||
`${chalk.greenBright('[OK]')} [Called ok 1 times] This is the best logging library\n` + | ||
' | [Called ok 2 times] It\'s not even a question\n' + | ||
' | [Called ok 3 times] It even supports multi\n' + | ||
' \\- line logs' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters