Run a browser test with the chat API on a different origin than the page
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
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.mjslisten on a second port (E2E_API_PORT, default 4174) that serves onlyPOST /api/chatandOPTIONS /api/chat, using the same mock replies as now. - On that port, answer
OPTIONSexactly like a 0.5 server does:204,Access-Control-Allow-Origin: *,Access-Control-Allow-Methods: POST, OPTIONS,Access-Control-Allow-Headers: Content-Type. PutAccess-Control-Allow-Origin: *on thePOSTreplies too. - Add
e2e/fixtures/cross-origin.html, the same asindex.htmlbut withdata-api-urlpointing athttp://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 JSONPOSTalways needs one), for example by countingOPTIONSrequests in the mock and reading the count from the test. - Start both ports from the existing
webServerentry ine2e/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 e2epasses, including the new spec - If you change the mock so
Access-Control-Allow-Headersis 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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 13
- Forks
- 7
- Ø Merge
- 3 Std. 33 Min.
- Gemergte PRs (30 T.)
- 176
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus codercops/chatcops
-
Add startup checks that catch weak or leaked security settingsEvtl. vergeben @varun-pahuja hat das vor 3 Tagen übernommen. Offenenhancement good first issue hacktoberfest server
codercops/chatcops#231 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Type-check the TypeScript samples in the docsEvtl. vergeben @An16og hat das vor 2 Tagen übernommen. Offendocumentation hacktoberfest help wanted testing
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 70/100
codercops/chatcops#201 · 7 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
hacktoberfest
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 35/100
Maintainer antworten meist innerhalb von 1 Tag
-
Add built-in translations to the widgetEvtl. vergeben @piyusshhjangid hat das vor 1 Tag übernommen. Offenhelp wanted widget
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
codercops/chatcops#55 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in codercops/chatcops
Ähnliche Issues
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 82/100
source-cooperative/docs.source.coop#41 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Nimblesite/SharpLsp#468 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
solidjs-community/solid-primitives#1082 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag