-
Notifications
You must be signed in to change notification settings - Fork 58
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
Bump Jest version to v27 #4499
Bump Jest version to v27 #4499
Conversation
"jest": "^24.9.0", | ||
"jest-junit": "^6.3.0", | ||
"jest": "^27.4.5", | ||
"jest-junit": "^13.0.0", |
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 versions match the values from Gutenberg's package.json
file:
https://github.com/WordPress/gutenberg/blob/5a84b27bcead1528ca98bcade9c6d5259c70de7b/package.json#L178-L179
"babel-jest": "^24.9.0", | ||
"babel-jest": "^27.4.5", |
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 version matches the value from Gutenberg's package.json
file:
https://github.com/WordPress/gutenberg/blob/5a84b27bcead1528ca98bcade9c6d5259c70de7b/package.json#L151
Changing the PR to draft as it requires further modifications to fix the unit tests 🔧 . |
It's not longer required to isolate modules for registering jetpack blocks.
Wanna run full suite of Android and iOS UI tests? Click here and 'Approve' CI job! |
registerGutenberg( { | ||
beforeInitCallback: () => { | ||
// We have to lazy import the setup code to prevent executing any code located | ||
// at global scope before the editor is initialized, like translations retrieval. | ||
require( './setup' ).default(); | ||
export default function registerGutenbergMobile() { |
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 had to expose the register function mainly for testing purposes, so we can initialize Gutenberg Mobile on each test without having to reimport the module.
I noticed that Android device tests are failing with the following error:
I'll take a deeper look but I have the gut feeling that after the Jest upgrade, we might need to reconfigure how/where CircleCI fetches the test results. |
@@ -26,7 +26,6 @@ module.exports = { | |||
clearMocks: true, | |||
preset: './gutenberg/node_modules/react-native/jest-preset.js', | |||
setupFiles: [ '<rootDir>/' + configPath + '/setup.js' ], | |||
testEnvironment: 'jsdom', |
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.
Now we use node
environment which is now the default value (reference).
const setupLocaleLogs = [ | ||
[ 'locale', defaultLocale, getGutenbergTranslation( defaultLocale ) ], | ||
[ | ||
'jetpack - locale', | ||
defaultLocale, | ||
getJetpackTranslation( defaultLocale ), | ||
], | ||
[ | ||
'layout-grid - locale', | ||
defaultLocale, | ||
getLayoutGridTranslation( defaultLocale ), | ||
], | ||
]; |
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 logs correspond to the setup locale logs triggered from here.
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 for this PR, but what do you think about refactoring all of our intentional logs to reside behind a ENABLE_LOGGING
environment flag? E.g. ENABLE_LOGGING=true npm run start:quick
.
Whether to add a log message is often left to each contributor to decide what subject reaches the threshold of deserving a log message. Ultimately, the project will likely arrive at a point where there are so many logs that it becomes difficult to parse important warnings or errors.
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.
AFAIK, we don't display too many informational logs, apart from the locale/translations ones, but in any case, I like your idea about providing an option for enabling/disabling logs. As you mentioned, it would help us on identifying important messages like warnings and errors 👍.
jest.isolateModules( () => { | ||
// Import entry point to initialize the editor | ||
require( '../index' ); | ||
} ); | ||
return render( <EditorComponent { ...props } /> ); | ||
registerGutenbergMobile(); |
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 running several tests, I noticed that now using isolateModules
when rendering the editor causes failures. As far as I investigated, it duplicates the Redux stores, in my case I verified it was creating two different stores for @wordpress/blocks
. This leads to a scenario where blocks are registered into the second store but the editor complains about the lack of blocks (most likely because it's accessing the first one).
For this reason, I decided to stop using the workaround of isolating modules for registering Gutenberg on each test, and instead export the register function and call it here.
// Jetpack blocks are registered when importing the editor extension module. | ||
// Since we need to register the blocks multiple times for testing, | ||
// it's required to isolate modules for re-importing the editor extension multiple times. | ||
const registerJetpackBlocksIsolated = ( props ) => { | ||
jest.isolateModules( () => { | ||
registerJetpackBlocks( props ); | ||
} ); | ||
}; | ||
// Similarly to Jetpack blocks, Jetpack embed variations also require to isolate modules. | ||
const registerJetpackEmbedVariationsIsolated = ( props ) => { | ||
jest.isolateModules( () => { | ||
registerJetpackEmbedVariations( props ); | ||
} ); | ||
}; |
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.
For the same reason as outlined in this comment, I removed the use of isolateModules
. In this case, the main purpose of using this function was to assure that Jetpack/Layout-grid blocks are registered on each test, as they are registered upon module importation. However, I realized after removing that function that it's no longer required to isolate the modules, as blocks are registered on every test.
I found out that the environment variable used for specifying the output file of Jest-unit (i.e. |
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 putting this work together. 👏🏻
I attempted to verify the e2e tests locally, but ran in to a fair amount of flakiness and unrelated build errors, unfortunately. Provided the CI tests pass, I think we are good to go. 👍🏻
const setupLocaleLogs = [ | ||
[ 'locale', defaultLocale, getGutenbergTranslation( defaultLocale ) ], | ||
[ | ||
'jetpack - locale', | ||
defaultLocale, | ||
getJetpackTranslation( defaultLocale ), | ||
], | ||
[ | ||
'layout-grid - locale', | ||
defaultLocale, | ||
getLayoutGridTranslation( defaultLocale ), | ||
], | ||
]; |
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 for this PR, but what do you think about refactoring all of our intentional logs to reside behind a ENABLE_LOGGING
environment flag? E.g. ENABLE_LOGGING=true npm run start:quick
.
Whether to add a log message is often left to each contributor to decide what subject reaches the threshold of deserving a log message. Ultimately, the project will likely arrive at a point where there are so many logs that it becomes difficult to parse important warnings or errors.
Related to WordPress/gutenberg#38133.
This PR bumps the Jest package version to v27 to match the same version in Gutenberg, which was recently updated in WordPress/gutenberg#33287.
Additionally, it updates the unit tests located in GB-mobile in order to prevent failures with the update.
To test:
Automated tests
Manual tests
npm run test:e2e:android:local
.npm run test:e2e:ios:local
.npm run test
.PR submission checklist: