-
Notifications
You must be signed in to change notification settings - Fork 0
/
log-middleware.test.js
47 lines (45 loc) · 1.79 KB
/
log-middleware.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import StashKu from '@appku/stashku';
import LogMiddleware from './log-middleware.js';
import jest from 'jest-mock';
const SUPPORTED_SEVERITIES = ['debug', 'info', 'warn', 'error'];
const cloneMiddleware = () => Object.assign({}, LogMiddleware);
describe('~callback', () => {
it('only supports the "log" state.', () => {
expect(LogMiddleware.states).toEqual(['log']);
});
describe('~callback', () => {
it('is called from stashku.', async () => {
let stash = new StashKu();
let mw = cloneMiddleware();
mw.callback = jest.fn(mw.callback);
stash.use(mw);
for (let severity of SUPPORTED_SEVERITIES) {
await stash.middlerun('log', severity, ['message', 123]);
expect(mw.callback).toHaveBeenCalled();
expect(mw.callback).toHaveBeenCalledWith(stash, stash.engine, severity, ['message', 123]);
}
});
it('sets logger configurations from stashku', async () => {
let stash = new StashKu({
'@appku/stashku-log': {
console: {
enabled: false,
unique: 123
},
file: {
enabled: false,
unique: 'hello'
}
}
});
let mw = cloneMiddleware();
mw.callback = jest.fn(mw.callback);
stash.use(mw);
await stash.middlerun('log', 'debug', ['message', 123]);
expect(mw.config.console.enabled).toBe(false);
expect(mw.config.console.unique).toBe(123);
expect(mw.config.file.enabled).toBe(false);
expect(mw.config.file.unique).toBe('hello');
});
});
});