Skip to content

fix test coverage#156

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

fix test coverage#156
auniverseaway merged 1 commit intomainfrom
fix-test-coverage

Conversation

@hannessolo
Copy link
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
Copy link

codecov bot commented Jul 21, 2025

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