Passed
Push — master ( a3cf99...dec494 )
by Dmytro
02:02
created

tests/init.js   A

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 32
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
mnd 0
bc 0
fnc 6
dl 0
loc 32
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

3 Functions

Rating   Name   Duplication   Size   Complexity  
A init.js ➔ preventParentScopeModules 0 12 3
A init.js ➔ initEnv 0 3 1
A init.js ➔ clearRequireCache 0 5 2
1
/* eslint-disable import/no-commonjs */
2
const path = require('path');
3
const { Module } = require('module');
4
const dotenv = require('dotenv');
5
6
function clearRequireCache() {
7
    Object.keys(require.cache).forEach((key) => {
8
        delete require.cache[key];
9
    });
10
}
11
12
const ROOT_FOLDER = process.cwd();
13
14
function preventParentScopeModules() {
15
    const nodeModulePaths = Module._nodeModulePaths;
16
17
    Module._nodeModulePaths = function (from) {
18
        const originalPath = nodeModulePaths.call(this, from);
19
        const insideRootPaths = originalPath.filter(function (p) {
20
            return p.match(ROOT_FOLDER);
21
        });
22
23
        return insideRootPaths;
24
    };
25
}
26
27
function initEnv() {
28
    dotenv.config({ path: path.join(__dirname, './test.env') });
29
}
30
31
clearRequireCache();
32
preventParentScopeModules();
33
initEnv();
34