Passed
Push — master ( 19fbeb...acc0f5 )
by Dmytro
01:54 queued 12s
created

utils.js ➔ load   A

Complexity

Conditions 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
c 0
b 0
f 0
rs 10
cc 3
1
import path from 'path';
2
import { assert } from 'chai';
3
import { entry } from './constants';
4
5
export async function checkError(promise, type, message) {
6
    try {
7
        await promise;
8
        assert.fail();
9
    } catch (error) {
10
        if (error.name === 'AssertionError') throw error;
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...
11
        assert.equal(error.name, type, error.toString());
12
        assert.equal(error.message, message, error.toString());
13
    }
14
}
15
16
export function load(relPath, clearCache) {
17
    const absPath = path.resolve(entry, relPath);
18
19
    if (clearCache) delete require.cache[require.resolve(absPath)];
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...
20
    // eslint-disable-next-line security/detect-non-literal-require
21
    const result =  require(absPath);
22
23
    if (clearCache) delete require.cache[require.resolve(absPath)];
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...
24
25
    return result;
26
}
27
28
export function resolve(relPath) {
29
    return require.resolve(path.join(entry, relPath));
30
}
31