Skip to content

Legg til vitest browser mode #6429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Legg til vitest browser mode #6429

wants to merge 4 commits into from

Conversation

tor-nav
Copy link
Collaborator

@tor-nav tor-nav commented Jun 10, 2025

mswTest må no brukast for testar som krev msw-handlers. Denne wrappar applyRequestHandlers som blir brukt av jsdom-testar, og setupWorker som må brukast for browser-mode.

Det er rundt 20-30 testar som feilar av ukjent årsak. Mange av desse køyrer ok om ein rekøyrer dei, så usikker på årsak. Håpar det ligg i vitest, men skal få sett meir på det etterkvart. Per no brukar me ikkje browser-mode i CI så det er ikkje krise at nokre testar feilar.

Så får me sjå om browser-mode blir nyttig. Forhåpentlegvis så vil det komme forbedringar i UI'et og kanskje ein bedre integrasjon i storybook. Evt bør me kanskje heller sjå på playwright eller play-funksjonaliteten i storybook

@tor-nav tor-nav requested a review from a team as a code owner June 10, 2025 09:14
@tor-nav tor-nav marked this pull request as draft June 10, 2025 09:14
event.waitUntil(self.clients.claim())
})

self.addEventListener('message', async function (event) {
const clientId = event.source.id
addEventListener('message', async function (event) {

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.

Copilot Autofix

AI 8 days ago

To fix the issue, we need to verify the origin of the incoming message event to ensure it comes from a trusted source. This involves adding a check for the event.origin property against a list of allowed origins. If the origin is not trusted, the handler should return early without processing the message.

The fix will involve:

  1. Defining a list of trusted origins (e.g., const TRUSTED_ORIGINS = ['https://www.example.com'];).
  2. Adding a conditional check at the beginning of the message event handler to verify the event.origin against the trusted origins.
  3. If the origin is not in the trusted list, the handler will return early.

Suggested changeset 1
public/mockServiceWorker.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/public/mockServiceWorker.js b/public/mockServiceWorker.js
--- a/public/mockServiceWorker.js
+++ b/public/mockServiceWorker.js
@@ -23,2 +23,7 @@
 addEventListener('message', async function (event) {
+  const TRUSTED_ORIGINS = ['https://www.example.com'];
+  if (!TRUSTED_ORIGINS.includes(event.origin)) {
+    return;
+  }
+
   const clientId = Reflect.get(event.source || {}, 'id')
EOF
@@ -23,2 +23,7 @@
addEventListener('message', async function (event) {
const TRUSTED_ORIGINS = ['https://www.example.com'];
if (!TRUSTED_ORIGINS.includes(event.origin)) {
return;
}

const clientId = Reflect.get(event.source || {}, 'id')
Copilot is powered by AI and may make mistakes. Always verify output.
@tor-nav tor-nav marked this pull request as ready for review June 13, 2025 09:21
Copy link

@tor-nav tor-nav requested a review from sirimykland June 13, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant