]>
Commit | Line | Data |
---|---|---|
6c5065a0 C |
1 | import { stat } from 'fs-extra' |
2 | import { basename, isAbsolute, join, resolve } from 'path' | |
3 | ||
4 | function parallelTests () { | |
5 | return process.env.MOCHA_PARALLEL === 'true' | |
6 | } | |
7 | ||
8 | function isGithubCI () { | |
9 | return !!process.env.GITHUB_WORKSPACE | |
10 | } | |
11 | ||
12 | function areHttpImportTestsDisabled () { | |
13 | const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true' | |
14 | ||
15 | if (disabled) console.log('Import tests are disabled') | |
16 | ||
17 | return disabled | |
18 | } | |
19 | ||
20 | function buildAbsoluteFixturePath (path: string, customCIPath = false) { | |
21 | if (isAbsolute(path)) return path | |
22 | ||
23 | if (customCIPath && process.env.GITHUB_WORKSPACE) { | |
24 | return join(process.env.GITHUB_WORKSPACE, 'fixtures', path) | |
25 | } | |
26 | ||
27 | return join(root(), 'server', 'tests', 'fixtures', path) | |
28 | } | |
29 | ||
30 | function root () { | |
31 | // We are in /miscs | |
32 | let root = join(__dirname, '..', '..', '..') | |
33 | ||
34 | if (basename(root) === 'dist') root = resolve(root, '..') | |
35 | ||
36 | return root | |
37 | } | |
38 | ||
39 | function wait (milliseconds: number) { | |
40 | return new Promise(resolve => setTimeout(resolve, milliseconds)) | |
41 | } | |
42 | ||
43 | async function getFileSize (path: string) { | |
44 | const stats = await stat(path) | |
45 | ||
46 | return stats.size | |
47 | } | |
48 | ||
49 | function buildRequestStub (): any { | |
50 | return { } | |
51 | } | |
52 | ||
53 | export { | |
54 | parallelTests, | |
55 | isGithubCI, | |
56 | areHttpImportTestsDisabled, | |
57 | buildAbsoluteFixturePath, | |
58 | getFileSize, | |
59 | buildRequestStub, | |
60 | wait, | |
61 | root | |
62 | } |