Skip to content

Commit

Permalink
Start adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Lengrand-Lambert authored and Julien Lengrand-Lambert committed May 1, 2018
1 parent 44f309e commit 89fdc01
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/utils/logger/index.js
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
}
42 changes: 42 additions & 0 deletions lib/utils/logger/index.spec.js
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('🙀');
});
});

0 comments on commit 89fdc01

Please sign in to comment.