Skip to content
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

Use a custom esm cache for coverage testing. #6

Merged
merged 3 commits into from
Dec 21, 2021
Merged

Conversation

davidlehn
Copy link
Member

This replaces #4 as a way to fix coverage testing. c8 may still be an option, but this patch is to fix the underlying esm issue.

This fix sets a custom esm cache directory when running coverage testing. Without a fix like this, mixed running of regular testing and coverage testing can result in incorrect coverage results.

This pattern may end up applying to many other packages. Please test and suggest improvements.

Copy link
Member

@dlongley dlongley left a comment

Choose a reason for hiding this comment

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

We already chatted about this quite a bit offline. LGTM.

@@ -4,8 +4,8 @@
"private": true,
"scripts": {
"test": "node --preserve-symlinks test.js test",
"coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm test",
"coverage-ci": "cross-env NODE_ENV=test nyc --reporter=lcov npm test",
"coverage": "cross-env NODE_ENV=test ESM_OPTIONS='{cache:\"node_modules/.cache/esm-coverage\"}' nyc --reporter=lcov --reporter=text-summary npm test",
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, can this be part of the package.json or other .npmFOO thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to make this more DRY, but I wasn't sure how that didn't add complexity. We only want ESM_OPTIONS set for coverage commands, so any sort of global config doesn't seem like it would work. I had tried a cross-env-shell version that had a single common command and passed args to it, but that seemed more complex. I pushed a patch to change to disable the cache. Perhaps in the future esm can be fixed or ESM_DISABLE_CACHE=true will work for this use case.

@davidlehn
Copy link
Member Author

For anyone testing, you may need to remove ./node_modules/.cache/ and ./test/node_modules/.cache/ first to avoid old cached esm data.

Copy link
Contributor

@JSAssassin JSAssassin left a comment

Choose a reason for hiding this comment

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

Tested and it works.

@codecov-commenter
Copy link

codecov-commenter commented Dec 10, 2021

Codecov Report

Merging #6 (c08a686) into main (c898c24) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main       #6   +/-   ##
=======================================
  Coverage   93.33%   93.33%           
=======================================
  Files           4        4           
  Lines          75       75           
=======================================
  Hits           70       70           
  Misses          5        5           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c898c24...c08a686. Read the comment docs.

Copy link
Member

@dlongley dlongley left a comment

Choose a reason for hiding this comment

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

I'm also fine with this approach.

- Disabling the esm cache was a preferred fix rather than than more
  verbose setting of a cache directory.
- This also may ease the transition to ESM_DISABLE_CACHE if that becomes
  more functional for this use case.
@davidlehn davidlehn merged commit 4f119e9 into main Dec 21, 2021
@davidlehn davidlehn deleted the fix-coverage branch December 21, 2021 03:08
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.

5 participants