測試:檢查 html 內嵌與瀏覽器用的 JavaScript 語法 #42

Merged
walkdoggo.yeh merged 1 commits from html-syntax-test into main 2026-11-25 08:38:24 +00:00
Owner

為什麼

看板大半的邏輯寫在 index.html 的 inline script 裡(二十幾萬字元),只有瀏覽器會執行。node --test 不會碰它,所以語法打壞了 CI 照樣綠燈,網站卻整頁空白。

今天做 CODA 分配規則介面時就寫錯了一個反引號,是我手動檢查才抓到的。這個測試把那道手動檢查變成自動的。

做了什麼

新增 tests/html-scripts.test.mjs:

  • 把 index.html、my.html、permissions.html、archive.html 每一段 inline script 交給 V8 解析(node:vm 的 Script,只解析不執行)。
  • 另外解析三支瀏覽器用的 calc-core.js、scope-ui.js、i18n.js。
  • 如果哪天出現有 type 屬性的 script(module 或 JSON),測試會明確失敗並要求先更新測試,而不是默默跳過。
  • 找不到任何 inline script 也會失敗,避免選取條件失效之後測試變成空轉。

只檢查語法,不檢查邏輯。但語法錯誤正是會讓整個看板掛掉的那一類。

🤖 Generated with Claude Code

https://claude.ai/code/session_01VDJVpPiGiWjJP1yVvvGhzQ

## 為什麼 看板大半的邏輯寫在 `index.html` 的 inline script 裡(二十幾萬字元),只有瀏覽器會執行。`node --test` 不會碰它,所以**語法打壞了 CI 照樣綠燈,網站卻整頁空白**。 今天做 CODA 分配規則介面時就寫錯了一個反引號,是我手動檢查才抓到的。這個測試把那道手動檢查變成自動的。 ## 做了什麼 新增 `tests/html-scripts.test.mjs`: - 把 `index.html`、`my.html`、`permissions.html`、`archive.html` 每一段 inline script 交給 V8 解析(`node:vm` 的 `Script`,只解析不執行)。 - 另外解析三支瀏覽器用的 `calc-core.js`、`scope-ui.js`、`i18n.js`。 - 如果哪天出現有 `type` 屬性的 script(module 或 JSON),測試會明確失敗並要求先更新測試,而不是默默跳過。 - 找不到任何 inline script 也會失敗,避免選取條件失效之後測試變成空轉。 只檢查語法,不檢查邏輯。但語法錯誤正是會讓整個看板掛掉的那一類。 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VDJVpPiGiWjJP1yVvvGhzQ
walkdoggo.yeh added 1 commit 2026-11-25 07:22:36 +00:00
測試:檢查 html 內嵌與瀏覽器用的 JavaScript 語法
CI / build (pull_request) Successful in 30s
CI / build (push) Successful in 32s
295250c8e5
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VDJVpPiGiWjJP1yVvvGhzQ
walkdoggo.yeh merged commit aa7ae3e5a0 into main 2026-11-25 08:38:24 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: walkdoggo.yeh/leadboard#42