diff --git a/README.md b/README.md index a1dfa13..a684cf0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# grunt-contrib-watch [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-watch.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch) +# grunt-contrib-watch v0.5.2 [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-watch.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch) > Run predefined tasks whenever watched file patterns are added, changed or deleted. @@ -425,4 +425,4 @@ Spawning does cause a performance hit (usually 500ms for most environments). It Task submitted by [Kyle Robinson Young](http://dontkry.com) -*This file was generated on Fri Aug 16 2013 08:58:16.* +*This file was generated on Fri Aug 23 2013 14:07:18.* diff --git a/tasks/watch.js b/tasks/watch.js index 3a6190f..1305d85 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -146,7 +146,9 @@ module.exports = function(grunt) { // Add changed files to the target if (taskrun.targets[target.name]) { - taskrun.targets[target.name].changedFiles = Object.create(null); + if (!taskrun.targets[target.name].changedFiles) { + taskrun.targets[target.name].changedFiles = Object.create(null); + } taskrun.targets[target.name].changedFiles[filepath] = status; } diff --git a/test/fixtures/livereload/Gruntfile.js b/test/fixtures/livereload/Gruntfile.js index 87edf7a..9e14c54 100644 --- a/test/fixtures/livereload/Gruntfile.js +++ b/test/fixtures/livereload/Gruntfile.js @@ -21,6 +21,15 @@ module.exports = function(grunt) { }, }, }, + multiplefiles: { + files: ['lib/*.js'], + tasks: ['before'], + options: { + livereload: { + port: 9876, + }, + }, + }, nospawn: { files: ['lib/*.js'], tasks: ['before'], diff --git a/test/fixtures/livereload/lib/two.js b/test/fixtures/livereload/lib/two.js new file mode 100644 index 0000000..24ad8a3 --- /dev/null +++ b/test/fixtures/livereload/lib/two.js @@ -0,0 +1 @@ +var two = true; \ No newline at end of file diff --git a/test/tasks/livereload_test.js b/test/tasks/livereload_test.js index 912801a..43a793c 100644 --- a/test/tasks/livereload_test.js +++ b/test/tasks/livereload_test.js @@ -84,6 +84,28 @@ exports.livereload = { test.done(); }); }, + multiplefiles: function(test) { + test.expect(4); + var resultData = ''; + var cwd = path.resolve(fixtures, 'livereload'); + var assertWatch = helper.assertTask(['watch:multiplefiles', '-v'], {cwd: cwd}); + assertWatch([function() { + request(9876, function(data) { + resultData += data; + grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;'); + grunt.file.write(path.join(cwd, 'lib', 'two.js'), 'var two = true;'); + }); + }], function(result) { + result = helper.unixify(result); + helper.verboseLog(result); + test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.'); + test.ok(result.indexOf('Live reload server started on port: 9876') !== -1, 'live reload server should have been started on port 35729.'); + test.ok(/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), 'live reload should have triggered on lib/one.js and lib/two.js'); + resultData = JSON.parse(resultData); + test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.'); + test.done(); + }); + }, nospawn: function(test) { test.expect(4); var resultData = '';