mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-28 09:51:06 -06:00
a839c86d83
* Electron-66 - Added more unit tests for config, getRegistry & throttle * Electron-66 - Added some more unit tests and enabled activity detection unit test
71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
const { Logger } = require('../js/log.js');
|
|
|
|
describe('logger tests', function() {
|
|
let log;
|
|
|
|
beforeEach(function() {
|
|
// get new rewired version for each test.
|
|
log = new Logger();
|
|
});
|
|
|
|
it('when no logger registered then queue items', function() {
|
|
log.send('DEBUG', 'test');
|
|
log.send('DEBUG', 'test2');
|
|
let queue = log.logQueue;
|
|
expect(queue.length).toBe(2);
|
|
});
|
|
|
|
it('flush queue when logger get registered', function() {
|
|
log.send('DEBUG', 'test');
|
|
log.send('DEBUG', 'test2');
|
|
|
|
let mockWin = {
|
|
send: jest.fn()
|
|
};
|
|
|
|
log.setLogWindow(mockWin);
|
|
|
|
let queue = log.logQueue;
|
|
|
|
expect(mockWin.send).toHaveBeenCalled();
|
|
expect(queue.length).toBe(0);
|
|
});
|
|
|
|
it('send single log msg logger has already been registered', function() {
|
|
let mockWin = {
|
|
send: jest.fn()
|
|
};
|
|
|
|
log.setLogWindow(mockWin);
|
|
log.send('DEBUG', 'test');
|
|
|
|
let queue = log.logQueue;
|
|
|
|
expect(mockWin.send).toHaveBeenCalled();
|
|
expect(queue.length).toBe(0);
|
|
});
|
|
|
|
it('should cap at 100 queued log messages', function() {
|
|
for(let i = 0; i < 110; i++) {
|
|
log.send('DEBUG', 'test' + i);
|
|
}
|
|
|
|
let queue = log.logQueue;
|
|
expect(queue.length).toBe(100);
|
|
});
|
|
|
|
it('should not send the logs', function() {
|
|
let mockWin = {
|
|
send: jest.fn()
|
|
};
|
|
|
|
log.setLogWindow(mockWin);
|
|
log.send();
|
|
|
|
let queue = log.logQueue;
|
|
|
|
expect(mockWin.send).toHaveBeenCalledWith("log", {"msgs": []});
|
|
expect(queue.length).toBe(0);
|
|
});
|
|
});
|