-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add initial unit tests for logging library (#17)
* test: add initial unit tests for logging library * add tests to workflow * fix devDependencies * add missing new line
- Loading branch information
Showing
6 changed files
with
4,000 additions
and
1,001 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.whisper | ||
data/* | ||
|
||
node_modules | ||
node_modules | ||
coverage |
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,60 @@ | ||
/* eslint-env jest */ | ||
const chalk = require('chalk') | ||
const log = require('./log') | ||
|
||
jest.spyOn(console, 'log').mockImplementation() | ||
|
||
describe('log', () => { | ||
beforeEach(() => { | ||
|
||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
delete process.env.DEBUG | ||
}) | ||
|
||
const levels = [ | ||
{ level: 'error', color: 'red' }, | ||
{ level: 'success', color: 'green' }, | ||
{ level: 'warn', color: 'yellow' }, | ||
{ level: 'info', color: 'cyan' }, | ||
{ level: 'notice', color: 'white' } | ||
] | ||
|
||
for (const test of levels) { | ||
describe(`${test.level}()`, () => { | ||
it(`should output ${test.level} message`, () => { | ||
log[test.level]('test') | ||
expect(console.log).toBeCalledWith(chalk[test.color]('test'), '') | ||
}) | ||
it(`should output ${test.level} with optional message`, () => { | ||
log[test.level]('test', { msg: 'testing' }) | ||
expect(console.log).toBeCalledWith(chalk[test.color]('test'), { msg: 'testing' }) | ||
}) | ||
}) | ||
} | ||
|
||
// separate test since it uses an env variable | ||
describe('debug()', () => { | ||
it('should not output debug message', () => { | ||
log.debug('test') | ||
expect(console.log).toBeCalledTimes(0) | ||
}) | ||
it('should not output debug with optional message', () => { | ||
log.debug('test', { msg: 'testing' }) | ||
expect(console.log).toBeCalledTimes(0) | ||
}) | ||
|
||
it('should output debug message', () => { | ||
process.env.DEBUG = true | ||
log.debug('test') | ||
expect(console.log).toBeCalledWith('[DEBUG] test', '') | ||
}) | ||
it('should output debug with optional message', () => { | ||
process.env.DEBUG = true | ||
log.debug('test', { msg: 'testing' }) | ||
expect(console.log).toBeCalledWith('[DEBUG] test', { msg: 'testing' }) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.