Build/Test Tools: Add watch:phpunit task.

This allow PHPUnit test groups to run automatically when files are changed, rather than having to be ran manually throughout the development process. This creates a smoother developer experience, and a tighter feedback loop.

Props iandunn, netweb, pento
Fixes #42282


git-svn-id: https://develop.svn.wordpress.org/trunk@42760 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ian Dunn 2018-02-27 00:31:33 +00:00
parent c625e2e7d9
commit 2f68ec5750

View File

@ -10,7 +10,17 @@ module.exports = function(grunt) {
SOURCE_DIR = 'src/',
BUILD_DIR = 'build/',
BANNER_TEXT = '/*! This file is auto-generated */',
autoprefixer = require( 'autoprefixer' );
autoprefixer = require( 'autoprefixer' ),
phpUnitWatchGroup = grunt.option( 'group' );
if ( 'watch:phpunit' === grunt.cli.tasks[ 0 ] && ! phpUnitWatchGroup ) {
grunt.log.writeln();
grunt.fail.fatal(
'Missing required parameters. Example usage: ' + '\n\n' +
'grunt watch:phpunit --group=community-events' + '\n' +
'grunt watch:phpunit --group=multisite,mail'
);
}
// Load tasks.
require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks );
@ -742,6 +752,10 @@ module.exports = function(grunt) {
'!tests/qunit/editor/**'
],
tasks: ['qunit']
},
phpunit: {
files: [ '**/*.php' ],
tasks: [ 'phpunit:default' ]
}
}
});
@ -945,7 +959,7 @@ module.exports = function(grunt) {
grunt.registerMultiTask('phpunit', 'Runs PHPUnit tests, including the ajax, external-http, and multisite tests.', function() {
grunt.util.spawn({
cmd: this.data.cmd,
args: this.data.args,
args: phpUnitWatchGroup ? this.data.args.concat( [ '--group', phpUnitWatchGroup ] ) : this.data.args,
opts: {stdio: 'inherit'}
}, this.async());
});