Skip to content

test: mock adobe api responses#819

Merged
danielroe merged 1 commit into
mainfrom
test/adobe-provider-flake
Apr 27, 2026
Merged

test: mock adobe api responses#819
danielroe merged 1 commit into
mainfrom
test/adobe-provider-flake

Conversation

@danielroe
Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

this aims to make suite less flaky in ecosystem-ci

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 27, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/fonts@819

commit: 65bf33a

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying fonts with  Cloudflare Pages  Cloudflare Pages

Latest commit: 65bf33a
Status: ✅  Deploy successful!
Preview URL: https://48e3afb8.fonts-dsw.pages.dev
Branch Preview URL: https://test-adobe-provider-flake.fonts-dsw.pages.dev

View logs

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.47%. Comparing base (8154aa6) to head (65bf33a).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #819   +/-   ##
=======================================
  Coverage   68.47%   68.47%           
=======================================
  Files           9        9           
  Lines         295      295           
  Branches       67       67           
=======================================
  Hits          202      202           
  Misses         75       75           
  Partials       18       18           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

This pull request introduces test infrastructure for mocking Adobe Typekit font API interactions. A new fixture module exports mockAdobeFetch(), which replaces globalThis.fetch to intercept requests to Typekit endpoints and return fixture-backed responses. The mock handles JSON kit definitions, CSS font declarations, and WOFF2 stub requests. Accompanying fixture files provide sample CSS font-face definitions and JSON kit metadata. The test setup is updated to initialize the mock before running tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main change: mocking Adobe API responses in tests to reduce flakiness.
Description check ✅ Passed The description is related to the changeset, explaining the purpose (reducing flakiness) though it lacks detail about implementation specifics.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/adobe-provider-flake

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
test/fixtures/adobe/index.ts (2)

4-8: Nit: prefer path.join over template-literal path concat.

fileURLToPath(new URL('.', import.meta.url)) returns a trailing-slash path, so the current ${fixtureDir}/${name} produces …/adobe//kit-…json. Linux/macOS tolerate it, but path.join is cleaner and portable.

♻️ Proposed fix
 import { promises as fsp } from 'node:fs'
