Passed
Push — master ( febfa8...1d87f0 )
by Dmytro
01:44
created

tests/package/params.test.js   A

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 40
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 6
mnd 2
bc 2
fnc 4
bpm 0.5
cpm 1.5
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A params.test.js ➔ x 0 5 3
1
import { assert } from 'chai';
2
import { Decorator } from '../entry';
3
import Logger from '../Logger';
4
import { verifyStdout } from '../utils';
5
6
suite('Params');
7
8
test('Positive: function paramsLevel', function () {
9
    const logger = new Logger();
10
    const decorator = new Decorator({ logger, paramsLevel: 'verbose' });
11
12
    const decorated = decorator()(function x(n) {
13
        if (n > 0) return n * 2;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
14
15
        return n;
16
    });
17
18
    assert.equal(decorated(4), 8);
19
    assert.isNotEmpty(logger.stack.verbose);
20
    verifyStdout(logger, { params: '[ 4 ]', result: '8' }, { level: 'info' });
21
    verifyStdout(logger, { method: 'x', params: '[ 4 ]' }, { level: 'verbose' });
22
});
23
24
25
test('Negative: function paramsLevel', function () {
26
    const logger = new Logger();
27
    const decorator = new Decorator({ logger });
28
29
    const decorated = decorator()(function (n) {
30
        if (n > 0) return n * 2;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
31
32
        return n;
33
    });
34
35
    assert.equal(decorated(4), 8);
36
37
    verifyStdout(logger, { params: '[ 4 ]', result: '8' }, { level: 'info' });
38
39
    assert.isEmpty(logger.stack.verbose);
40
});
41