-
Notifications
You must be signed in to change notification settings - Fork 393
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
test: remove remaining vestiges of jest types #4435
Conversation
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.
Here's some things to address before merging
if ( | ||
snapshotState['_updateSnapshot'] === 'new' || | ||
snapshotState['_updateSnapshot'] === 'all' | ||
) { |
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.
_updateSnapshot is private in vitest which means there's probably a better way to do this, but for now this is needed to avoid annoying errors in vscode.
import 'vitest'; | ||
|
||
interface CustomMatchers<R = unknown> { | ||
toMatchFile: (receivedContent: string, filename?: string) => R; | ||
} | ||
|
||
declare module 'vitest' { | ||
interface Assertion<T = any> extends CustomMatchers<T> {} | ||
interface AsymmetricMatchersContaining extends CustomMatchers {} |
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.
This might fit better in a .d.ts file
const realModule = await import(pathToEsmDistFile); | ||
// The commend below needs to be updated: | ||
// When jest properly supports ESM, this will be a lot simpler | ||
// const aliasedModule = await import(`lwc/${pkg}`); | ||
// expect(aliasedModule.default).toBe(realModule.default); |
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.
This comment and related code should be updated
} | ||
|
||
expect.extend({ | ||
toBeInRange(code, min, max, key) { | ||
toBeInRange(code, { min, max }, key) { |
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.
Typing will only work here if there's no more than 3 parameters, although tests would pass. VSCode shows errors otherwise.
@@ -31,7 +31,7 @@ | |||
"release:version": "./scripts/release/version.js" | |||
}, | |||
"//": { | |||
"prettier": "v3 requires ESM, and we use prettier in our Jest tests. Jest does not support ESM yet." | |||
"prettier": "Outdated since Jest has been replaced with vitest: v3 requires ESM, and we use prettier in our Jest tests. Jest does not support ESM yet." |
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.
Added a reminder here, maybe for another PR? I reckon this is related to #4386
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.
Thanks a bunch for this PR! LGTM, a few nits about explicit vs implicit globals.
I actually would prefer if we explicitly imported it
/test
/describe
/etc. but since we're using globals for now, let's be consistent about it across all the test files.
packages/@lwc/engine-server/src/__tests__/render-component.spec.ts
Outdated
Show resolved
Hide resolved
ERROR_CODE_RANGES.compiler.max, | ||
key | ||
); | ||
expect(errorInfo.code).toBeInRange(ERROR_CODE_RANGES.compiler, key); |
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
/nucleus test |
import diff from 'jest-diff'; | ||
import MatcherUtils = jest.MatcherUtils; | ||
import diff from '@vitest/utils/diff'; | ||
import type { MatcherState } from '@vitest/expect'; |
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.
These packages both already come from vitest
, but it makes me nervous not to have these explicitly declared in the root package.json
. Let's add them.
@@ -5,11 +5,11 @@ | |||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | |||
*/ | |||
|
|||
import diff from 'jest-diff'; |
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.
This was getting pulled in by @wdio/cli
! Whoops 🫣
Co-authored-by: Nolan Lawson <[email protected]>
Co-authored-by: Nolan Lawson <[email protected]>
Co-authored-by: Nolan Lawson <[email protected]>
Co-authored-by: Nolan Lawson <[email protected]>
Co-authored-by: Nolan Lawson <[email protected]>
/nucleus test |
Sweet, thank you! Vitest all the things 💪 |
Here's an attempt at a proper fix: #4458 |
Details
I updated all jest type usage and declarations with equivalent the equivalent vitest counterparts.
I also fixed all errors vscode was reporting in test files: There's some conflicts with @types/mocha which seems to come from webdriver.io , so I had to add some explicit imports. I'm not sure there's a better way currently.
I also updated most comments and docs I felt confident were only referring to this project's tests. Some comments I just flagged to be updated as it might involve updating code I'm not familiar with (mainly lwc/default-exports).
Closes #4422
Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
GUS work item