Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Run a browser test with the chat API on a different origin than the page

已关闭
#233 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@piyusshhjangid 已经在做这个了。

开始于 2026年10月20日。

  • #294 来自 @piyusshhjangid —— 已合并

评估

这个 Issue 还没有评估数据。

描述

enhancement hacktoberfest help wanted testing widget

In the browser tests the page and the mock chat API are on the same origin (e2e/fixtures/index.html, line 14, uses data-api-url="/api/chat"), so the browser never sends a CORS preflight. Real sites are almost always cross-origin: the page is on acme.com and the chat server is on api.acme.com or a Vercel URL. If the widget ever adds a request header that older servers don't allow, those sites break and our tests stay green. The next release changes the request format, so I want this test in place first.

What to do

  • Make e2e/server.mjs listen on a second port (E2E_API_PORT, default 4174) that serves only POST /api/chat and OPTIONS /api/chat, using the same mock replies as now.
  • On that port, answer OPTIONS exactly like a 0.5 server does: 204, Access-Control-Allow-Origin: *, Access-Control-Allow-Methods: POST, OPTIONS, Access-Control-Allow-Headers: Content-Type. Put Access-Control-Allow-Origin: * on the POST replies too.
  • Add e2e/fixtures/cross-origin.html, the same as index.html but with data-api-url pointing at http://localhost:4174/api/chat.
  • Add e2e/tests/cross-origin.spec.ts: open the page, send a message, and check that the streamed reply shows up. Also check that the browser sent a preflight first (a JSON POST always needs one), for example by counting OPTIONS requests in the mock and reading the count from the test.
  • Start both ports from the existing webServer entry in e2e/playwright.config.ts.

Where to look

  • e2e/server.mjs, e2e/playwright.config.ts, e2e/tests/widget.spec.ts
  • CONTRIBUTING.md, "Browser tests"

Acceptance criteria

  • pnpm e2e passes, including the new spec
  • If you change the mock so Access-Control-Allow-Headers is empty, the new test fails (try it, and say so in the PR)
  • The existing specs still pass and still use the same-origin page
  • No changeset needed (pnpm changeset --empty)

Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #<this issue number>. Setup notes (pnpm, build before test) are in CONTRIBUTING.md.

主要语言
TypeScript
星标
13
派生
7
平均合并
3 小时 33 分钟
30 天内合并 PR
176

环境准备

从这里开始

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

codercops/chatcops 的其他 Issue

查看 codercops/chatcops 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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