vitest-dev / vitest-dev/vitest

Support service worker testing

Open
#4,033 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Clear and concise description of the problem

Service workers are complicated, so having unit tests for them where you can inspect every caching decision can be important.

Currently I'm not familiar with any way to test in a service worker environment with vitest. It would be great if it supported that.

I had a quick go and I got a hard error:

Error: This module can only be imported inside a service worker

I will try look for a workaround, but generally it would be good to have decent support for the service worker use case

Suggested solution

Add service worker environment testing

Alternative

playwright? Though I'm not sure it has good support either + you can't inspect every decision to ensure caches are correctly added / removed in all scenarios

Additional context

No response

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported import error in Vitest when testing a service worker environment. Review the existing environment-testing entry points and determine how service-worker execution and cache decisions should be inspected. Done means service-worker unit tests run without the environment error and the supported behavior is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.