-
Notifications
You must be signed in to change notification settings - Fork 118
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
1 parent
0da2edc
commit 606ac91
Showing
1 changed file
with
111 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { assertEquals } from 'https://deno.land/[email protected]/assert/mod.ts'; | ||
import { describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts'; | ||
import { Logger } from "../logger.ts"; | ||
|
||
describe('Logger', () => { | ||
it('getLogs should return an array of entries', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.info('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.method, 'test'); | ||
}) | ||
|
||
it('should be able to add entries of different severity', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.info('test'); | ||
logger.debug('test'); | ||
logger.error('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 3); | ||
assertEquals(logs.entries[0].severity, 'info'); | ||
assertEquals(logs.entries[1].severity, 'debug'); | ||
assertEquals(logs.entries[2].severity, 'error'); | ||
}) | ||
|
||
it('should be able to add an info entry', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.info('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'info'); | ||
}); | ||
|
||
it('should be able to add an debug entry', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.debug('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'debug'); | ||
}); | ||
|
||
it('should be able to add an error entry', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.error('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'error'); | ||
}); | ||
|
||
it('should be able to add an success entry', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.success('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'success'); | ||
}); | ||
|
||
it('should be able to add an warning entry', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.warning('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'warning'); | ||
}); | ||
|
||
it('should be able to add an log entry', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.log('test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'log'); | ||
}); | ||
|
||
it('should be able to add an entry with multiple arguments', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.log('test', 'test', 'test'); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].args[1], 'test'); | ||
assertEquals(logs.entries[0].args[2], 'test'); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'log'); | ||
}); | ||
|
||
it('should be able to add an entry with multiple arguments of different types', () => { | ||
const logger = new Logger('test', 'test'); | ||
logger.log('test', 1, true, { foo: 'bar' }); | ||
const logs = logger.getLogs(); | ||
assertEquals(logs.entries.length, 1); | ||
assertEquals(logs.entries[0].args[0], 'test'); | ||
assertEquals(logs.entries[0].args[1], 1); | ||
assertEquals(logs.entries[0].args[2], true); | ||
assertEquals(logs.entries[0].args[3], { foo: 'bar' }); | ||
assertEquals(logs.entries[0].method, 'test'); | ||
assertEquals(logs.entries[0].severity, 'log'); | ||
}); | ||
|
||
}) |