Files
tolaria/src/indexBootDiagnostics.test.ts

47 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-05-11 16:37:06 +02:00
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
function firstInlineScriptFromIndex(): string {
const indexHtml = readFileSync(`${process.cwd()}/index.html`, 'utf8')
const match = indexHtml.match(/<script>\s*([\s\S]*?)\s*<\/script>/)
2026-05-12 11:37:14 +02:00
if (!match) throw new Error('index.html startup script was not found')
2026-05-11 16:37:06 +02:00
return match[1]
}
2026-05-12 11:37:14 +02:00
describe('index startup script', () => {
2026-05-12 11:58:50 +02:00
it('does not ship a visible boot diagnostics element by default', () => {
const indexHtml = readFileSync(`${process.cwd()}/index.html`, 'utf8')
expect(indexHtml).not.toContain('Tolaria boot: HTML parsed')
expect(indexHtml).not.toContain('<pre id="tolaria-boot-diagnostics"')
})
2026-05-11 16:37:06 +02:00
it('does not show the boot overlay for ResizeObserver loop notifications', () => {
2026-05-12 11:37:14 +02:00
document.body.innerHTML = ''
2026-05-11 16:37:06 +02:00
new Function(firstInlineScriptFromIndex())()
const event = new ErrorEvent('error', {
cancelable: true,
message: 'ResizeObserver loop completed with undelivered notifications.',
})
window.dispatchEvent(event)
expect(event.defaultPrevented).toBe(true)
2026-05-12 11:37:14 +02:00
expect(document.body.children).toHaveLength(0)
2026-05-11 16:37:06 +02:00
})
2026-05-12 11:37:14 +02:00
it('does not create a visible boot overlay for real startup errors', () => {
document.body.innerHTML = ''
2026-05-11 16:37:06 +02:00
new Function(firstInlineScriptFromIndex())()
window.dispatchEvent(new ErrorEvent('error', {
message: 'startup failed',
filename: 'app.js',
lineno: 1,
colno: 2,
}))
2026-05-12 11:37:14 +02:00
expect(document.body.children).toHaveLength(0)
2026-05-11 16:37:06 +02:00
})
})