Skip to content

Commit

Permalink
test: add tests to logger file
Browse files Browse the repository at this point in the history
  • Loading branch information
tapiarafael committed Dec 11, 2023
1 parent 0da2edc commit 606ac91
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions deno-runtime/lib/tests/logger.test.ts
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');
});

})

0 comments on commit 606ac91

Please sign in to comment.