feat: add a built-output smoke test command (`nuxt preview --smoke`)

未关闭
#1,661 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
bun, node.js, typescript
领域
cli, testing

调研方向

Read the existing nuxt preview command and the described ~550-line Bun smoke script to map how the built server is started and checked. Then trace how the CLI resolves the .output entry and handles environment and signals across runtimes. Done means a smoke command checks HTTP expectations and shutdown, exits nonzero on failure, and leaves no server process running.

由索引模型根据 Issue 内容生成。

描述

nuxt preview starts .output/server/index.mjs, but it does not verify that the built output:

  • boots with the production environment,
  • serves the shell and all required assets/chunks,
  • starts with the intended runtime (Bun or Node),
  • runs Nitro close hooks and exits cleanly on SIGTERM/SIGINT.

nuxt build can pass while the deploy fails at runtime: a missing secret, a wrong database path, a missing asset, a preset regression (for example the Bun preset skipping close hooks), or a shutdown that hangs. We currently maintain a ~550-line smoke script for this.

What our script does:

  • reserves a free port, creates temporary SQLite databases, and applies migrations;
  • builds a minimal environment instead of inheriting the developer .env;
  • spawns .output/server/index.mjs with Bun;
  • waits for HTTP 200 and a known shell marker, and scans captured logs for forbidden content;
  • sends SIGTERM, asserts exit within 15 seconds and clean shutdown; on Windows it records that Bun's SIGTERM is termination-only;
  • is the last step of check -> build -> built-output Playwright -> smoke.

Proposal: nuxt preview --smoke (or nuxt build --smoke) with:

  • --url / --expect for a path plus expected status and optional body marker;
  • --timeout and --signal;
  • --env-file or --env for a minimal production environment;
  • an assertion that the process exits after the signal, optionally checking a close-hook marker;
  • a non-zero exit on failure, and no server process left behind;
  • support for the current runtime and .output layout without hard-coding Nitro internals.

What exists today:

  • nuxt preview starts the server but makes no assertions.
  • @nuxt/test-utils is excellent for tests that call the server, but it does not own the built process lifecycle or shutdown assertions.
  • Nitro close hooks are usually tested manually or with a custom script.

This could be a module, but a CLI command is the right home because it must know the output entry, environment loading and signal semantics. Happy to contribute the command or a shared helper. Our script is Bun-specific today; cross-platform signal handling is the main design work.

Additional information
  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?
主要语言
TypeScript
星标
402
派生
125
平均合并
2 天 9 小时
30 天内合并 PR
37

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nuxt/cli 的其他 Issue

查看 nuxt/cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。