]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/miscs/tests.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / miscs / tests.ts
CommitLineData
6c5065a0
C
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}