hono-void
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHono Void Skill
Hono Void Skill
Void builds a Hono app from file-based routes, so there is no entry file and the code does not import . Verify changes with Hono CLI, not with a browser, curl, or a dev server. It runs the app through Vite with no flag and no file argument:
honobash
npm install -D @hono/cli@next
npx hono --help
npx hono routes --exclude /__void # hide Void's internal routes
npx hono request /For a flow (create, then read), use one call with on every step. Send so a page answers with JSON instead of the full HTML. A page action returns 200 even when it fails, so assert on the body ( in is a deep partial match):
npx hono batch -expectx-voidpages: truebodyexpectbash
npx hono batch - <<'EOF'
{"method":"POST","path":"/","headers":{"x-voidpages":"true"},"body":{"shop":""},"expect":{"status":200,"body":{"errors":{"shop":"Enter a shop name"}}}}
{"method":"POST","path":"/","headers":{"x-voidpages":"true"},"body":{"shop":"Hono Ramen"},"expect":{"status":200}}
EOFA create that redirects shows its ; follow it with and then . An array in must match the whole array, so check one item of a list by reading the response, not with . The path, fields, and messages above are an example. Check yours with and one request first.
location"save":{"next":"header:location"}"path":"{{next}}"expectexpectnpx hono routesVoid 基于文件式路由构建 Hono 应用,因此没有入口文件,代码中也不会 import 。请使用 Hono CLI 验证变更,而不是用浏览器、curl 或开发服务器。它通过 Vite 运行应用,无需任何标志和文件参数:
honobash
npm install -D @hono/cli@next
npx hono --help
npx hono routes --exclude /__void # hide Void's internal routes
npx hono request /对于一个流程(先创建,再读取),使用一次 调用,并在每个步骤中带上 。发送 ,这样页面会以 JSON 而非完整 HTML 进行响应。页面操作即使失败也会返回 200,因此应对响应体进行断言( 中的 是深度部分匹配):
npx hono batch -expectx-voidpages: trueexpectbodybash
npx hono batch - <<'EOF'
{"method":"POST","path":"/","headers":{"x-voidpages":"true"},"body":{"shop":""},"expect":{"status":200,"body":{"errors":{"shop":"Enter a shop name"}}}}
{"method":"POST","path":"/","headers":{"x-voidpages":"true"},"body":{"shop":"Hono Ramen"},"expect":{"status":200}}
EOF如果创建操作发生重定向,会显示其 ;用 保存它,然后用 继续请求。 中的数组必须与整个数组匹配,因此要检查列表中的某一项,应读取响应内容,而不是用 。上面的路径、字段和消息仅为示例。请先用 和一次请求检查你自己的应用。
location"save":{"next":"header:location"}"path":"{{next}}"expectexpectnpx hono routesChecking the page in a browser
在浏览器中检查页面
HTTP requests do not run the page's JavaScript, so they miss client-side bugs: a form that keeps its values after a submit, or a redirect that lands on the wrong URL. Check those with . It loads the page in happy-dom, runs its JavaScript, and fills and clicks in order. Install happy-dom first:
npx hono browsebash
npm install -D happy-dom
npx hono browse / --fill "Shop name=Hono Ramen" --click 'button[type=submit]'--fillformsurltextformsconsoleHTTP 请求不会执行页面的 JavaScript,因此会遗漏客户端 bug:例如提交后表单仍保留原值,或重定向跳转到错误的 URL。用 检查这些问题。它在 happy-dom 中加载页面,运行其 JavaScript,并按顺序填写和点击。需要先安装 happy-dom:
npx hono browsebash
npm install -D happy-dom
npx hono browse / --fill "Shop name=Hono Ramen" --click 'button[type=submit]'--fillformsurltextformsconsoleChecking a Void app
检查 Void 应用
- return HTML. Send the header
pages/**to get the page data as JSON:x-voidpages: true.{ component, props, errors, head, ... } - Page actions are POST/PUT/PATCH/DELETE to the page URL. A named action has a suffix, e.g.
?name.POST /ramen/1?delete - A validation failure in a page action returns 200, not 422, with the messages in (
body.errors). A success has no{ field: message }.errors - A foreign header gets 403. Omit
Originor use the app's own origin.Origin - resets the local DB between runs.
npx void db seed --yes
For Void itself (routing, pages, the Void CLI), read Void's docs in .
node_modules/void/docs/- 返回 HTML。发送头部
pages/**可获取 JSON 格式的页面数据:x-voidpages: true。{ component, props, errors, head, ... } - 页面操作是对页面 URL 发起 POST/PUT/PATCH/DELETE 请求。命名操作带有 后缀,例如
?name。POST /ramen/1?delete - 页面操作中的校验失败返回 200 而不是 422,错误消息位于 (
body.errors)。成功时没有{ field: message }。errors - 外部的 头会得到 403。请省略
Origin或使用应用自身的 origin。Origin - 可在多次运行之间重置本地数据库。
npx void db seed --yes
关于 Void 本身(路由、页面、Void CLI),请阅读 中的 Void 文档。
node_modules/void/docs/