-
-
Notifications
You must be signed in to change notification settings - Fork 739
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
Feature/jest to vitest migration #6605
base: main
Are you sure you want to change the base?
Feature/jest to vitest migration #6605
Conversation
✅ Deploy Preview for plone-components canceled.
|
I’ve created this draft PR to get feedback on my current progress for this issue. Here’s what I’ve completed so far and what remains to be done: Remaining Work: Looking forward to your feedback! |
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 added some preliminary comments, please take a look at them. I know it's a WIP still, but I hope they help.
I haven't gone through all the changes, but the few I went look good.
It's an humongous work, so thank you for taking care of it!
You already changed the scripts commands, so it should work, CI points at them:
pnpm --filter @plone/volto test
CI is RED because you need to update the lockfile (pnpm install
).
@@ -0,0 +1,10 @@ | |||
/* eslint-disable */ |
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.
What is this file for?
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 added it to bypass ESLint warnings that I was encountering while committing. Once the work is complete, I’ll remove it.
coreAddons: {}, | ||
}), | ||
{ virtual: true }, | ||
); | ||
|
||
it('works in a mock project directory', () => { | ||
test('works in a mock project directory', () => { |
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.
Why are you changing it
to test
? Which is the reasoning behind?
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.
As u know both it and test work the same in Vitest. When I started migrating tests in Volto, I saw test in some places and it in others. However, for consistency, I wanted to standardize on using it. That said, I noticed that test is used in many existing files. If there's a preference or guideline for which one to use, please let me know so I can align with it.
packages/volto/package.json
Outdated
@@ -53,8 +55,8 @@ | |||
"stylelint:fix": "yarn stylelint --fix && yarn stylelint:overrides --fix", | |||
"lint": "eslint --max-warnings=0 'src/**/*.{js,jsx,ts,tsx,json}'", | |||
"lint:fix": "eslint --fix 'src/**/*.{js,jsx,ts,tsx,json}'", | |||
"lint:husky": "eslint --max-warnings=0 --fix", | |||
"i18n": "rm -rf build/messages && NODE_ENV=production i18n", |
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.
Please reason this change. This 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.
I added it to bypass ESLint warnings that I was encountering while committing the changes , I will remove it.
packages/volto/package.json
Outdated
@@ -53,8 +55,8 @@ | |||
"stylelint:fix": "yarn stylelint --fix && yarn stylelint:overrides --fix", | |||
"lint": "eslint --max-warnings=0 'src/**/*.{js,jsx,ts,tsx,json}'", | |||
"lint:fix": "eslint --fix 'src/**/*.{js,jsx,ts,tsx,json}'", | |||
"lint:husky": "eslint --max-warnings=0 --fix", | |||
"i18n": "rm -rf build/messages && NODE_ENV=production i18n", | |||
"lint:husky": "eslint --max-warnings=1 --fix", |
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.
why warnings=1?
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.
The warnings=0 setting was quite strict for the ESLint checks and blocking my commits, so I temporarily changed it to 1.Once the work is complete, I'll revert this change and ensure that all warnings are resolved before finalizing.
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.
git ci -am "message" -n
With -n
it does not check anything, so you can push anyways.
packages/volto/package.json
Outdated
@@ -384,6 +387,7 @@ | |||
"ts-loader": "9.4.4", | |||
"typescript": "^5.6.3", | |||
"use-trace-update": "1.3.2", | |||
"vitest": "^2.1.3", |
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.
They just released 3.0.0, we should give it a try.
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 check out Vitest 3.0.0 and integrate it into the migration.
|
||
jest.mock('../Form/Form', () => jest.fn(() => <div className="Form" />)); | ||
vi.mock('../Form/Form', () => ({ |
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.
We should include some docs about how mocks work, and the recommended way in usual cases, like this one.
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 add documentation about how mocks work and the recommended approach for common cases like this. That will make it easier for others to follow.
packages/volto/vitest.config.js
Outdated
css: true, | ||
transform: { | ||
'\\.svg$': { | ||
transform: 'vite-plugin-svgr', |
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 wrote a vite plugin for this: https://github.com/plone/volto/blob/plip6320-Vite-as-Volto-bundler/packages/volto/vite-plugins/svg.js
Please use it to have exactly the same features and output.
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 will use it and Thank you for reference.
packages/volto/vitest.config.js
Outdated
'@root': path.resolve(__dirname, 'src'), | ||
'@plone/registry/addon-registry': path.resolve( | ||
__dirname, | ||
'src/registry.js', |
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.
Not quite right... this is not the add-on registry.
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 wasn't entirely sure about the path, so I was testing some paths for the test that weren't resolving properly.I will remove it.
@sneridagh Thank you for the helpful review! I’ll implement the suggestions. |
a617af1
to
ac8055c
Compare
If your pull request closes an open issue, include the exact text below, immediately followed by the issue number. When your pull request gets merged, then that issue will close automatically.
Closes #6326