ServerCrashTests.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. const { expect } = require('chai')
  2. const fs = require('fs')
  3. const Path = require('path')
  4. const fetch = require('node-fetch')
  5. const UserHelper = require('./helpers/UserHelper')
  6. const BASE_URL = UserHelper.baseUrl()
  7. const glob = require('glob')
  8. // Test all files in the crash_test_urls directory
  9. const CRASH_TEST_FILES = glob.sync(
  10. Path.join(__dirname, '../files/crash_test_urls/*.txt')
  11. )
  12. describe('Server Crash Tests', function () {
  13. for (const file of CRASH_TEST_FILES) {
  14. const crashTestUrls = fs.readFileSync(file).toString().split('\n')
  15. it(`should not crash on bad urls in ${file}`, async function () {
  16. // increase the timeout for these tests due to the number of urls
  17. this.timeout(60 * 1000)
  18. // test each url in the list
  19. for (let i = 0; i < crashTestUrls.length; i++) {
  20. const url = BASE_URL + crashTestUrls[i]
  21. const response = await fetch(url)
  22. expect(response.status).to.not.match(
  23. /5\d\d/,
  24. `Request to ${url} failed with status ${response.status}`
  25. )
  26. }
  27. })
  28. }
  29. })