diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-13 09:43:59 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 6c5065a011b099618681a37bd77eaa7bd3db752e (patch) | |
tree | 352252a00b25013c4b1902f6bcd9668aba295c7b /shared/extra-utils/miscs/tests.ts | |
parent | 0d8ecb7592577f54012413a2b5a9b159cfc90399 (diff) | |
download | PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.gz PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.zst PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.zip |
Introduce server commands
Diffstat (limited to 'shared/extra-utils/miscs/tests.ts')
-rw-r--r-- | shared/extra-utils/miscs/tests.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/shared/extra-utils/miscs/tests.ts b/shared/extra-utils/miscs/tests.ts new file mode 100644 index 000000000..8f7a2f92b --- /dev/null +++ b/shared/extra-utils/miscs/tests.ts | |||
@@ -0,0 +1,62 @@ | |||
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 | } | ||