ServerCrashTests.mjs 1.1 KB

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