Skip to content

fix test coverage#156

Merged
auniverseaway merged 1 commit into
mainfrom
fix-test-coverage
Jul 22, 2025
Merged

fix test coverage#156
auniverseaway merged 1 commit into
mainfrom
fix-test-coverage

Conversation

@hannessolo

Copy link
Copy Markdown
Contributor

There is a bug with c8 and esmock that breaks test coverage when mocking a global like:

await esmock('some-module.js', {}, {
  import: {
    fetch: mockFetch
  }
});

Instead, we should use:

async function withMockedFetch(act) {
  const savedFetch = globalThis.fetch;
  globalThis.fetch = fetch;
  try {
    await act();
  } finally {
    globalThis.fetch = savedFetch;
  }
}

@codecov

codecov Bot commented Jul 21, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.71%. Comparing base (78a68cf) to head (4d2f753).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #156       +/-   ##
===========================================
+ Coverage   76.23%   86.71%   +10.47%     
===========================================
  Files          39       39               
  Lines        2243     2243               
===========================================
+ Hits         1710     1945      +235     
+ Misses        533      298      -235     

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

@auniverseaway
auniverseaway merged commit 28fb718 into main Jul 22, 2025
5 checks passed
@auniverseaway
auniverseaway deleted the fix-test-coverage branch July 22, 2025 04:15
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.

3 participants