-
Notifications
You must be signed in to change notification settings - Fork 28
Scripts: Provide the default configuration for the test
command
#83
Conversation
Codecov Report
@@ Coverage Diff @@
## master #83 +/- ##
==========================================
+ Coverage 71.5% 75.23% +3.73%
==========================================
Files 29 34 +5
Lines 393 432 +39
Branches 79 84 +5
==========================================
+ Hits 281 325 +44
+ Misses 92 89 -3
+ Partials 20 18 -2
Continue to review full report at Codecov.
|
lerna.json
Outdated
"commands": { | ||
"publish": { | ||
"ignore": [ | ||
"**/test/*.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.
I want to test if that excludes such files from publishing to npm or this is only used to detect changed files when deciding if bump version. If the latter I will investigate how to prevent those files from being published in a different way.
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.
It is only useful to prevent publishing a new version when no code related changes are applied. See what gets downloaded from the npm:
test
folder is there. I'm wondering if there is a different way to stop publishing test file. We can always move code src
and let build script do the file filtering.
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.
That would work 👍 (i.e. let the build script take care of it)
I'd like to see this be even more generic, more focused might be a better term. In considering the widest adoption possible for these scripts instead of |
On a train and got to thinking a little more about what I wrote above, I don’t think we should look to add any zero-config support to the alternatives I listed, rather for example bbPress, currently it only uses PHPUnit, so whilst I plan on adding some Jest tests to bbPress and leverage this awesome Jest zero-config configuration you’ve put together here in this PR @gziolo I’d like to be able to have some standardised task names of sorts in that repo, in this case So I’m looking to be able to support more than just Jest in some scripts, I’m not concerned if the naming scheme is something other than what I’ve suggested above either. Does that make sense, and what are your thoughts on this @gziolo ? |
I took a peek at Gutenberg's
Otherwise, it is going to be difficult to pick one for someone who is not familiar with all those tools. One more thing to consider here, should we make only
Yes, I would prefer we support one tool for PHP and one for JS. The same we use in Gutenberg, packages and hopefully in WordPress core. |
It is used in the case when the project does not have a config for Jest or Babel
640a3ba
to
cf7900c
Compare
Writing tests for CLI scripts is hard, tons of juggling to make sure we can mock env bits :( This is ready for a review. As discussed I renamed |
A great idea, could the alias reference multiple scripts? i.e. Could the alias
Having
In a perfect world I'd agree, for WordPress Core QUnit will not be going away anytime soon, if we are to add Jest it will need to coexist with QUnit. I've not taken a close look at what would be required to for WordPress Core to drop QUnit and switch to Jest but I expect this would require a significant amount of work. |
WordPress and its sister projects use Grunt & Webpack build tooling within those projects, and as we are already looking to use this repo to simplify some of the complexity of setting up JavaScript build tooling with |
We would have to check. I guess we could to do it if we don't want to pass additional params. Otherwise, it might be difficult to distribute those params properly between those 2. What you can do is use {
"scripts": {
"test-unit:js:qunit": "wp-scripts test-unit-qunit",
"test-unit:js:jest": "wp-scripts test-unit-jest",
"test-unit:js": "npm-run-all test-unit:js:*",
"test-unit:php": "wp-scripts test-unit-phunit",
"test": "npm-run-all test-unit:**",
},
} Just and idea to show the intent.
Yes. What I did here is
I migrate Mocha -> Jest for Calypso, over 1 000 files, nearly 10 000 tests and they use a very similar API. So I totally understand your concern. Calypso still uses Chai and Sinon in many places although Jest provides its own alternatives :) |
Yes, that makes sense to have it all available in the long run. 👍 |
I don't see |
We'd like to merge this as it adds value as is. @gziolo could you resolve the merge conflict and document all the unresolved discussion / ideas in separate issues so those can be separate iterations? |
This PR provides zero configuration mode for
wp-scripts test-unit
command in the case when a project does not have a config for Jest and/or Babel. I also refactored code to make it easier to test. New utility methods were inspired by work done by @kentcdodds in https://github.com/kentcdodds/kcd-scripts. Kudos to him for amazing work and excellent coding skills. It was my pleasure to follow along and cherry pick what we need! 💯This PR also renames
test
command totest-unit
to better reflect its intent. It was raised by @youknowriad during the integration with Gutenberg. See: WordPress/gutenberg#4705 (comment):In addition, I noticed some errors in the docs when updating the script name from
test
totest-unit
.TODO
wp-scripts
throws proper errors when an unknown script name passed as the first argument.