Passed
Push — master ( 1f4975...33c5b5 )
by Dmytro
01:42
created

tests/utils.js   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 18
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
mnd 2
bc 2
fnc 2
dl 0
loc 18
bpm 1
cpm 2
noi 2
c 0
b 0
f 0
rs 10
1
import path from 'path';
2
import { promisify } from 'util';
3
import { exec } from 'child_process';
4
import { entry } from './constants';
5
6
const execAsync = promisify(exec);
7
8
export function load(relPath, clearCache) {
9
    const absPath = path.resolve(entry, relPath);
10
11
    if (clearCache) delete require.cache[require.resolve(absPath)];
12
    // eslint-disable-next-line security/detect-non-literal-require
13
    const result =  require(absPath);
14
15
    if (clearCache) delete require.cache[require.resolve(absPath)];
16
17
    return result;
18
}
19
20
export function resolve(relPath) {
21
    return require.resolve(path.join(entry, relPath));
22
}
23
24
25
export async function CLITester(command, args = {}) {
26
    try {
27
        const execArgs = {
28
            shell : true,
29
            ...args
30
        };
31
32
        const { stdout } = await execAsync(command.join(' '), execArgs);
33
34
        console.log(stdout);
35
36
        return stdout;
37
    } catch (error) {
38
        console.log(error.stdout);
39
        console.error(error);
40
        throw error;
41
    }
42
}
43