-
-
Notifications
You must be signed in to change notification settings - Fork 266
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): migrate to vitest #646
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 65ddb7c:
|
The tests are passing, I do not know what is happening with types in the lower versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work!
added some comments for a start.
tests/computed.test.tsx
Outdated
@@ -64,7 +57,7 @@ describe('proxyWithComputed', () => { | |||
}) | |||
|
|||
it('computed getters and setters', async () => { | |||
const computeDouble = jest.fn((x: number) => x * 2) | |||
const computeDouble = vi.fn((x) => x * 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is computeDouble
typed without : number
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it becomes any
. Can we keep : number
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did it!
"import/namespace": "off", | ||
"import/named": "off", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious what was the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's related to vitest ./utils import! so i solved it with this as suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll revisit it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why __dirname
is necessary, and it seems weird, but can't be helped.
@arjunvegda Could you have a closer look to find why 21db220 doesn't work? what's the difference from jotai and zustand... |
Never mind. The last commit fixes the test, and it's probably because it somehow points to a different file. |
Ah! This explains it. if I change the import in utils/watch.ts#L1 to It appears that vite is resolving modules differently based on how we import the paths (relative vs absolute)? - import { subscribe } from '../../vanilla.ts'
+ import { subscribe } from 'valtio/vanilla' |
Jotai and Zustand do not appear to have conflicting imports within test files, so it is working fine. However, we could reproduce the issue in those libs too. This will cause modules to be duplicated and the test will fail. import { expect, it } from 'vitest'
import { getDefaultStore } from 'jotai/vanilla/store'
import { getDefaultStore as getDefaultStoreFromVanilla } from 'jotai/vanilla'
it('should match the default store', () => {
const storeA = getDefaultStoreFromVanilla()
const storeB = getDefaultStore()
expect(storeA).toBe(storeB)
}) This could be fixed by deduping imports using @rollup/plugin-node-resolve in |
@arjunvegda Thanks for investigating. Things are clear now. I think for now what we have is fine. |
This happens because relative paths in aliases are used. Vitest doesn't resolve them relative to root. Each time "valtio" is mentioned it will try to load it relative to the file it is imported from and fail. But Vitest fallbacks to the original replacement. This creates two different instances in the modules graph. The fix is to never use relative paths in aliases. The code you have here will probably break in the next Vitest release where we fixed this. |
@sheremet-va Thank you for the explanation. We'll try removing it in the next release of Vitest. cc @dai-shi |
So, always to use |
Yes. Or |
Related Issues
#643