#35557 closed task (blessed) (fixed)
grunt precommit should run phpunit tests
Reported by: | ericlewis | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
The grunt precommit
task, as it says "Runs front-end dev/test tasks in preparation for a commit." phpunit is a test task, we should run it too.
Attachments (6)
Change History (38)
#2
@
9 years ago
@helen had a great point in that discussion:
if i'm making CSS changes i don't want to run [phpunit] tests, but that's specific to those commits :)
Perhaps our precommit task could check what files have been modified and decide what should be run. e.g.
- if css has been modified run
postcss:core
- if js has been modified run
browserify
,jshint:corejs
,uglify:bookmarklet
, andqunit:compiled
- if php has bee modified run
phpunit
.
#3
@
9 years ago
This is the reason I didn't see this coming. https://travis-ci.org/aaronjorbin/develop.wordpress/builds/102999440
#4
@
9 years ago
if i'm making CSS changes i don't want to run [phpunit] tests, but that's specific to those commits :)
I agree with this, but the same argument could be made for the js and image tasks. Those seem unnecessary for css changes.
As I'm not a committer I don't know the pains of it, but to me it makes sense to give options. i.e. pass --no-phpunit
to skip phpunit tests, --no-js
to skip js, etc. The default would run all of them.
#5
@
9 years ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to Future Release
attachment:35557.diff is a proof of concept patch that works for svn-based installs. It will look at the status of the svn repository, and run tests depending on what file types have been modified.
#6
@
9 years ago
I wonder if we should try to refactor some of the stuff from grunt-patch-wordpress
out that detect the difference between git and svn and use that. That could be a dependency that both grunt-patch-wordpress
and WordPress relied on.
#7
follow-up:
↓ 8
@
9 years ago
Quick notes on the patch so these pieces aren't forgotten:
1) let's not get rid of the description. It's valuable if you run grunt --help
to see the description.
2) Bail if the svn diff command returned a non-zero exit code.
We should pass either false
or an Error
object so the task is a failure rather then just bailing.
Otherwise, solid start.
#8
in reply to:
↑ 7
@
9 years ago
Replying to jorbin:
I wonder if we should try to refactor some of the stuff from grunt-patch-wordpress out that detect the difference between git and svn and use that.
Why not :) I've rolled this logic into a package. Feedback welcome there.
Replying to jorbin:
1) let's not get rid of the description. It's valuable if you run
grunt --help
to see the description.
Good point!
2)
Bail if the svn diff command returned a non-zero exit code.
We should pass eitherfalse
or anError
object so the task is a failure rather then just bailing.
I added a grunt.fail.warn()
here instead.
#10
@
9 years ago
Chatted in meatspace with @ericlewis,
He is going to add support for git, fix up a logic issue for detecting php file changes, then I'm going to do some testing and commit this.
#11
@
9 years ago
- Add support for git
- Move code that decides what tasks to enqueue into its own function, which both git and svn callbacks can use.
- Add logging to let the user know when tests will be run based on files modified.
- Let the user know if we couldn't find the install under version control, and no tests will be run.
#12
@
9 years ago
Updated patch 35557.4.diff makes a couple of changes:
- Adds a new line to the end of each of the
grunt.log.write
messages, so if multiple precommit tasks are run each message is on a new line rather than 1 long line.
- Fixes task
imagemin:core
so it is run whenever each of the 3 (currently) JS, CSS, or PHP precommit tasks are run, previously only would run if JS files had been modified
- Rejigs the grunt tasks in
enqueueTestingTasksForModifiedFiles
to use grunt sub task aliases of theprecommit
task,precommit:core
,precommit:js
,precommit:css
, andprecommit:php
. This should make any future tasks changes/additions to the "precommit" workflow a little more friendly for svn blame and improves readability.
Tested with SVN of both modified and new files with JS, CSS, PHP or combinations thereof.
#13
@
9 years ago
This isn't working for me.
$ grunt precommit Running "precommit" task Warning: The `svn diff --summarize` command returned a non-zero exit code. Use --force to continue. Aborted due to warnings. $ svn diff --summarize svn: E200007: Summarizing diff can only compare repository to repository
svn, version 1.7.20
This ticket was mentioned in Slack in #core by jorbin. View the logs.
9 years ago
#16
@
9 years ago
- Keywords commit added
I am not sure why that failed for you @jorbin. svn status
is probably more reliable to use, switched to that in attachment:35557.5.diff.
This ticket was mentioned in Slack in #core by jorbin. View the logs.
9 years ago
#20
@
9 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Apparently there are some comma splice that @boonebgorges would love to fix. I had to google what a comma splice is.
#21
@
9 years ago
- Owner changed from jorbin to boonebgorges
- Status changed from reopened to assigned
#22
follow-up:
↓ 25
@
9 years ago
The naming of the precommit:core
task is a bit confusing because it only runs the image:core
task.
Also, shouldn't the precommit task only check staged files?
It would be awesome if the phpunit task would run in Vagrant, see https://github.com/xwp/wp-dev-lib/blob/f95a6e9e60fc261af655be929cee637e93149f41/check-diff.sh#L532-L552. :-)
#25
in reply to:
↑ 22
@
9 years ago
Replying to ocean90:
The naming of the
precommit:core
task is a bit confusing because it only runs theimage:core
task.
I chose that name in that it is the sub task name for all the other tasks that are *not* CSS, JS, or PHP
Maybe precommit:base
would be better? Any other suggestions?
Also, shouldn't the precommit task only check staged files?
After the issues last week of trying to get a patch to apply from #35945 that included the deletion of files as discussed in Slack here it was problematic at best, for experienced Git/SVN users reverting staged files or deleted files is would not prove to be overly challenging, for less experienced users reverting these types of changes would not be so easy. For that reason my inclination here is to leave it as it currently stands and iterate further another time if required.
It would be awesome if the phpunit task would run in Vagrant, see https://github.com/xwp/wp-dev-lib/blob/f95a6e9e60fc261af655be929cee637e93149f41/check-diff.sh#L532-L552. :-)
+1 I like this idea, created ticket #36190 for this.
#28
@
9 years ago
In 35557.6.diff are two fixes/tweaks:
- First fixes a mistake I made in my original patch which landed as part of r36906, for CSS files the
precommit
task should be calling theprecommit:css
task, and notpostcss:core
directly. FWIW thepostcss:core
task only callsprecommit:css
anyway, so its not broken per se, but it's not inline with the purpose of the original patch and should be fixed to operate in the same fashion as the otherprecommit
sub tasks.
- Secondly a tweak to the
prerelease
task introduced in r36930, the patch removes the taskbuild
from theprerelease
task list asbuild
was being ran twice causing theprerelease
task to take much more time than it should. Thebuild
task is triggered as part of theprecommit:js
task which in turn calls thequnit:compiled
task which includes thebuild
task in its task list.
This ticket was mentioned in Slack in #core by netweb. View the logs.
9 years ago
#30
follow-up:
↓ 31
@
9 years ago
@netweb Can you create a new ticket? As this one was closed for 4.5, we will want a new one to follow up and improve things in 4.6
Related discussion: https://irclogs.wordpress.org/chanlog.php?channel=wordpress-dev&day=2014-02-13&sort=asc#m791485