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

chore(tests): remove import of npmlog in test to fix Vitest error #796

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

ghiscoding
Copy link
Member

Description

Updating Vitest to latest brought a Vitest error with imported mocked module

Motivation and Context

We should not import a Vitest module that is mocked in a setup file because that will throw an error as shown below

FAIL  packages/filter-packages/src/__tests__/get-filtered-packages.spec.ts [ packages/filter-packages/src/__tests__/get-filtered-packages.spec.ts ]
Error: [vitest] Cannot mock "npmlog" because it is already loaded. Did you import it in a setup file?

Please, remove the import if you want static imports to be mocked, or clear module cache by calling "vi.resetModules()" before mocking if you are going to import the file again. See: https://vitest.dev/guide/common-errors.html#cannot-mock-mocked-file.js-because-it-is-already-loaded
 ❯ packages/filter-packages/src/__tests__/get-filtered-packages.spec.ts:21:25

How Has This Been Tested?

Types of changes

  • Chore (change that has absolutely no effect on users)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (549abfa) 98.09% compared to head (375dd1a) 98.09%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #796   +/-   ##
=======================================
  Coverage   98.09%   98.09%           
=======================================
  Files         157      157           
  Lines       11549    11549           
  Branches     1897     1897           
=======================================
  Hits        11328    11328           
  Misses        220      220           
  Partials        1        1           

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

@ghiscoding ghiscoding merged commit bbf4c7f into main Jan 4, 2024
6 checks passed
@ghiscoding ghiscoding deleted the bugfix/vitest-hoisted-npmlog-setup branch January 4, 2024 19:33
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.

None yet

1 participant