#35557 closed task (blessed) (fixed)
grunt precommit should run phpunit tests
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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
@
10 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
@
10 years ago
This is the reason I didn't see this coming. https://travis-ci.org/aaronjorbin/develop.wordpress/builds/102999440
#4
@
10 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
@
10 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
@
10 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
@
10 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
@
10 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 --helpto see the description.
Good point!
2)
Bail if the svn diff command returned a non-zero exit code.We should pass eitherfalseor anErrorobject so the task is a failure rather then just bailing.
I added a grunt.fail.warn() here instead.
#10
@
10 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
@
10 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
@
10 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.writemessages, so if multiple precommit tasks are run each message is on a new line rather than 1 long line.
- Fixes task
imagemin:coreso 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
enqueueTestingTasksForModifiedFilesto use grunt sub task aliases of theprecommittask,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
@
10 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.
10 years ago
#16
@
10 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.
10 years ago
#20
@
10 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
@
10 years ago
- Owner changed from jorbin to boonebgorges
- Status changed from reopened to assigned
#22
follow-up:
↓ 25
@
10 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
@
10 years ago
Replying to ocean90:
The naming of the
precommit:coretask is a bit confusing because it only runs theimage:coretask.
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
@
10 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
precommittask should be calling theprecommit:csstask, and notpostcss:coredirectly. FWIW thepostcss:coretask only callsprecommit:cssanyway, 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 otherprecommitsub tasks.
- Secondly a tweak to the
prereleasetask introduced in r36930, the patch removes the taskbuildfrom theprereleasetask list asbuildwas being ran twice causing theprereleasetask to take much more time than it should. Thebuildtask is triggered as part of theprecommit:jstask which in turn calls thequnit:compiledtask which includes thebuildtask in its task list.
This ticket was mentioned in Slack in #core by netweb. View the logs.
10 years ago
#30
follow-up:
↓ 31
@
10 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