anbot

c1d80cc / test/webui.sh

View file at this commit

diff --git a/test/webui.sh b/test/webui.sh
index 76435da..5b29385 100755
--- a/test/webui.sh
+++ b/test/webui.sh
@@ -74,10 +74,11 @@ function getRaw(path) {
   })
 }
 
-function checkHtml(page) {
+function checkHtml(page, live = false) {
   assert.equal(page.status, 200)
   assert.match(page.type, /^text\/html/)
-  assert.doesNotMatch(page.text, /<script/)
+  const scripts = page.text.match(/<script\b[^>]*>/g) ?? []
+  assert.deepEqual(scripts, live ? ['<script src="./feed-live.js" defer>'] : [])
 }
 
 const index = await get('/')
@@ -124,7 +125,11 @@ assert.equal((await getRaw('/tree/%2e%2e/')).status, 404)
 assert.equal((await getRaw('/blob/%2e%2e%2fREADME.md')).status, 404)
 
 const feed = await get('/feed')
-checkHtml(feed)
+checkHtml(feed, true)
+assert.match(feed.text, /id="feed-entries"/)
+const liveScript = await get('/feed-live.js')
+assert.equal(liveScript.status, 200)
+assert.match(liveScript.type, /^text\/javascript/)
 assert.match(feed.text, /<h1>ANBot feed<\/h1>/)
 assert.doesNotMatch(feed.text, /<style|\sstyle=|<form|ANBot repository|<table/)
 assert.match(feed.text, /Hello &lt;script&gt;alert\(1\)&lt;\/script&gt;<br>\nSecond line/)
@@ -132,15 +137,15 @@ assert.ok(feed.text.includes(`?author=${encodeURIComponent(author)}`))
 assert.ok(feed.text.includes(`?post=${encodeURIComponent(post)}`))
 assert.ok(feed.text.indexOf('Reply from another author') < feed.text.indexOf('Hello'))
 const ownFeed = await get(`/feed?author=${encodeURIComponent(author)}`)
-checkHtml(ownFeed)
+checkHtml(ownFeed, true)
 assert.match(ownFeed.text, /Hello/)
 assert.doesNotMatch(ownFeed.text, /Reply from another author/)
 const peerFeed = await get(`/feed?author=${encodeURIComponent(other)}`)
-checkHtml(peerFeed)
+checkHtml(peerFeed, true)
 assert.match(peerFeed.text, /Reply from another author/)
 assert.doesNotMatch(peerFeed.text, /Hello/)
 const thread = await get(`/feed?post=${encodeURIComponent(post)}`)
-checkHtml(thread)
+checkHtml(thread, true)
 assert.match(thread.text, /Hello[\s\S]*<h2>Replies<\/h2>[\s\S]*Reply from another author/)
 assert.equal((await get('/feed?post=invalid')).status, 404)
 assert.equal((await get(`/feed?post=${encodeURIComponent(author)}`)).status, 404)

Git ยท Social feed