-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ESLint: Enable jest/recommended
for tests
#47065
Conversation
@@ -372,6 +372,7 @@ module.exports = { | |||
extends: [ | |||
'plugin:jest-dom/recommended', | |||
'plugin:testing-library/react', | |||
'plugin:jest/recommended', |
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're enabling the jest/recommended
set of rules:
https://github.com/jest-community/eslint-plugin-jest#recommended
@@ -185,6 +185,7 @@ | |||
"eslint-import-resolver-node": "0.3.4", | |||
"eslint-plugin-eslint-comments": "3.1.2", | |||
"eslint-plugin-import": "2.25.2", | |||
"eslint-plugin-jest": "27.2.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.
We're now relying on it directly, so adding it as a dependency. Using the latest version.
package-lock.json
Outdated
"version": "25.2.3", | ||
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-25.2.3.tgz", | ||
"integrity": "sha512-Yoa0at3euTjERDvPGPWiItY1uuqKYQ5Ov2SmkSLmKRq9OFiVdEehw0rWuK4PA538k7CNqnvmkztjAB9l+HJ7kQ==", | ||
"version": "27.2.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.
This is expected: we're not requiring the minimum version that eslint-plugin
requires.
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.
Scratch that, there's been an incompatibility in peer dependencies when running npm run other:check-licenses
. I've matched the versions now.
@@ -50,7 +50,7 @@ describe( 'BlockSelectionClearer component', () => { | |||
|
|||
fireEvent.mouseDown( screen.getByTestId( 'selection-clearer' ) ); | |||
|
|||
expect( mockClearSelectedBlock ).toBeCalled(); | |||
expect( mockClearSelectedBlock ).toHaveBeenCalled(); |
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.
@@ -22,20 +22,17 @@ describe( 'getPxFromCssUnit', () => { | |||
[ '40Q', '38px' ], // 40 Q should be 1 cm. | |||
]; | |||
|
|||
test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => { |
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.
@@ -78,7 +78,7 @@ describe( 'withDispatch', () => { | |||
|
|||
// Function value reference should not have changed in props update. | |||
// The spy method is only called during inital render. | |||
expect( ButtonSpy ).toBeCalledTimes( 1 ); | |||
expect( ButtonSpy ).toHaveBeenCalledTimes( 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.
@@ -29,7 +29,7 @@ describe( 'persistence', () => { | |||
expect( () => { | |||
const options = Object.freeze( { persist: true, reducer() {} } ); | |||
registry.registerStore( 'test', options ); | |||
} ).not.toThrowError( /object is not extensible/ ); | |||
} ).not.toThrow( /object is not extensible/ ); |
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.
@@ -748,7 +749,7 @@ describe( 'createRegistry', () => { | |||
Object.fromEntries( | |||
Object.entries( registry ).map( ( [ key ] ) => { | |||
if ( key === 'stores' ) { | |||
return [ key, expect.any( Object ) ]; | |||
return [ key, anyObject ]; |
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.
@@ -174,7 +174,10 @@ describe( 'AutosaveMonitor', () => { | |||
|
|||
jest.runOnlyPendingTimers(); | |||
|
|||
expect( setTimeout ).lastCalledWith( expect.any( Function ), 5000 ); | |||
expect( setTimeout ).toHaveBeenLastCalledWith( |
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.
@@ -12,7 +12,6 @@ process.on( 'unhandledRejection', ( err ) => { | |||
/** | |||
* External dependencies | |||
*/ | |||
/* eslint-disable-next-line jest/no-jest-import */ |
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.
No longer a valid rule, it was removed in jest-community/eslint-plugin-jest#1220.
Size Change: 0 B Total Size: 1.33 MB ℹ️ View Unchanged
|
Flaky tests detected in 5ad13c2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3893161190
|
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.
LGTM 🚀
Thank you for the continuous iteration on improving our testing environment 🙏
What?
This PR enables the
jest/recommended
rules for tests. We're updating to the latesteslint-plugin-jest
version too. Finally, we're addressing all the present errors, most of which are pretty straightforward.Why?
By enabling the ESLint plugins of our libraries and enabling their recommended configuration, we ensure to be following the best practices for writing our tests.
How?
Most of what we're doing is straightforward, but I'll do a self-review to add context.
Testing Instructions
npm run lint:js
Testing Instructions for Keyboard
None
Screenshots or screencast
None