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

refactor(vitest): reimplement hoistMocks to fix incorrect dynamic imports #4664

Merged
merged 18 commits into from
Jan 3, 2024

Conversation

Dunqing
Copy link
Member

@Dunqing Dunqing commented Dec 5, 2023

Description

fix: #4619
fix: #4604
fix: #3300

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Dec 5, 2023

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 5feb4c3
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65953ac636f15b0008759632

packages/browser/rollup.config.js Outdated Show resolved Hide resolved
packages/vitest/src/node/hoistMocks.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/hoistMocks.ts Outdated Show resolved Hide resolved
test/core/test/spy.test.ts Outdated Show resolved Hide resolved
test/core/test/injector-mock.test.ts Show resolved Hide resolved
@Dunqing Dunqing marked this pull request as draft December 7, 2023 11:53
@Dunqing Dunqing marked this pull request as ready for review December 19, 2023 15:52
@sheremet-va
Copy link
Member

I cannot accept this PR without tests. Vitest is a testing framework and the lack of tests for our own features is not a good sign. Initially, this was an experimental feature to test how it works, but now it does more than before. Since it doesn't use Vite's SSR transformer directly, we need to have tests in our repo. You can just copy SSR transformer tests from Vite.

@Dunqing
Copy link
Member Author

Dunqing commented Dec 28, 2023

I cannot accept this PR without tests. Vitest is a testing framework and the lack of tests for our own features is not a good sign. Initially, this was an experimental feature to test how it works, but now it does more than before. Since it doesn't use Vite's SSR transformer directly, we need to have tests in our repo. You can just copy SSR transformer tests from Vite.

Sorry! I finally got what you meant. I will add these tests later

@Dunqing
Copy link
Member Author

Dunqing commented Dec 28, 2023

I added tests and made some changes. Since the hoistMocks must the code has mocks code. so I added some mock code combined with the original code. Please feel free to point out if it's not right!

@sheremet-va sheremet-va merged commit e0b8c54 into vitest-dev:main Jan 3, 2024
18 of 19 checks passed
@sheremet-va
Copy link
Member

@Dunqing this broke tests using imported variables inside the factory: #4872
PR with a failing test at #4873

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