Issues (7)

tests/package/test-levels.test.js (3 issues)

1
import { createLogger } from 'winston';
2
import transport from '../entry';
3
4
import { verifyStdout } from '../utils';
5
6
7
const LEVELS = {
8
    info    : 2,
9
    notice  : 3,
10
    verbose : 4,
11
    debug   : 5
12
};
13
14
suite('Levels');
15
16
test('Positive: levels answering', function () {
17
    const logger = createLogger({
18
        level      : 'debug',
19
        levels     : LEVELS,
20
        transports : [ new transport() ]
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like transport should be capitalized.
Loading history...
21
    });
22
23
    Object.keys(LEVELS).forEach(level => {
24
        const input = `TEST LOGGING IN LEVEL ${level}`;
25
26
        verifyStdout(() => logger[level](input), { message: input });
27
    });
28
});
29
30
test('Positive: levels filtering', function () {
31
    const logger = createLogger({
32
        levels     : LEVELS,
33
        level      : 'notice',
34
        transports : [ new transport() ]
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like transport should be capitalized.
Loading history...
35
    });
36
37
    Object.keys(LEVELS).filter(key => LEVELS[key] <= 3).forEach(level => {
38
        const input = `TEST LOGGING IN LEVEL ${level}`;
39
40
        verifyStdout(() => logger[level](input), { message: input });
41
    });
42
    Object.keys(LEVELS).filter(key => LEVELS[key] > 3).forEach(level => {
43
        const input = `TEST LOGGING IN LEVEL ${level}`;
44
45
        verifyStdout(() => logger[level](input), null);
46
    });
47
});
48
49
50
test('Positive: levels mapping', function () {
51
    const logger = createLogger({
52
        levels     : LEVELS,
53
        level      : 'debug',
54
        transports : [ new transport({
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like transport should be capitalized.
Loading history...
55
            levels : {
56
                notice : console.error
57
            }
58
        }) ]
59
    });
60
61
    verifyStdout(
62
        () => logger.log('notice', 'Should be in stderr'),
63
        { 'message': 'Should be in stderr' },
64
        { stderr: true, json: true }
65
    );
66
});
67