-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Jest to vitest migration alpha #5097
Jest to vitest migration alpha #5097
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
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 e9f3a1a:
|
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## alpha #5097 +/- ##
==========================================
- Coverage 90.39% 88.39% -2.01%
==========================================
Files 105 78 -27
Lines 3791 2877 -914
Branches 952 815 -137
==========================================
- Hits 3427 2543 -884
+ Misses 331 283 -48
- Partials 33 51 +18
... and 74 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
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.
Thank you 🙏 ❤️ . Please have a look at my comments:
const handleError = (e: unknown) => { | ||
expect(e).toBe(err) | ||
done() |
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 does vitest know to wait for this expectation to occur ?
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 believe vitest will wait for any unresolved promises created by the test's callback closure to resolve before continuing. I affirmed this assumption by adding a false assertion (expect(true).toBe(false)
) where the done()
was and ensuring the test fails).
If we want we can make the test callback async
and explicitely await
a promise that will assert this assertion is called. e.g.:
test('"onError" should be called when "func" throw error', async () => {
await new Promise((res) => {
const err = new Error('error')
const handleError = (e: unknown) => {
expect(e).toBe(err)
res()
}
const testFunc = asyncThrottle(
() => {
throw err
},
{ onError: handleError },
)
testFunc()
})
})
This appears to be the recommended solution for the deprecated done
parameter.
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.
yeah that looks good 👍
// Should not display the console error | ||
// "Warning: Can't perform a React state update on an unmounted component" |
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.
feel free to delete this whole test. this warning is no longer a thing in react18, so the test doesn't test anything
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.
👍
resolve(observer.fetchOptimistic(defaultedOptions.value)) | ||
resolve(observer.fetchOptimistic(defaultedOptions.value) as any) | ||
} else { | ||
stopWatch() | ||
resolve(optimisticResult) | ||
resolve(optimisticResult as any) |
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.
@DamianOsipiuk FYI
packages/vue-query/tsconfig.json
Outdated
@@ -4,10 +4,9 @@ | |||
"composite": true, | |||
"rootDir": "./src", | |||
"outDir": "./build/lib", | |||
"tsBuildInfoFile": "./build/.tsbuildinfo" | |||
"tsBuildInfoFile": "./build/.tsbuildinfo", | |||
"module": "esnext" |
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.
doesn't this change the output of the type definitions for the vue
package?
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.
@ZackDeRose Could you please explain why this change is necessary?
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.
Hey folks - yes I needed top-level await for those mock files. The equivalent of jest's synchronous requireActual
is vitest's async importActual
. I'll revert this and see if I can fix those mocks some other way.
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.
Looks like the error I was getting is only in the ts language server, so this is safe to revert. See comment in the mock file!
|
||
export const useBaseQuery = jest.fn(originImpl) |
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.
If vi.mock
automatically wraps all original implementations
with spy functions, then we could remove it.
Jest used the __mock__
directory for mocking modules, without necessity to write the same mock in multiple files.
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.
makes sense - thanks!
// @ts-expect-error - vitest uses esmodules; tsconfig is not set to use them | ||
(await vi.importActual('../useBaseQuery')) as any |
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.
After reverting my change to the tsconfig.json
this error shows up in the IDE via the ts language service, but running pnpm test:ci
passes just fine even with the error marked in the IDE.
I've added this // @ts-expect-error
so we don't see this via the IDE, but lmk if there's a preferred fix I'm not aware of.
Setting sights on coverage reports now |
let's see if that fixes coverage - confirming I see the reports generated now on my local filesystem |
ran into an error:
I've re-run to see if this was just flaky |
hmm the error seems to persist :/ |
interesting - I'm getting passing investigating now |
Was able to reproduce this I'll add a bump this in the ci files to 16.19 (most recent v16), I don't seem to get the error on that version of node, let me know if that acceptable or if we need to stay on this version |
That's fine 👍 |
Mostly a clone of #5081, but for the
alpha
branch (see discussion in that pr w/ @TkDodo)Addresses #5074