request.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
  4. import { get4KFileUrl, root, wait } from '../../../shared/extra-utils'
  5. import { join } from 'path'
  6. import { pathExists, remove } from 'fs-extra'
  7. import { expect } from 'chai'
  8. describe('Request helpers', function () {
  9. const destPath1 = join(root(), 'test-output-1.txt')
  10. const destPath2 = join(root(), 'test-output-2.txt')
  11. it('Should throw an error when the bytes limit is exceeded for request', async function () {
  12. try {
  13. await doRequest({ uri: get4KFileUrl() }, 3)
  14. } catch {
  15. return
  16. }
  17. throw new Error('No error thrown by do request')
  18. })
  19. it('Should throw an error when the bytes limit is exceeded for request and save file', async function () {
  20. try {
  21. await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath1, 3)
  22. } catch {
  23. await wait(500)
  24. expect(await pathExists(destPath1)).to.be.false
  25. return
  26. }
  27. throw new Error('No error thrown by do request and save to file')
  28. })
  29. it('Should succeed if the file is below the limit', async function () {
  30. await doRequest({ uri: get4KFileUrl() }, 5)
  31. await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath2, 5)
  32. expect(await pathExists(destPath2)).to.be.true
  33. })
  34. after(async function () {
  35. await remove(destPath1)
  36. await remove(destPath2)
  37. })
  38. })