-
-
Notifications
You must be signed in to change notification settings - Fork 742
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?
Changes from all commits
0a99d78
616c046
480d002
8fc3bbc
4793eba
25003e0
1282f45
2c12713
a067d6c
ccc6cb1
ac8055c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ indent_size = 2 | |
indent_style = tab | ||
indent_size = unset | ||
tab_width = unset | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
/types/ | ||
.i18nrc.js | ||
build/ | ||
dist/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,5 +91,7 @@ | |
"jest": true, | ||
"socket": true, | ||
"webpackIsomorphicTools": true, | ||
"vitest":true, | ||
"vi":true | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-disable */ | ||
module.exports = { | ||
locales: ['en'], | ||
extractMessages: true, | ||
outputFilePattern: 'build/messages/messages.json', | ||
inputFilePattern: [ | ||
'src/**/*.{js,jsx,ts,tsx}', | ||
'__tests__/**/*.{js,jsx,ts,tsx}', | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,22 @@ import { | |
buildDependencyGraph, | ||
getAddonsLoaderChain, | ||
} from '@plone/registry/addon-registry'; | ||
import { vi, expect, describe, test, beforeEach, afterEach } from 'vitest'; | ||
|
||
describe('AddonRegistry - Project', () => { | ||
jest.mock( | ||
vi.mock( | ||
`${path.join( | ||
__dirname, | ||
'fixtures', | ||
'test-volto-project', | ||
)}/node_modules/@plone/volto/package.json`, | ||
() => ({ | ||
// TODO: mock the packages folder inside the mocked @plone/volto to work with resolves | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Why are you changing There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const base = path.join(__dirname, 'fixtures', 'test-volto-project'); | ||
const { registry } = AddonRegistry.init(base); | ||
|
||
|
@@ -102,7 +102,7 @@ describe('AddonRegistry - Project', () => { | |
}); | ||
}); | ||
|
||
it('provides aliases for addons', () => { | ||
test('provides aliases for addons', () => { | ||
const base = path.join(__dirname, 'fixtures', 'test-volto-project'); | ||
const { registry } = AddonRegistry.init(base); | ||
expect(registry.getResolveAliases()).toStrictEqual({ | ||
|
@@ -115,13 +115,13 @@ describe('AddonRegistry - Project', () => { | |
}); | ||
}); | ||
|
||
it('provides addon extenders', () => { | ||
test('provides addon extenders', () => { | ||
const base = path.join(__dirname, 'fixtures', 'test-volto-project'); | ||
const { registry } = AddonRegistry.init(base); | ||
expect(registry.getAddonExtenders().length).toBe(1); | ||
}); | ||
|
||
it('provides a list of addon records ordered by initial package declaration', () => { | ||
test('provides a list of addon records ordered by initial package declaration', () => { | ||
const base = path.join(__dirname, 'fixtures', 'test-volto-project'); | ||
const { registry } = AddonRegistry.init(base); | ||
const addons = registry.getAddons(); | ||
|
@@ -135,7 +135,7 @@ describe('AddonRegistry - Project', () => { | |
]); | ||
}); | ||
|
||
it('provides customization paths declared in a Volto project', () => { | ||
test('provides customization paths declared in a Volto project', () => { | ||
const base = path.join(__dirname, 'fixtures', 'test-volto-project'); | ||
const { registry } = AddonRegistry.init(base); | ||
expect(registry.getProjectCustomizationPaths()).toStrictEqual({ | ||
|
@@ -148,7 +148,7 @@ describe('AddonRegistry - Project', () => { | |
}); | ||
}); | ||
|
||
it('provides customization paths declared in addons', () => { | ||
test('provides customization paths declared in addons', () => { | ||
const base = path.join(__dirname, 'fixtures', 'test-volto-project'); | ||
const { registry } = AddonRegistry.init(base); | ||
expect(registry.getAddonCustomizationPaths()).toStrictEqual({ | ||
|
@@ -220,7 +220,7 @@ describe('Addon via env var - Released addon', () => { | |
const originalEnv = process.env; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
vi.resetModules(); | ||
process.env = { | ||
...originalEnv, | ||
ADDONS: 'test-released-via-addons-env-var', | ||
|
@@ -231,7 +231,7 @@ describe('Addon via env var - Released addon', () => { | |
process.env = originalEnv; | ||
}); | ||
|
||
it('addons can be specified on the fly using ADDONS env var - Released addon', () => { | ||
test('addons can be specified on the fly using ADDONS env var - Released addon', () => { | ||
const base = path.join(__dirname, 'fixtures', 'test-volto-project'); | ||
const { registry } = AddonRegistry.init(base); | ||
expect( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { render } from '@testing-library/react'; | |
import configureStore from 'redux-mock-store'; | ||
import { Provider } from 'react-intl-redux'; | ||
import config from '@plone/volto/registry'; | ||
|
||
import Add from './Add'; | ||
|
||
const mockStore = configureStore(); | ||
|
@@ -16,9 +15,15 @@ beforeAll(() => { | |
config.settings.loadables = {}; | ||
}); | ||
|
||
jest.mock('../Toolbar/Toolbar', () => jest.fn(() => <div id="Portal" />)); | ||
vi.mock('../Toolbar/Toolbar', () => ({ | ||
__esModule: true, | ||
default: vi.fn(() => <div id="Portal" />), | ||
})); | ||
|
||
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 commentThe 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 commentThe 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. |
||
__esModule: true, | ||
default: vi.fn(() => <div className="Form" />), | ||
})); | ||
|
||
describe('Add', () => { | ||
it('renders an empty add 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.
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.