-
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.
- Loading branch information
Julien Lengrand-Lambert
authored and
Julien Lengrand-Lambert
committed
May 1, 2018
1 parent
44f309e
commit 89fdc01
Showing
2 changed files
with
58 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
const chalk = require('chalk'); | ||
|
||
const Logger = { | ||
log : (...args) =>{ | ||
console.log(...args); | ||
}, | ||
|
||
warn : (...args) =>{ | ||
console.log('⚠️', chalk.yellow.bold(...args)); | ||
}, | ||
|
||
err : (...args) =>{ | ||
console.log('🙀', chalk.red.bold(...args)); | ||
const getLogger = function(transport){ | ||
return { | ||
log : (...args) =>{ | ||
transport.log(...args); | ||
}, | ||
|
||
warn : (...args) =>{ | ||
transport.log('⚠️', chalk.yellow.bold(...args)); | ||
}, | ||
|
||
err : (...args) =>{ | ||
transport.log('🙀', chalk.red.bold(...args)); | ||
} | ||
} | ||
|
||
}; | ||
} | ||
|
||
module.exports = { | ||
logger: Logger | ||
logger: getLogger(console), | ||
getLogger: getLogger | ||
} |
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,42 @@ | ||
const {getLogger} = require('./index'); | ||
|
||
describe('utils/logger', () => { | ||
let mockConsole; | ||
let logger; | ||
|
||
beforeAll(() => { | ||
mockConsole = { | ||
content: '', | ||
|
||
log: function(...args) { | ||
this.content = [...args]; | ||
}, | ||
} | ||
logger = getLogger(mockConsole); | ||
}); | ||
|
||
test('Testing normal log message', () => { | ||
|
||
logger.log('test', 'plop'); | ||
|
||
expect(mockConsole.content).toHaveLength(2); | ||
expect(mockConsole.content).toEqual(['test', 'plop']); | ||
}); | ||
|
||
test('Testing warning log message', () => { | ||
|
||
logger.warn('test', 'plop'); | ||
|
||
expect(mockConsole.content).toHaveLength(2); | ||
expect(mockConsole.content[0]).toEqual('⚠️'); | ||
}); | ||
|
||
test('Testing error log message', () => { | ||
|
||
logger.err('test', 'plop'); | ||
|
||
expect(mockConsole.content).toHaveLength(2); | ||
expect(mockConsole.content[0]).toEqual('🙀'); | ||
}); | ||
}); | ||
|