+import { join } from 'node:path'
 import { fileURLToPath } from 'node:url'

 const fixtureDir = fileURLToPath(new URL('.', import.meta.url))

 async function readFixture(name: string) {
-  return fsp.readFile(`${fixtureDir}/${name}`, 'utf8')
+  return fsp.readFile(join(fixtureDir, name), 'utf8')
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/fixtures/adobe/index.ts` around lines 4 - 8, The readFixture helper
currently concatenates paths using a template literal which can produce
duplicate slashes; update readFixture to use path.join to build the file path
(use the existing fixtureDir from fileURLToPath(new URL('.', import.meta.url))
and join it with name), and add the required import for path (or import { join }
from 'path') so the function becomes fsp.readFile(path.join(fixtureDir, name),
'utf8') — update references to fixtureDir, readFixture, and fileURLToPath
accordingly.

11-30: Make mockAdobeFetch() idempotent and restorable.

Two concerns:

  1. Re-invocation hazard. If mockAdobeFetch() is ever called more than once (e.g. another test file imports it, or a future setup hook), the second call will capture the already-patched globalThis.fetch as realFetch. Non-Typekit fall-through requests then route through the previous mock unnecessarily — and a third call would set up a self-referential chain. Cheap to guard against now.
  2. No teardown. Because the patch is permanent for the worker, any later test that legitimately needs real fetch (or a different mock) inherits this one. Returning a restore handle (or registering afterAll) keeps the surface honest.
♻️ Proposed fix
-/** Replace adobe HTTP calls with shape-only stubs so the suite doesn't depend on `typekit.com`. */
-export function mockAdobeFetch() {
-  const realFetch = globalThis.fetch
-  globalThis.fetch = async function mockedFetch(input, init) {
+/** Replace adobe HTTP calls with shape-only stubs so the suite doesn't depend on `typekit.com`. */
+export function mockAdobeFetch() {
+  const mocked = globalThis.fetch as typeof fetch & { __adobeMock?: true }
+  if (mocked.__adobeMock) return () => {}
+  const realFetch = globalThis.fetch
+  const mockedFetch = async function mockedFetch(input: RequestInfo | URL, init?: RequestInit) {
     const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url
     const kitMeta = url.match(/^https:\/\/typekit\.com\/api\/v1\/json\/kits\/([^/]+)\/published/)
     if (kitMeta) {
       const body = await readFixture(`kit-${kitMeta[1]}.json`)
       return new Response(body, { status: 200, headers: { 'content-type': 'application/json' } })
     }
     const kitCss = url.match(/^https:\/\/use\.typekit\.net\/([^/]+)\.css/)
     if (kitCss) {
       const body = await readFixture(`${kitCss[1]}.css`)
       return new Response(body, { status: 200, headers: { 'content-type': 'text/css' } })
     }
     if (/^https:\/\/use\.typekit\.net\/stub\//.test(url)) {
       return new Response(new Uint8Array(), { status: 200, headers: { 'content-type': 'font/woff2' } })
     }
-    return realFetch(input as RequestInfo, init)
-  } as typeof fetch
-}
+    return realFetch(input as RequestInfo, init)
+  } as typeof fetch & { __adobeMock?: true }
+  mockedFetch.__adobeMock = true
+  globalThis.fetch = mockedFetch
+  return () => { globalThis.fetch = realFetch }
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/fixtures/adobe/index.ts` around lines 11 - 30, The mockAdobeFetch
function should be made idempotent and provide a restore mechanism: detect if
globalThis.fetch is already our mock (use a unique marker like a Symbol or a
hidden property on the wrapper) and if so, do nothing (or return the existing
restore function); when first invoked capture the realFetch from the true
original fetch, install the mockedFetch (attach the marker and a restore
function that sets globalThis.fetch back to realFetch and clears the marker),
and return that restore function; also optionally register that restore with the
test framework (e.g. call afterAll to invoke the restore) so the mock is torn
down automatically. Ensure references to mockAdobeFetch, realFetch,
globalThis.fetch and the mockedFetch wrapper are used to locate and implement
this change.
test/fixtures/adobe/grx7wdj.css (1)

1-11: Exclude test/fixtures/adobe/ from stylelint.

These fixtures intentionally mirror Adobe Typekit’s actual output (which quotes font-family), so the font-family-name-quotes errors flagged by Stylelint here (and in test/fixtures/adobe/sij5ufr.css at the same lines) are noise — “fixing” them would make the fixtures diverge from what the real provider returns. Add an ignore entry rather than per-file disable comments so future fixtures stay clean.

♻️ Suggested change to `.stylelintignore` (or `ignoreFiles` in your stylelint config)
+test/fixtures/adobe/**/*.css
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/fixtures/adobe/grx7wdj.css` around lines 1 - 11, Add an ignore entry to
the Stylelint config (either .stylelintignore or "ignoreFiles") to exclude the
Adobe fixtures directory so Stylelint won't flag the intentionally quoted
font-family values (e.g., font-family:"barlow-semi-condensed" found in the Adobe
fixture CSS and the other fixture with the same issue) for the rule
font-family-name-quotes; update the ignore pattern to cover the Adobe fixtures
folder so future provider-mirroring files are not modified or annotated with
per-file disables.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/fixtures/adobe/grx7wdj.css`:
- Around line 1-11: Add an ignore entry to the Stylelint config (either
.stylelintignore or "ignoreFiles") to exclude the Adobe fixtures directory so
Stylelint won't flag the intentionally quoted font-family values (e.g.,
font-family:"barlow-semi-condensed" found in the Adobe fixture CSS and the other
fixture with the same issue) for the rule font-family-name-quotes; update the
ignore pattern to cover the Adobe fixtures folder so future provider-mirroring
files are not modified or annotated with per-file disables.

In `@test/fixtures/adobe/index.ts`:
- Around line 4-8: The readFixture helper currently concatenates paths using a
template literal which can produce duplicate slashes; update readFixture to use
path.join to build the file path (use the existing fixtureDir from
fileURLToPath(new URL('.', import.meta.url)) and join it with name), and add the
required import for path (or import { join } from 'path') so the function
becomes fsp.readFile(path.join(fixtureDir, name), 'utf8') — update references to
fixtureDir, readFixture, and fileURLToPath accordingly.
- Around line 11-30: The mockAdobeFetch function should be made idempotent and
provide a restore mechanism: detect if globalThis.fetch is already our mock (use
a unique marker like a Symbol or a hidden property on the wrapper) and if so, do
nothing (or return the existing restore function); when first invoked capture
the realFetch from the true original fetch, install the mockedFetch (attach the
marker and a restore function that sets globalThis.fetch back to realFetch and
clears the marker), and return that restore function; also optionally register
that restore with the test framework (e.g. call afterAll to invoke the restore)
so the mock is torn down automatically. Ensure references to mockAdobeFetch,
realFetch, globalThis.fetch and the mockedFetch wrapper are used to locate and
implement this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 117d0ec7-8db4-4ac5-930e-26a94f849bdb

📥 Commits

Reviewing files that changed from the base of the PR and between ab38ef1 and 65bf33a.

📒 Files selected for processing (6)
  • test/basic.test.ts
  • test/fixtures/adobe/grx7wdj.css
  • test/fixtures/adobe/index.ts
  • test/fixtures/adobe/kit-grx7wdj.json
  • test/fixtures/adobe/kit-sij5ufr.json
  • test/fixtures/adobe/sij5ufr.css

@danielroe danielroe merged commit 9d4ada4 into main Apr 27, 2026
10 checks passed
@danielroe danielroe deleted the test/adobe-provider-flake branch April 27, 2026 13:17
@github-actions github-actions Bot mentioned this pull request Apr 27, 2026
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.

2 participants