Skip to content

fix(tests): pre-seed Cache API to eliminate live group API dependency#5233

Draft
marcoscaceres wants to merge 5 commits intomainfrom
fix/test-group-cache
Draft

fix(tests): pre-seed Cache API to eliminate live group API dependency#5233
marcoscaceres wants to merge 5 commits intomainfrom
fix/test-group-cache

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

Closes #5231

Tests that use group: in their config were hitting the live
respec.org/w3c/groups/ API, making them fragile when groups are
renamed or removed (the autowebplatform BG removal broke the
BG-FINAL style test on all branches).

Adds a generic seedCache() helper that pre-populates the browser
Cache API with fixture data from tests/data/groups.json, so
fetchAndCache() 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.org endpoints
(xref, biblio) — add a fixture JSON and a seedXrefCache() export.

Zero production code changes. 295 tests across 5 affected suites pass.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from tests/data/groups.json.
  • Wire seedGroupCache() into several W3C-focused Jasmine suites via beforeAll(...) 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.

Comment on lines +40 to +52
/**
* 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);
}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/spec/respec-cache-helper.js Outdated
Comment on lines +46 to +49
groupsPromise = fetch("/tests/data/groups.json").then(r => {
if (!r.ok) throw new Error(`Failed to load groups fixture: ${r.status}`);
return r.json();
});
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;
});

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

@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 551e75e:

  1. All test files with group: now call beforeAll(seedGroupCache) — the 5 remaining files (core/exporter-spec.js, core/include-config-spec.js, core/seo-spec.js, core/ui-spec.js, w3c/linter-rules/required-sections-spec.js) were wired up alongside the original W3C spec files.

  2. Rejected-promise retrygroupsPromise is reset to undefined inside a .catch() so a transient fetch failure won't permanently poison the memoized promise.

Nothing left to fix.

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.
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.

Style and group tests break when W3C groups are renamed or removed

3 participants