fix(tests): pre-seed Cache API to eliminate live group API dependency#5233
fix(tests): pre-seed Cache API to eliminate live group API dependency#5233marcoscaceres wants to merge 5 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make browser-based spec tests hermetic by removing their dependency on the live https://respec.org/w3c/groups/ API when group: is used in ReSpec config, by pre-seeding the Cache API with fixture responses.
Changes:
- Add a reusable
seedCache()/seedGroupCache()helper to pre-populate Cache API entries fromtests/data/groups.json. - Wire
seedGroupCache()into several W3C-focused Jasmine suites viabeforeAll(...)to avoid live group lookups. - Update Karma spec config to ensure the new helper module is served to the browser test runner.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/spec/w3c/style-spec.js | Seeds group cache before running style-related W3C tests that set group:. |
| tests/spec/w3c/seo-spec.js | Seeds group cache before SEO tests to prevent live group API calls. |
| tests/spec/w3c/headers-spec.js | Seeds group cache once for the headers suite (many cases use group:). |
| tests/spec/w3c/group-spec.js | Seeds group cache before group module tests to avoid network dependency. |
| tests/spec/w3c/defaults-spec.js | Seeds group cache before defaults tests that use group:. |
| tests/spec/respec-cache-helper.js | Introduces Cache API seeding utilities and a group-specific seeder backed by fixture JSON. |
| tests/spec/karma.conf.cjs | Serves the new helper module to Karma as an ES module. |
| tests/data/groups.json | Adds fixture responses for the W3C group API (success + error cases). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Seeds the cache with W3C group API responses from tests/data/groups.json. | ||
| * Call from beforeAll() in any test file that uses group: in its config. | ||
| */ | ||
| export async function seedGroupCache() { | ||
| if (!groupsPromise) { | ||
| groupsPromise = fetch("/tests/data/groups.json").then(r => { | ||
| if (!r.ok) throw new Error(`Failed to load groups fixture: ${r.status}`); | ||
| return r.json(); | ||
| }); | ||
| } | ||
| await seedCache(await groupsPromise); | ||
| } |
There was a problem hiding this comment.
The PR description suggests all tests using group: no longer depend on the live https://respec.org/w3c/groups/ API, but seedGroupCache() is only being wired into a subset of suites (the W3C ones in this PR). There are other spec files (e.g., under tests/spec/core/ and tests/spec/w3c/linter-rules/) that still set group: and will continue to hit the network when run in isolation (e.g., via --grep). Consider either adding beforeAll(seedGroupCache) to those suites too, or centralizing the seeding in shared test setup (e.g., SpecHelper/test-main) so individual suites can’t forget it.
There was a problem hiding this comment.
Fixed in 551e75e — added seedGroupCache to all 5 remaining test files that use group: in their config: core/exporter-spec.js, core/include-config-spec.js, core/seo-spec.js, core/ui-spec.js, and w3c/linter-rules/required-sections-spec.js.
| groupsPromise = fetch("/tests/data/groups.json").then(r => { | ||
| if (!r.ok) throw new Error(`Failed to load groups fixture: ${r.status}`); | ||
| return r.json(); | ||
| }); |
There was a problem hiding this comment.
groupsPromise memoizes the fixture fetch permanently. If the initial fetch rejects (transient Karma/proxy issue), subsequent calls will keep reusing the rejected promise and you won’t get a retry. Consider resetting groupsPromise back to undefined/null in a .catch() (or wrapping in try/catch) so a later call can retry loading the fixture.
| groupsPromise = fetch("/tests/data/groups.json").then(r => { | |
| if (!r.ok) throw new Error(`Failed to load groups fixture: ${r.status}`); | |
| return r.json(); | |
| }); | |
| groupsPromise = fetch("/tests/data/groups.json") | |
| .then(r => { | |
| if (!r.ok) throw new Error(`Failed to load groups fixture: ${r.status}`); | |
| return r.json(); | |
| }) | |
| .catch(err => { | |
| groupsPromise = undefined; | |
| throw err; | |
| }); |
There was a problem hiding this comment.
Fixed in 551e75e — added .catch() that resets groupsPromise to undefined on failure, so subsequent calls can retry the fetch instead of reusing the rejected promise.
|
@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed? |
Both review items are fully addressed in commit
Nothing left to fix. |
551e75e to
416cee5
Compare
Closes #5231 Tests that use group: in their config were hitting the live respec.org/w3c/groups/ API, breaking when groups were renamed or removed (e.g., autowebplatform BG removal broke BG-FINAL style test). Add a generic cache seeding helper (respec-cache-helper.js) that pre-populates the browser Cache API with fixture data from tests/data/groups.json. The fetchAndCache() function finds the cached responses and returns them without making network requests. The helper is designed to be reusable — when xref or biblio tests need the same treatment, add a fixture JSON and a seedXrefCache() export.
typeof null === "object" in JavaScript, so the isJSON check would incorrectly treat null bodies as JSON. Add explicit null guard.
A 404 from the karma server would produce an opaque JSON parse error instead of a clear "failed to load fixture" message.
Addresses Copilot review feedback — 5 additional test files (exporter, include-config, core/seo, ui, required-sections) also use group: in their config but were missing the cache seeding. Also resets groupsPromise on fetch failure so subsequent calls can retry.
416cee5 to
6b9f542
Compare
Closes #5231
Tests that use
group:in their config were hitting the liverespec.org/w3c/groups/API, making them fragile when groups arerenamed or removed (the
autowebplatformBG removal broke theBG-FINALstyle test on all branches).Adds a generic
seedCache()helper that pre-populates the browserCache API with fixture data from
tests/data/groups.json, sofetchAndCache()finds cached responses and never hits the network.Each affected test file adds a single
beforeAll(seedGroupCache)call.The helper is designed to be reusable for other
respec.orgendpoints(xref, biblio) — add a fixture JSON and a
seedXrefCache()export.Zero production code changes. 295 tests across 5 affected suites pass.