25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
1.8 KiB

  1. import assert from 'node:assert/strict'
  2. import test from 'node:test'
  3. import { readFileSync } from 'node:fs'
  4. const source = readFileSync(new URL('../../unreal_tran_web/src/features/guide-legacy/demo-src/ofd-render-interactive.js', import.meta.url), 'utf8')
  5. const handlerSource = source.slice(source.indexOf(' const reportedLoadErrors = new WeakSet();'), source.indexOf(' const syncAnimationControls ='))
  6. function fixture(destroyed = false) {
  7. const statuses = []
  8. const messages = []
  9. const report = new Function('destroyed', 'setStatus', 'onError', `${handlerSource}\nreturn reportLoadError`)(
  10. destroyed,
  11. (text, error) => statuses.push({ text, error }),
  12. error => messages.push(error),
  13. )
  14. return { report, statuses, messages }
  15. }
  16. test('GLB load and ready rejection handlers report the same failure only once', () => {
  17. const f = fixture()
  18. const error = new Error('HTTP 503: asset service unavailable')
  19. f.report(error)
  20. f.report(error)
  21. assert.deepEqual(f.messages, [error])
  22. assert.ok(f.statuses.length > 0)
  23. assert.ok(f.statuses.every(status => status.error && !status.text.includes(error.message)))
  24. assert.match(f.statuses.at(-1).text, /重新加载/)
  25. })
  26. test('retrying an unavailable GLB still reports the new failed request', () => {
  27. const f = fixture()
  28. f.report(new Error('HTTP 503'))
  29. f.report(new Error('HTTP 503'))
  30. assert.equal(f.messages.length, 2)
  31. })
  32. test('cancelled and destroyed model viewers do not surface stale load errors', () => {
  33. const f = fixture()
  34. f.report(Object.assign(new Error('cancelled'), { name: 'AbortError' }))
  35. assert.equal(f.messages.length, 0)
  36. assert.equal(f.statuses.length, 0)
  37. const destroyed = fixture(true)
  38. destroyed.report(new Error('late HTTP 503'))
  39. assert.equal(destroyed.messages.length, 0)
  40. assert.equal(destroyed.statuses.length, 0)
  41. })