| 661 | // Figure out what tasks to run based on what files have been modified. |
| 662 | function enqueueTestingTasksForModifiedFiles( filesModified ) { |
| 663 | var taskList = ['imagemin:core']; |
| 664 | if ( /src.*\.js/.test( filesModified ) ) { |
| 665 | grunt.log.write( 'JavaScript source files modified, will run JavaScript tests.'); |
| 666 | taskList = taskList.concat( ['browserify', 'jshint:corejs', 'uglify:bookmarklet', 'qunit:compiled'] ); |
| 667 | } |
| 668 | if ( /src.*\.css/.test( filesModified ) ) { |
| 669 | grunt.log.write( 'CSS source files modified, will run CSS tests.'); |
| 670 | taskList.push( 'postcss:core' ); |
| 671 | } |
| 672 | if ( /src.*\.php/.test( filesModified ) ) { |
| 673 | grunt.log.write( 'PHP source files modified, will run PHP tests.'); |
| 674 | taskList.push( 'phpunit' ); |
| 675 | } |
| 676 | grunt.task.run( taskList ); |
| 677 | done(); |
| 678 | } |
| 679 | gitorsvn( __dirname, function(gitorsvn) { |
| 680 | if ( gitorsvn === 'svn' ) { |
| 681 | grunt.util.spawn( |
| 682 | { |
| 683 | cmd: 'svn', |
| 684 | args: ['diff', '--summarize'] |
| 685 | }, |
| 686 | function(error, result, code) { |
| 687 | if ( code !== 0 ) { |
| 688 | grunt.fail.warn( 'The `svn diff --summarize` command returned a non-zero exit code.', code ); |
| 689 | } |
| 690 | enqueueTestingTasksForModifiedFiles( result.stdout ); |
| 691 | } |
| 692 | ); |
| 693 | } else if ( gitorsvn === 'git' ) { |
| 694 | grunt.util.spawn( |
| 695 | { |
| 696 | cmd: 'git', |
| 697 | args: ['diff', '--name-only'] |
| 698 | }, |
| 699 | function(error, result, code) { |
| 700 | if ( code !== 0 ) { |
| 701 | grunt.fail.warn( 'The `git diff --name-only` command returned a non-zero exit code.', code ); |
| 702 | } |
| 703 | enqueueTestingTasksForModifiedFiles( result.stdout ); |
| 704 | } |
| 705 | ); |
| 706 | } else { |
| 707 | grunt.log.write( 'This WordPress install is not under version control, no tests will be run.' ); |
| 708 | } |
| 709 | }); |
| 710 | }); |
| 711 | |