Passed
Push — master ( 4ca75b...cc8dd9 )
by Dmytro
01:45 queued 12s
created

Test.js ➔ resolve   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import path from 'path';
2
import fse from 'fs-extra';
3
import API from './entry';
4
import { tmpFolder, entry } from './constants';
5
import { mockAPI, unMockAPI, startMockApp, stopMockApp } from  './mock';
6
7
export default class Test {
8
    createAPI(url = 'http://mock/', opts = undefined) {
9
        return new API(url, opts);
10
    }
11
12
    async setTmpFolder() {
13
        await fse.ensureDir(tmpFolder);
14
    }
15
16
    async cleanTmpFolder() {
17
        await fse.remove(tmpFolder);
18
    }
19
20
    mockAPI() {
21
        mockAPI();
22
    }
23
24
    unMockAPI() {
25
        unMockAPI();
26
    }
27
28
    async startMockApp() {
29
        this._server = await startMockApp();
30
    }
31
32
    get mockAppUrl() {
33
        const { port } = this._server.address();
34
35
        return `http://localhost:${port}`;
36
    }
37
38
    async stopMockApp() {
39
        await stopMockApp(this._server);
40
    }
41
}
42
43
function load(relPath) {
44
    // eslint-disable-next-line security/detect-non-literal-require
45
    return require(path.join(entry, relPath));
46
}
47
48
function resolve(relPath) {
49
    return require.resolve(path.join(entry, relPath));
50
}
51
52
export {
53
    tmpFolder,
54
    entry,
55
    load,
56
    resolve
57
};
58