Skip to content

Fix/service worker installation#76

Merged
kevinccbsg merged 6 commits into
mainfrom
fix/service-worker-installation
Nov 1, 2025
Merged

Fix/service worker installation#76
kevinccbsg merged 6 commits into
mainfrom
fix/service-worker-installation

Conversation

@kevinccbsg

Copy link
Copy Markdown
Member

This pull request introduces improvements to the mock service worker infrastructure, focusing on version management, file extension handling, and test coverage. The main goals are to ensure smoother service worker updates, improve file-matching robustness (especially with query parameters), and provide more reliable and comprehensive testing.

Key changes include:

Service Worker Version Management

  • Introduced a TWD_VERSION constant to centralize the version number for the mock service worker and ensure consistent versioning across the codebase. Service worker registration now includes the version in the query string, and localStorage is used to track and update the service worker version as needed. Old service workers are unregistered when a version change is detected, and the code waits for the service worker to take control before proceeding. (src/constants/version.js, src/constants/version.ts, src/commands/mockBridge.ts, src/cli/mock-sw.js, [1] [2] [3] [4] [5] [6] [7]

  • The service worker now logs its version dynamically using the new constant, and the install/activate lifecycle events are handled to ensure immediate activation and control. (src/cli/mock-sw.js, src/cli/mock-sw.jsR85-R94)

Improved File Extension Handling

  • Updated the logic for detecting file extensions in URLs to handle cases with query parameters (for example, /api.twd.test.ts?t=12345), ensuring that file matching works correctly even when query strings are present. This change is reflected in both the main code and the distributed service worker files. (src/cli/utils/findRule.js, examples/tutorial-example/public/mock-sw.js, examples/twd-test-app/public/mock-sw.js, [1] [2]

Test Enhancements

  • Expanded and improved tests for service worker registration, version upgrades, and file extension handling. Tests now cover scenarios such as first-time installs, version updates, waiting for service worker control, and correct rule execution. Mocks for service worker APIs have been enhanced for more realistic simulation. (src/tests/commands/mockBridge/initMocking.spec.ts, src/tests/cli/findRule.spec.js, [1] [2] [3] [4] [5]

Documentation/Deployment

This closes #74

@kevinccbsg kevinccbsg merged commit b374c41 into main Nov 1, 2025
4 checks passed
@kevinccbsg kevinccbsg deleted the fix/service-worker-installation branch November 1, 2025 18:50
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.

[bug] weird behaviour when running SW for the first time and when we update version

1 participant