Add tests for the service worker's restoreTabs

Open
#30 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Vamsi-2581 is already working on this.

Since Nov 1, 2026.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
testing

Research direction

Start with restoreTabs in background/service_worker.js (lines 322-348) and the RESTORE_TABS handler near line 137, then read loadServiceWorkerFunction in tests/storage.test.js (lines 183-203) to see how the sandbox chrome object is built. Extend that loader to accept extra tabs and windows stubs, record calls, and assert on openedIds, failedIds and the window each tab lands in, covering mixed safe/unsafe URLs, newWindow, a rejected create, and empty input. Done when those cases pass under npm test without changing service_worker.js.

Written by the indexing model from the issue text.

Description

good first issue tests

Problem
restoreTabs decides which tabs the dashboard deletes after a restore: only openedIds are removed. It has no unit test, so a change that marks failed tabs as opened would delete tabs that never reopened.

Where to look

  • background/service_worker.js:322-348, restoreTabs:
    • Unsafe URLs and null entries go to failedIds. A null tab pushes undefined (line 332).
    • The newWindow option overrides the restoreInNewWindow setting.
    • Only the first tab creates a window.
    • A rejected chrome.tabs.create doesn't stop the loop.
  • background/service_worker.js:137-138: the RESTORE_TABS message handler.
  • tests/storage.test.js:183-203, loadServiceWorkerFunction: its sandbox chrome has no windows.create or tabs.create yet.

Suggested approach

  • Let loadServiceWorkerFunction accept extra chrome stubs, for example loadServiceWorkerFunction(name, { tabs: {...}, windows: {...} }).
  • Record calls in the stubs and assert on openedIds, failedIds and which window each tab opened in.
  • Cover: mixed safe and unsafe URLs; newWindow: true opening one window and adding the rest to it; one create that rejects; an empty or non-array input.

Done when

  • The cases above are covered without changing service_worker.js.
  • npm test passes.

New to Pinfold? See CONTRIBUTING.md for setup and tests. Please comment here to claim this issue before you start, and wait to be assigned, so two people don't do the same work. Good first issues are meant for newcomers, so please take one at a time.

Dominant language
JavaScript
Stars
1
Forks
2
Avg merge
9h 33m
Merged PRs (30d)
29

Getting set up

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.

More from Tektrix/pinfold

All issues in Tektrix/pinfold

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.