From 2f68ec575043e5559af37b841b42f89567d1e510 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Tue, 27 Feb 2018 00:31:33 +0000 Subject: [PATCH] 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 --- Gruntfile.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 65cd2bcc17..a43eabd832 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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()); });