-
Notifications
You must be signed in to change notification settings - Fork 28
Jest preset: Add default jest preset for WordPress development #74
Conversation
package.json
Outdated
], | ||
"coverageDirectory": "coverage", | ||
"setupTestFrameworkScriptFile": "./packages/jest-console/build/index.js" | ||
"preset": "./packages/jest-preset-default/jest-preset.json" |
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 will have to include @wordpress/jest-preset-default
in devDependencies
and replace this line with:
"preset": "@wordpress/jest-preset-default"
"<rootDir>/.*/build.*" | ||
], | ||
"moduleNameMapper": { | ||
"\\.(scss|css)$": "<rootDir>/packages/jest-preset-default/scripts/style-mock.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.
All occurences of <rootDir>/packages/jest-preset-default
will have to be replaced with:
<rootDir>/node_modules/@wordpress/jest-preset-default
2fc3d1b
to
6bcb0f3
Compare
I included detailed documentation about all config options used in this preset. I think it is enough to proceed. |
6bcb0f3
to
6ade9fa
Compare
Why name it For example, we could add a configuration for "themes" and "plugins" and these would be I also think this change should also be implemented for Likewise with The |
I wanted to follow what I did for Babel... I'm fine with removing
I wouldn't worry as much about this at the moment :)
I wanted to use shorthand for Babel as described here, but we can also remove |
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 👍
This PR introduces Jest preset to be shared between
@wordpress/packages
and Gutenberg. In the future, it can be also consumed by the projects created by plugin or theme developers. This implementation is fully based on the existing setup of Gutenberg which can be found in thejest
section of thepackage.json
file: https://github.com/WordPress/gutenberg/blob/master/package.json#L105. I moved everything that isn't very specific to Gutenberg's configuration. We might further discuss some things included in this PR, but I expect that most of the things included here should be left as they are. Maybe jQuery stub is something we don't want to keep. Not sure really :)There aren't many Jest preset published to npm so it doesn't seem to be a popular technique, but in our case, it should remove some code duplication and provide reasonable default settings.
The last step is to add changes which will detect if the project consuming
scripts
contains Babel or Jest config and use our presets as fallbacks. That should conclude all the work required to make unit testing easy to start within all WordPress projects.I'm not quite sure if we should include docs about the recommended Jest setup here, inside
scripts
package or in Gutenberg's handbook? I guess it can be a follow-up task once we have all the pieces working together.Testing
It's pretty annoying that I couldn't start this PR in a shape that allows to work seamlessly after it's going to be published. The thing is that all the files referenced inside the preset file need to use paths relative to the root folder of the project that is including the preset :( I will comment inline to highlight what needs to be changed before publishing to npm. What we have now allows to validate it as it is now because it works properly with all test commands:
npm test
npm run test:coverage
npm run test:coverage-ci
- which Travis usesnpm run test:watch