mirror of
https://github.com/finos/SymphonyElectron.git
synced 2026-07-29 15:55:55 -05:00
add logging and unit tests (#117)
* add logging and unit tests * fix logging msg spell for notification
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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);
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
const getCmdLineArg = require('../../js/utils/getCmdLineArg.js');
|
||||
|
||||
describe('getCmdLineArg tests', function() {
|
||||
it('should return no exact match', function() {
|
||||
var result = getCmdLineArg([ 'hello.exe', '--arg1', '--arg2'], '--arg', true);
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
it('should return exact match only', function() {
|
||||
var result = getCmdLineArg([ 'hello.exe', '--arg1', '--arg2'], '--arg2', true);
|
||||
expect(result).toBe('--arg2');
|
||||
});
|
||||
|
||||
it('should return starts with match', function() {
|
||||
var result = getCmdLineArg([ 'hello.exe', '--hello=test', '--arg2'], '--hello=');
|
||||
expect(result).toBe('--hello=test');
|
||||
});
|
||||
|
||||
it('should return no match for starts with', function() {
|
||||
var result = getCmdLineArg([ 'hello.exe', '--hello=test', '--arg2'], '--help=');
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
it('should return no match invalid argv given', function() {
|
||||
var result = getCmdLineArg('invalid argv', '--help=');
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user