From 80860c90943783e605333cd259adf8f57c54b63c Mon Sep 17 00:00:00 2001 From: Brian Porter Date: Wed, 3 Sep 2014 14:46:22 -0500 Subject: [PATCH 1/3] Adds TODO marker. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fb81185..bd2e95d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "_PROJECT_NAME_", + "name": "@TODO:_PROJECT_NAME_", "scripts": { "start": "grunt dev" }, From 7c0bdcdfeec2d9c38ab3cbe18aae7c28efdbd586 Mon Sep 17 00:00:00 2001 From: Brian Porter Date: Wed, 21 Jan 2015 09:19:42 -0600 Subject: [PATCH 2/3] WIP gruntfile experiments. The PHP test runner should really be a MultiTask so it fires tests sequentially (they clobber each other inside the VM otherwise.) This would also allow us to have the individual filenames available in the grunt task for watching php files instead of having to register an event watcher using `grunt.event.on()`. --- Gruntfile.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index 803542a..6586edd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,7 @@ module.exports = function(grunt) { grunt.loadTasks('Console/node/tasks'); require('load-grunt-tasks')(grunt); + var changedFiles = {}; grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), @@ -27,6 +28,10 @@ module.exports = function(grunt) { '!.git/**/*.php' ], tasks: 'null' // See Console/node/tasks/php_tests.js +// tasks: 'phptestfile', + options: { + spawn: false + } }, less: { files: ['webroot/less/**/*.less'], @@ -37,4 +42,28 @@ module.exports = function(grunt) { grunt.registerTask('default', ['less', 'watch']); grunt.registerTask('test', ['jstest']); // See Console/node/tasks/js_tests.js + + + +// grunt.event.on('watch', function(action, filepath) { +// if (this.name === 'watch:php') { +// changedFiles[filepath] = action; +// } +// }); +// +// grunt.registerMultiTask('phptestfile', function() { +// console.log(changedFiles); +// return true; +// +// var filepath = '?'; +// var CakeTestRunner = require('./Console/node/cake_test_runner'); +// var file = new CakeTestRunner(filepath); +// +// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too. +// file.vagrantHost = true; +// } +// +// file.exists(function() { file.run(); }); +// }); + }; From f6df1c99ef7221cb03eedd21a6ae5806d7f15bdf Mon Sep 17 00:00:00 2001 From: Brian Porter Date: Wed, 21 Jan 2015 13:20:26 -0600 Subject: [PATCH 3/3] WIP. Non-functional. So the basic idea here is that instead of binding a hidden `grunt.even.on('watch)` event, we could register a multiTask directly, and loop over the supplied filenames. The problem seems to be that grunt-contrib-watch doesn't expect to hand off to a multiTask, so things don't work correctly. There seems to be an approach for handling this kind of case laid out here though: https://www.npmjs.com/package/grunt-contrib-watch#compiling-files-as-needed Needs more experimentation. --- Console/node/tasks/php_tests.js | 30 +++++++++++----------- Gruntfile.js | 45 +++++++++++++++------------------ 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/Console/node/tasks/php_tests.js b/Console/node/tasks/php_tests.js index ef7e332..e92d6c9 100644 --- a/Console/node/tasks/php_tests.js +++ b/Console/node/tasks/php_tests.js @@ -1,17 +1,17 @@ var fs = require('fs'); -module.exports = function(grunt) { - grunt.event.on('watch', function(action, filepath) { - var CakeTestRunner, regex = /\.php$/; - if (regex.test(filepath)) { - CakeTestRunner = require('../cake_test_runner'), - file = new CakeTestRunner(filepath); - - if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too. - file.vagrantHost = true; - } - - file.exists(function() { file.run(); }); - } - }); -}; \ No newline at end of file +// module.exports = function(grunt) { +// grunt.event.on('watch', function(action, filepath) { +// var CakeTestRunner, regex = /\.php$/; +// if (regex.test(filepath)) { +// CakeTestRunner = require('../cake_test_runner'), +// file = new CakeTestRunner(filepath); +// +// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too. +// file.vagrantHost = true; +// } +// +// file.exists(function() { file.run(); }); +// } +// }); +// }; \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 6586edd..8c9bfe9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,7 @@ module.exports = function(grunt) { grunt.loadTasks('Console/node/tasks'); require('load-grunt-tasks')(grunt); - var changedFiles = {}; + var fs = require('fs'); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), @@ -17,6 +17,9 @@ module.exports = function(grunt) { } } }, + phptestfile: { + target: {}, + }, watch: { php: { @@ -27,8 +30,8 @@ module.exports = function(grunt) { '!tmp/**', '!.git/**/*.php' ], - tasks: 'null' // See Console/node/tasks/php_tests.js -// tasks: 'phptestfile', +// tasks: 'null', // See Console/node/tasks/php_tests.js + tasks: ['phptestfile'], options: { spawn: false } @@ -43,27 +46,19 @@ module.exports = function(grunt) { grunt.registerTask('default', ['less', 'watch']); grunt.registerTask('test', ['jstest']); // See Console/node/tasks/js_tests.js + grunt.registerMultiTask('phptestfile', function() { + var files = this.filesSrc; + var CakeTestRunner = require('./Console/node/cake_test_runner'); + var phpfile; + var vagrantHost = fs.existsSync('.vagrant'); + files.forEach(function(filepath) { + phpfile = new CakeTestRunner(filepath); + phpfile.vagrantHost = vagrantHost; + phpfile.exists(function() { phpfile.run(); }); + }); -// grunt.event.on('watch', function(action, filepath) { -// if (this.name === 'watch:php') { -// changedFiles[filepath] = action; -// } -// }); -// -// grunt.registerMultiTask('phptestfile', function() { -// console.log(changedFiles); -// return true; -// -// var filepath = '?'; -// var CakeTestRunner = require('./Console/node/cake_test_runner'); -// var file = new CakeTestRunner(filepath); -// -// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too. -// file.vagrantHost = true; -// } -// -// file.exists(function() { file.run(); }); -// }); - -}; + // Otherwise, print a success message. + grunt.log.ok('Files tested: ' + files.length); + }); +}