aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/miscs/tests.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 09:43:59 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit6c5065a011b099618681a37bd77eaa7bd3db752e (patch)
tree352252a00b25013c4b1902f6bcd9668aba295c7b /shared/extra-utils/miscs/tests.ts
parent0d8ecb7592577f54012413a2b5a9b159cfc90399 (diff)
downloadPeerTube-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.ts62
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 @@
1import { stat } from 'fs-extra'
2import { basename, isAbsolute, join, resolve } from 'path'
3
4function parallelTests () {
5 return process.env.MOCHA_PARALLEL === 'true'
6}
7
8function isGithubCI () {
9 return !!process.env.GITHUB_WORKSPACE
10}
11
12function 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
20function 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
30function 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
39function wait (milliseconds: number) {
40 return new Promise(resolve => setTimeout(resolve, milliseconds))
41}
42
43async function getFileSize (path: string) {
44 const stats = await stat(path)
45
46 return stats.size
47}
48
49function buildRequestStub (): any {
50 return { }
51}
52
53export {
54 parallelTests,
55 isGithubCI,
56 areHttpImportTestsDisabled,
57 buildAbsoluteFixturePath,
58 getFileSize,
59 buildRequestStub,
60 wait,
61 root
62}