Fixed the log class and updated tests
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Sambo Chea 2021-03-10 21:55:41 +07:00
parent 010dda1cad
commit 478c7ab38f
3 changed files with 15 additions and 15 deletions

View File

@ -1,16 +1,16 @@
import { Loggable } from "./interfaces"; import { Loggable } from './interfaces';
class Log { class Index {
static log(loggable: Loggable): void { static log(loggable: Loggable): void {
switch (loggable.type) { switch (loggable.type) {
case 'error': case 'error':
this.error(loggable.from, loggable.data) this.error(loggable.from, loggable.data);
break; break;
case 'warn': case 'warn':
this.warn(loggable.from, loggable.data) this.warn(loggable.from, loggable.data);
break; break;
default: default:
this.info(loggable.from, loggable.data) this.info(loggable.from, loggable.data);
break; break;
} }
} }
@ -20,12 +20,12 @@ class Log {
} }
static error(...data: any[]): void { static error(...data: any[]): void {
console.error(data) console.error(data);
} }
static warn(...data: any[]): void { static warn(...data: any[]): void {
console.warn(data) console.warn(data);
} }
} }
export default Log; export default Index;

View File

@ -1,4 +1,4 @@
type LogType = 'info' | 'error' | 'warn' export type LogType = 'info' | 'error' | 'warn';
export interface Loggable { export interface Loggable {
type: LogType; type: LogType;

View File

@ -1,20 +1,20 @@
import Log from '../src/log/Log'; import Index from '../src/Log';
describe('logging into console', function () { describe('logging into console', function () {
it('info', function () { it('info', function () {
Log.info('I am an info!'); Index.info('I am an info!');
}); });
it('warn', function () { it('warn', function () {
Log.info('I am a warn!'); Index.info('I am a warn!');
}); });
it('error', function () { it('error', function () {
Log.info('I am an error!'); Index.info('I am an error!');
}); });
it('loggable', function () { it('loggable', function () {
Log.log({ Index.log({
type: 'info', type: 'info',
from: 'log.test.ts', from: 'log.test.ts',
data: 'I am loggable called' data: 'I am loggable called'