aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/miscs
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/miscs')
-rw-r--r--server/tests/utils/miscs/miscs.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index e6666619b..f93e2372e 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -1,5 +1,10 @@
1/* tslint:disable:no-unused-expression */
2
3import { expect } from 'chai'
1import { join } from 'path' 4import { join } from 'path'
5import * as request from 'supertest'
2import * as WebTorrent from 'webtorrent' 6import * as WebTorrent from 'webtorrent'
7import { readFileBufferPromise } from '../../../helpers/core-utils'
3 8
4let webtorrent = new WebTorrent() 9let webtorrent = new WebTorrent()
5 10
@@ -30,6 +35,27 @@ function root () {
30 return join(__dirname, '..', '..', '..', '..') 35 return join(__dirname, '..', '..', '..', '..')
31} 36}
32 37
38async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
39 // Don't test images if the node env is not set
40 // Because we need a special ffmpeg version for this test
41 if (process.env[ 'NODE_TEST_IMAGE' ]) {
42 const res = await request(url)
43 .get(imagePath)
44 .expect(200)
45
46 const body = res.body
47
48 const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension))
49 const minLength = body.length - ((50 * body.length) / 100)
50 const maxLength = body.length + ((50 * body.length) / 100)
51
52 return data.length > minLength && data.length < maxLength
53 } else {
54 console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.')
55 return true
56 }
57}
58
33// --------------------------------------------------------------------------- 59// ---------------------------------------------------------------------------
34 60
35export { 61export {
@@ -37,5 +63,6 @@ export {
37 wait, 63 wait,
38 webtorrentAdd, 64 webtorrentAdd,
39 immutableAssign, 65 immutableAssign,
66 testImage,
40 root 67 root
41} 68}