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

fix: normalize moduleCache path #1740

Closed
wants to merge 1 commit into from

Conversation

PatrickChen928
Copy link
Contributor

fix: #1714

This problem is caused by the moduleCache key is not same in setup file and the vue component.
In setup file, the key is /@fs/user/../node_modules/vue-meta/dist/vue-meta.cjs.js, but in the component, is /node_modules/vue-meta/dist/vue-meta.cjs.js.

I'm not sure if this solution is the best, if not, modifications or rewrites are welcome~

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

Can you add a test for this?

@PatrickChen928
Copy link
Contributor Author

Can you add a test for this?

ok. I will do it later.

@jagoncalves14
Copy link

Thanks for this @ChpShy.
I applied your change directly in my node_modules/vitest folder to see if it fixes it — and it did! 👏

@PatrickChen928
Copy link
Contributor Author

I'm confused that I can't reproduce this in vitest test. Maybe someone more familiar with vite and vitest could help with add test? Or I need more time to reproduce it.

@PatrickChen928
Copy link
Contributor Author

It looks like it is caused by pnpm workspace, In workspace package, test success, because vue component also compiled to be /@fs/Users/xxx/node_modules/.pnpm/vue-meta@3.0.0-alpha.10_vue@3.2.37/node_modules/vue-meta/dist/vue-meta.cjs.js.

But in demo project, test failed, because vue component compiled to be /node_modules/.pnpm/vue-meta@3.0.0-alpha.10_vue@3.2.37/node_modules/vue-meta/dist/vue-meta.cjs.js.

And callFunctionMock is private, So, how can I add the test? @sheremet-va

@PatrickChen928
Copy link
Contributor Author

Also, this maybe caused by vite. I'm not sure. Maybe someone can help to provide a reason? Hope for feedback~

@PatrickChen928
Copy link
Contributor Author

because

I also test the different version of vite. It get the same result.

@sheremet-va
Copy link
Member

So, how can I add the test?

You can add a unit test:

const mockMap = {
  ...your mocks
}
const mocker = new Mocker({ ...options })
const result = mocker.request(pathThatFailedBefore)

@PatrickChen928
Copy link
Contributor Author

PatrickChen928 commented Jul 31, 2022

I think this had been solved by pr #1726

line: https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/runtime/mocker.ts#L298

Waiting for release~

@sheremet-va sheremet-va mentioned this pull request Jul 31, 2022
6 tasks
@PatrickChen928 PatrickChen928 deleted the fix/mock branch July 31, 2022 07:56
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.

Unable to mock 'vue-meta'
3 participants