| 9 | const STARTUP_TIMEOUT_MS = 500; |
| 10 | |
| 11 | async function withTimeout(promise, label, ms = STARTUP_TIMEOUT_MS) { |
| 12 | let timer; |
| 13 | const guard = new Promise((_, reject) => { |
| 14 | timer = setTimeout(() => reject(new Error(`${label}: startup chain hung > ${ms}ms`)), ms); |
| 15 | }); |
| 16 | try { |
| 17 | return await Promise.race([promise, guard]); |
| 18 | } finally { |
| 19 | clearTimeout(timer); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // Wire chrome.storage.local.get/set against a plain object so each test can |
| 24 | // pre-seed state and observe writes. The default mock in service-worker-env.js |