aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/miscs/tests.ts
diff options
context:
space:
mode:
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}