Total Complexity | 10 |
Complexity/F | 1 |
Lines of Code | 57 |
Function Count | 10 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |