Skip to content

Commit f6df1c9

Browse files
committed
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.
1 parent 7c0bdcd commit f6df1c9

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

Console/node/tasks/php_tests.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
var fs = require('fs');
22

3-
module.exports = function(grunt) {
4-
grunt.event.on('watch', function(action, filepath) {
5-
var CakeTestRunner, regex = /\.php$/;
6-
if (regex.test(filepath)) {
7-
CakeTestRunner = require('../cake_test_runner'),
8-
file = new CakeTestRunner(filepath);
9-
10-
if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too.
11-
file.vagrantHost = true;
12-
}
13-
14-
file.exists(function() { file.run(); });
15-
}
16-
});
17-
};
3+
// module.exports = function(grunt) {
4+
// grunt.event.on('watch', function(action, filepath) {
5+
// var CakeTestRunner, regex = /\.php$/;
6+
// if (regex.test(filepath)) {
7+
// CakeTestRunner = require('../cake_test_runner'),
8+
// file = new CakeTestRunner(filepath);
9+
//
10+
// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too.
11+
// file.vagrantHost = true;
12+
// }
13+
//
14+
// file.exists(function() { file.run(); });
15+
// }
16+
// });
17+
// };

Gruntfile.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = function(grunt) {
22
grunt.loadTasks('Console/node/tasks');
33
require('load-grunt-tasks')(grunt);
4-
var changedFiles = {};
4+
var fs = require('fs');
55

66
grunt.initConfig({
77
pkg: grunt.file.readJSON('package.json'),
@@ -17,6 +17,9 @@ module.exports = function(grunt) {
1717
}
1818
}
1919
},
20+
phptestfile: {
21+
target: {},
22+
},
2023

2124
watch: {
2225
php: {
@@ -27,8 +30,8 @@ module.exports = function(grunt) {
2730
'!tmp/**',
2831
'!.git/**/*.php'
2932
],
30-
tasks: 'null' // See Console/node/tasks/php_tests.js
31-
// tasks: 'phptestfile',
33+
// tasks: 'null', // See Console/node/tasks/php_tests.js
34+
tasks: ['phptestfile'],
3235
options: {
3336
spawn: false
3437
}
@@ -43,27 +46,19 @@ module.exports = function(grunt) {
4346
grunt.registerTask('default', ['less', 'watch']);
4447
grunt.registerTask('test', ['jstest']); // See Console/node/tasks/js_tests.js
4548

49+
grunt.registerMultiTask('phptestfile', function() {
50+
var files = this.filesSrc;
51+
var CakeTestRunner = require('./Console/node/cake_test_runner');
52+
var phpfile;
53+
var vagrantHost = fs.existsSync('.vagrant');
4654

55+
files.forEach(function(filepath) {
56+
phpfile = new CakeTestRunner(filepath);
57+
phpfile.vagrantHost = vagrantHost;
58+
phpfile.exists(function() { phpfile.run(); });
59+
});
4760

48-
// grunt.event.on('watch', function(action, filepath) {
49-
// if (this.name === 'watch:php') {
50-
// changedFiles[filepath] = action;
51-
// }
52-
// });
53-
//
54-
// grunt.registerMultiTask('phptestfile', function() {
55-
// console.log(changedFiles);
56-
// return true;
57-
//
58-
// var filepath = '?';
59-
// var CakeTestRunner = require('./Console/node/cake_test_runner');
60-
// var file = new CakeTestRunner(filepath);
61-
//
62-
// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too.
63-
// file.vagrantHost = true;
64-
// }
65-
//
66-
// file.exists(function() { file.run(); });
67-
// });
68-
69-
};
61+
// Otherwise, print a success message.
62+
grunt.log.ok('Files tested: ' + files.length);
63+
});
64+
}

0 commit comments

Comments
 (0)