]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/miscs/miscs.ts
Don't rely on youtube for tests
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / miscs / miscs.ts
index f4e86b85a1f2b916774a07ff60353f7aadaa923b..caf09c01fdd41d23611ab402df8634c0c81cb0d3 100644 (file)
@@ -56,27 +56,33 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
   const body = res.body
 
   const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension))
-  const minLength = body.length - ((20 * body.length) / 100)
-  const maxLength = body.length + ((20 * body.length) / 100)
+  const minLength = body.length - ((30 * body.length) / 100)
+  const maxLength = body.length + ((30 * body.length) / 100)
 
-  expect(data.length).to.be.above(minLength)
-  expect(data.length).to.be.below(maxLength)
+  expect(data.length).to.be.above(minLength, "the generated image is way smaller than the recorded fixture")
+  expect(data.length).to.be.below(maxLength, "the generated image is way larger than the recorded fixture")
 }
 
 function buildAbsoluteFixturePath (path: string, customCIPath = false) {
-  if (isAbsolute(path)) {
-    return path
-  }
+  if (isAbsolute(path)) return path
 
   if (customCIPath) {
     if (process.env.GITLAB_CI) return join(root(), 'cached-fixtures', path)
 
-    if (process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path)
+    return join(process.env.HOME, 'fixtures', path)
   }
 
   return join(root(), 'server', 'tests', 'fixtures', path)
 }
 
+function areHttpImportTestsDisabled () {
+  const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true'
+
+  if (disabled) console.log('Import tests are disabled')
+
+  return disabled
+}
+
 async function generateHighBitrateVideo () {
   const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true)
 
@@ -131,6 +137,7 @@ async function generateVideoWithFramerate (fps = 60) {
 export {
   dateIsValid,
   wait,
+  areHttpImportTestsDisabled,
   buildServerDirectory,
   webtorrentAdd,
   immutableAssign,