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

.doMock won't mock if called from an imported module #3284

Open
6 tasks done
dearlordylord opened this issue May 2, 2023 · 3 comments
Open
6 tasks done

.doMock won't mock if called from an imported module #3284

dearlordylord opened this issue May 2, 2023 · 3 comments

Comments

@dearlordylord
Copy link

dearlordylord commented May 2, 2023

Describe the bug

If we have a module A and a module B

Where module A has devDependencies of module C and module B

and, if these conditions are true:

  • vi.doMock for module C is called inside module B
  • we're running vitest run in module A
  • and try to import module C after vi.doMock of module B is called

then, callback of vi.doMock never fires, with no error, and import module C returns a real module C

now, if we remove module C from devDependencies of module A, we have vi.doMock called and import module C returns the mocked value

this discrepancy is what makes me think it's a bug or undefined behaviour: I'd expect either both cases fail, or, hopefully, both cases success

Reproduction

https://github.com/Firfi/vittest-base - serves as "module A"

https://github.com/Firfi/vittest-dependency - serves as "module B"

uuid (https://www.npmjs.com/package/uuid) - serves as "module C" (but it's true with every module I tested with)

yarn install in both and link them together with yarn link (in readme) to see the effect

I have the same effect with a published module, therefore I rule out yarn link issues

System Info

  System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1
    Memory: 111.55 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.n/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.5.1 - ~/.n/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Edge: 112.0.1722.68
    Firefox: 109.0.1
    Safari: 16.3

Used Package Manager

yarn

Validations

@sheremet-va
Copy link
Member

sheremet-va commented May 2, 2023

All file resolution is done by Vite - here I assume this is how your package manager resolves it. Also, you provided zero information about your system configuration. What version of yarn? What Node version? Why should I care that you use osx? (I will put a label for reproduction, but I need system info). We provide you with a command to run because we need this information.

@github-actions
Copy link

github-actions bot commented May 2, 2023

Hello @Firfi. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@dearlordylord
Copy link
Author

Thank you for your response @sheremet-va . I overlooked the command npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers indeed! It was in too fine print for how late it is on my side of the globe 😅

I updated the system information, assuming this is what you are trying to tell me.

Thank you again for such a swift response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants