-
-
Notifications
You must be signed in to change notification settings - Fork 422
fix(tests): pre-seed Cache API to eliminate live group API dependency #5233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
marcoscaceres
wants to merge
5
commits into
main
Choose a base branch
from
fix/test-group-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3c3cc5
fix(tests): pre-seed Cache API to eliminate live group API dependency
marcoscaceres 3eaf879
fix(tests): guard typeof object check against null in seedCache
marcoscaceres b64cff5
fix(tests): check response.ok before parsing groups fixture JSON
marcoscaceres 6b9f542
fix(tests): add seedGroupCache to all remaining test files using group:
marcoscaceres c1c1fe8
fix(tests): fix sort-imports order in required-sections-spec
marcoscaceres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| { | ||
| "https://respec.org/w3c/groups/css/": { | ||
| "body": { | ||
| "shortname": "css", | ||
| "type": "wg", | ||
| "id": 32061, | ||
| "name": "Cascading Style Sheets (CSS) Working Group", | ||
| "URI": "https://www.w3.org/groups/wg/css/", | ||
| "patentURI": "https://www.w3.org/groups/wg/css/ipr", | ||
| "patentPolicy": "PP2020", | ||
| "wgURI": "https://www.w3.org/groups/wg/css" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/maps4html/": { | ||
| "body": { | ||
| "shortname": "maps4html", | ||
| "type": "cg", | ||
| "id": 70543, | ||
| "name": "Maps For HTML Community Group", | ||
| "URI": "https://www.w3.org/community/maps4html/", | ||
| "wgURI": "https://www.w3.org/groups/cg/maps4html" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/payments/": { | ||
| "body": { | ||
| "shortname": "payments", | ||
| "type": "wg", | ||
| "id": 83744, | ||
| "name": "Web Payments Working Group", | ||
| "URI": "https://www.w3.org/groups/wg/payments/", | ||
| "patentURI": "https://www.w3.org/groups/wg/payments/ipr", | ||
| "patentPolicy": "PP2020", | ||
| "wgURI": "https://www.w3.org/groups/wg/payments" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/publishingbg/": { | ||
| "body": { | ||
| "shortname": "publishingbg", | ||
| "type": "bg", | ||
| "id": 97159, | ||
| "name": "Publishing Business Group", | ||
| "URI": "https://www.w3.org/community/publishingbg/", | ||
| "wgURI": "https://www.w3.org/groups/bg/publishingbg" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/tag/": { | ||
| "body": { | ||
| "shortname": "tag", | ||
| "type": "other", | ||
| "id": 34270, | ||
| "name": "Technical Architecture Group", | ||
| "URI": "https://www.w3.org/2001/tag/", | ||
| "wgURI": "https://www.w3.org/groups/other/tag" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/webapps/": { | ||
| "body": { | ||
| "shortname": "webapps", | ||
| "type": "wg", | ||
| "id": 114929, | ||
| "name": "Web Applications Working Group", | ||
| "URI": "https://www.w3.org/groups/wg/webapps/", | ||
| "patentURI": "https://www.w3.org/groups/wg/webapps/ipr", | ||
| "patentPolicy": "PP2020", | ||
| "wgURI": "https://www.w3.org/groups/wg/webapps" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/webperf/": { | ||
| "body": { | ||
| "shortname": "webperf", | ||
| "type": "wg", | ||
| "id": 45211, | ||
| "name": "Web Performance Working Group", | ||
| "URI": "https://www.w3.org/groups/wg/webperf/", | ||
| "patentURI": "https://www.w3.org/groups/wg/webperf/ipr", | ||
| "patentPolicy": "PP2020", | ||
| "wgURI": "https://www.w3.org/groups/wg/webperf" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/wicg/": { | ||
| "body": { | ||
| "shortname": "wicg", | ||
| "type": "cg", | ||
| "id": 80485, | ||
| "name": "Web Platform Incubator Community Group", | ||
| "URI": "https://www.w3.org/community/wicg/", | ||
| "wgURI": "https://www.w3.org/groups/cg/wicg" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/wot/wg": { | ||
| "body": { | ||
| "shortname": "wot", | ||
| "type": "wg", | ||
| "id": 95969, | ||
| "name": "Web of Things Working Group", | ||
| "URI": "https://www.w3.org/WoT/wg/", | ||
| "patentURI": "https://www.w3.org/groups/wg/wot/ipr", | ||
| "patentPolicy": "PP2020", | ||
| "wgURI": "https://www.w3.org/groups/wg/wot" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/json-ld/wg": { | ||
| "body": { | ||
| "shortname": "json-ld", | ||
| "type": "wg", | ||
| "id": 107714, | ||
| "name": "JSON-LD Working Group", | ||
| "URI": "https://www.w3.org/groups/wg/json-ld/", | ||
| "patentURI": "https://www.w3.org/groups/wg/json-ld/ipr", | ||
| "patentPolicy": "PP2020", | ||
| "wgURI": "https://www.w3.org/groups/wg/json-ld" | ||
| } | ||
| }, | ||
| "https://respec.org/w3c/groups/wot/": { | ||
| "status": 409, | ||
| "body": "Multiple groups with shortname: \"wot\".\nPlease use either: \"cg/wot\", \"ig/wot\", \"wg/wot\"." | ||
| }, | ||
| "https://respec.org/w3c/groups/404/": { | ||
| "status": 404, | ||
| "body": "No group with shortname: \"404\"." | ||
| }, | ||
| "https://respec.org/w3c/groups/not%20a%20real%20group/": { | ||
| "status": 404, | ||
| "body": "No group with shortname: \"not a real group\"." | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| "use strict"; | ||
|
|
||
| const WEEK = 7 * 24 * 60 * 60 * 1000; | ||
|
|
||
| /** | ||
| * Pre-seeds the browser Cache API so fetchAndCache() returns cached | ||
| * data without hitting the network. Works for any respec.org endpoint. | ||
| * | ||
| * @param {Record<string, {status?: number, body: any}>} entries | ||
| * Keys are full URLs, values have optional status (default 200) | ||
| * and a body (object for JSON, string for text). | ||
| */ | ||
| export async function seedCache(entries) { | ||
| const byOrigin = new Map(); | ||
| for (const [url, entry] of Object.entries(entries)) { | ||
| const origin = new URL(url).origin; | ||
| if (!byOrigin.has(origin)) byOrigin.set(origin, []); | ||
| byOrigin.get(origin).push([url, entry]); | ||
| } | ||
| const expires = new Date(Date.now() + WEEK).toISOString(); | ||
| for (const [origin, urls] of byOrigin) { | ||
| const cache = await caches.open(origin); | ||
| for (const [url, { status = 200, body }] of urls) { | ||
| const isJSON = body !== null && typeof body === "object"; | ||
| const headers = { | ||
| "Content-Type": isJSON ? "application/json" : "text/plain", | ||
| Expires: expires, | ||
| }; | ||
| const responseBody = isJSON ? JSON.stringify(body) : body; | ||
| await cache.put( | ||
| new Request(url), | ||
| new Response(responseBody, { status, headers }) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let groupsPromise; | ||
|
|
||
| /** | ||
| * 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(); | ||
| }) | ||
| .catch(err => { | ||
| groupsPromise = undefined; | ||
| throw err; | ||
| }); | ||
| } | ||
| await seedCache(await groupsPromise); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 livehttps://respec.org/w3c/groups/API, butseedGroupCache()is only being wired into a subset of suites (the W3C ones in this PR). There are other spec files (e.g., undertests/spec/core/andtests/spec/w3c/linter-rules/) that still setgroup:and will continue to hit the network when run in isolation (e.g., via--grep). Consider either addingbeforeAll(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 551e75e — added
seedGroupCacheto all 5 remaining test files that usegroup:in their config:core/exporter-spec.js,core/include-config-spec.js,core/seo-spec.js,core/ui-spec.js, andw3c/linter-rules/required-sections-spec.js.