Merge branch 'master' into add-hostname-option

Conflicts:
	test/tasks/livereload_test.js
This commit is contained in:
Tim Kang 2015-02-20 20:44:23 -08:00
commit 70f142b9a0
15 changed files with 117 additions and 72 deletions

3
.jscsrc Normal file
View File

@ -0,0 +1,3 @@
{
"preset": "grunt"
}

View File

@ -1,8 +1,6 @@
sudo: false
language: node_js
node_js:
- "0.8"
- "0.10"
install:
- npm install npm@1.4 -g
- npm install -g grunt-cli
- npm install
- 'iojs'
- '0.12'
- '0.10'

View File

@ -2,7 +2,7 @@
* grunt-contrib-watch
* http://gruntjs.com/
*
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/
@ -20,6 +20,12 @@ module.exports = function(grunt) {
jshintrc: '.jshintrc',
},
},
jscs: {
src: ['tasks/**/*.js', 'test/tasks/**/*.js'],
options: {
config: '.jscsrc'
}
},
watch: {
all: {
files: ['<%= jshint.all %>'],
@ -33,6 +39,8 @@ module.exports = function(grunt) {
// Dynamic alias task to nodeunit. Run individual tests with: grunt test:events
grunt.registerTask('test', function(file) {
grunt.task.run('jshint');
grunt.task.run('jscs');
grunt.config('nodeunit.tests', String(grunt.config('nodeunit.tests')).replace('*', file || '*'));
grunt.task.run('nodeunit');
});
@ -42,7 +50,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-internal');
grunt.loadNpmTasks('grunt-jscs');
grunt.registerTask('test', ['jshint', 'nodeunit']);
grunt.registerTask('default', ['test', 'build-contrib']);
};

View File

@ -198,6 +198,9 @@ Default: `process.cwd()`
Ability to set the current working directory. Defaults to `process.cwd()`. Can either be a string to set the cwd to match files and spawn tasks. Or an object to set each independently. Such as `options: { cwd: { files: 'match/files/from/here', spawn: 'but/spawn/files/from/here' } }`.
Set `options: { cwd: { files: 'a/path', event: 'a/path' }}` to strip off `a/path` before emitting events. This option is useful for specifying the base directory to use with livereload.
## options.livereloadOnError
Type: `Boolean`
Default: `true`

View File

@ -1,19 +1,12 @@
{
"name": "grunt-contrib-watch",
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted.",
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted",
"version": "0.6.1",
"homepage": "https://github.com/gruntjs/grunt-contrib-watch",
"author": {
"name": "Grunt Team",
"url": "http://gruntjs.com/"
},
"repository": {
"type": "git",
"url": "git://github.com/gruntjs/grunt-contrib-watch.git"
},
"bugs": {
"url": "https://github.com/gruntjs/grunt-contrib-watch/issues"
},
"repository": "gruntjs/grunt-contrib-watch",
"licenses": [
{
"type": "MIT",
@ -21,33 +14,35 @@
}
],
"engines": {
"node": ">= 0.8.0"
"node": ">=0.10.0"
},
"scripts": {
"test": "grunt test -v"
},
"dependencies": {
"gaze": "~0.5.1",
"tiny-lr": "~0.1.4",
"lodash": "~2.4.1",
"async": "~0.9.0"
"gaze": "^0.5.1",
"tiny-lr": "^0.1.4",
"lodash": "^2.4.1",
"async": "^0.9.0"
},
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-internal": "~0.4.7",
"underscore.string": "~2.3.3"
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-internal": "^0.4.7",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-jscs": "^1.0.0",
"underscore.string": "^2.3.3"
},
"peerDependencies": {
"grunt": "~0.4.0"
"grunt": ">=0.4.0"
},
"keywords": [
"gruntplugin",
"watch"
"watch",
"livereload"
],
"files": [
"tasks",
"LICENSE-MIT"
"tasks"
]
}

View File

@ -2,7 +2,7 @@
* grunt-contrib-watch
* http://gruntjs.com/
*
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/
@ -16,7 +16,7 @@ var servers = Object.create(null);
module.exports = function(grunt) {
var defaults = { port: 35729 };
var defaults = {port: 35729};
function LR(options) {
if (options === true) {

View File

@ -32,7 +32,7 @@ module.exports = function(grunt) {
}
}
var getErrorCount = function(){
var getErrorCount = function() {
if (typeof grunt.fail.forever_warncount !== 'undefined') {
return grunt.fail.forever_warncount + grunt.fail.forever_errorcount;
} else {

View File

@ -2,7 +2,7 @@
* grunt-contrib-watch
* http://gruntjs.com/
*
* Copyright (c) 2014 "Cowboy" Ben Alman, contributors
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/
@ -61,7 +61,7 @@ module.exports = function(grunt) {
// Normalize cwd option
if (typeof self.options.cwd === 'string') {
self.options.cwd = { files: self.options.cwd, spawn: self.options.cwd };
self.options.cwd = {files: self.options.cwd, spawn: self.options.cwd};
}
// Function to call when closing the task

View File

@ -95,6 +95,11 @@ module.exports = function(grunt) {
target.options.event = [target.options.event];
}
var eventCwd = process.cwd();
if (target.options.cwd && target.options.cwd.event) {
eventCwd = target.options.cwd.event;
}
// Set cwd if options.cwd.file is set
if (typeof target.options.cwd !== 'string' && target.options.cwd.files) {
target.options.cwd = target.options.cwd.files;
@ -128,7 +133,7 @@ module.exports = function(grunt) {
return;
}
filepath = path.relative(process.cwd(), filepath);
filepath = path.relative(eventCwd, filepath);
// Skip empty filepaths
if (filepath === '') {

View File

@ -2,7 +2,7 @@
* grunt-contrib-watch
* http://gruntjs.com/
*
* Copyright (c) 2012 "Cowboy" Ben Alman, contributors
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/

View File

@ -44,9 +44,12 @@ exports.events = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event not emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, 'event not emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event not emitted when file deleted');
test.ok(result.indexOf('lib/added.js was indeed added') !== -1,
'event not emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') !== -1,
'event not emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1,
'event not emitted when file deleted');
test.done();
});
},
@ -59,9 +62,12 @@ exports.events = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event not emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, 'event should NOT have emitted when file deleted');
test.ok(result.indexOf('lib/added.js was indeed added') !== -1,
'event not emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') === -1,
'event should NOT have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') === -1,
'event should NOT have emitted when file deleted');
test.done();
});
},
@ -74,9 +80,12 @@ exports.events = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('lib/added.js was indeed added') === -1, 'event should NOT have emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, 'event should have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, 'event should NOT have emitted when file deleted');
test.ok(result.indexOf('lib/added.js was indeed added') === -1,
'event should NOT have emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') !== -1,
'event should have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') === -1,
'event should NOT have emitted when file deleted');
test.done();
});
},
@ -89,9 +98,12 @@ exports.events = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('lib/added.js was indeed added') === -1, 'event should NOT have emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event should have emitted when file deleted');
test.ok(result.indexOf('lib/added.js was indeed added') === -1,
'event should NOT have emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') === -1,
'event should NOT have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1,
'event should have emitted when file deleted');
test.done();
});
},
@ -104,9 +116,13 @@ exports.events = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event should have emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event should have emitted when file deleted');
test.ok(result.indexOf('lib/added.js was indeed added') !== -1,
'event should have emitted when file added');
test.ok(result.indexOf('lib/one.js was indeed changed') === -1,
'event should NOT have emitted when file changed');
test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1,
'event should have emitted when file deleted');
test.done();
});
},
@ -125,8 +141,10 @@ exports.events = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('lib/one/test.js was indeed changed\ntargetOne specifc event was fired') !== -1, 'event should have been emitted with targetOne specified');
test.ok(result.indexOf('lib/two/test.js was indeed changed\ntargetTwo specifc event was fired') !== -1, 'event should have been emitted with targetTwo specified');
test.ok(result.indexOf('lib/one/test.js was indeed changed\ntargetOne specifc event was fired') !== -1,
'event should have been emitted with targetOne specified');
test.ok(result.indexOf('lib/two/test.js was indeed changed\ntargetTwo specifc event was fired') !== -1,
'event should have been emitted with targetTwo specified');
test.done();
});
},

View File

@ -90,7 +90,7 @@ helper.assertTask = function assertTask(task, options) {
// clean up files within fixtures
helper.cleanUp = function cleanUp(files) {
if (typeof files === 'string') files = [files];
if (typeof files === 'string') { files = [files]; }
files.forEach(function(filepath) {
filepath = path.join(helper.fixtures, filepath);
if (grunt.file.exists(filepath)) {

View File

@ -56,7 +56,8 @@ exports.livereload = {
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 :35729') !== -1, 'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reload server started on :35729') !== -1,
'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
resultData = JSON.parse(resultData);
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
@ -77,7 +78,8 @@ exports.livereload = {
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 localhost:8675') !== -1, 'live reload server should have been started on localhost:8675.');
test.ok(result.indexOf('Live reload server started on localhost:8675') !== -1,
'live reload server should have been started on localhost:8675.');
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
resultData = JSON.parse(resultData);
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
@ -97,7 +99,8 @@ exports.livereload = {
helper.verboseLog(result);
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
test.ok(result.indexOf('Live reloading lib/two.js...') !== -1, 'live reload should have triggered on lib/two.js');
test.ok(!/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), 'live reload should have cleared js file that was already reloaded');
test.ok(!/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result),
'live reload should have cleared js file that was already reloaded');
test.done();
});
},
@ -116,8 +119,10 @@ exports.livereload = {
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 :9876') !== -1, 'live reload server should have been started on port 9876.');
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');
test.ok(result.indexOf('Live reload server started on :9876') !== -1,
'live reload server should have been started on port 9876.');
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();
@ -137,7 +142,8 @@ exports.livereload = {
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 :1337') !== -1, 'live reload server should have been started on port 1337.');
test.ok(result.indexOf('Live reload server started on :1337') !== -1,
'live reload server should have been started on port 1337.');
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
resultData = JSON.parse(resultData);
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
@ -157,7 +163,8 @@ exports.livereload = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('Live reload server started on :35729') !== -1, 'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reload server started on :35729') !== -1,
'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
resultData = JSON.parse(resultData);
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
@ -175,8 +182,10 @@ exports.livereload = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('Live reloading sass/one.scss') === -1, 'Should not trigger live reload on non livereload targets.');
test.ok(result.indexOf('Live reloading css/one.css') !== -1, 'Should trigger live reload when other tasks trigger livereload targets.');
test.ok(result.indexOf('Live reloading sass/one.scss') === -1,
'Should not trigger live reload on non livereload targets.');
test.ok(result.indexOf('Live reloading css/one.css') !== -1,
'Should trigger live reload when other tasks trigger livereload targets.');
test.done();
});
},
@ -206,7 +215,8 @@ exports.livereload = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('Live reloading lib/one.js...') === -1, 'Should not livereload when a task errors with flag');
test.ok(result.indexOf('Live reloading lib/one.js...') === -1,
'Should not livereload when a task errors with flag');
test.done();
});
},
@ -221,7 +231,8 @@ exports.livereload = {
}], function(result) {
result = helper.unixify(result);
helper.verboseLog(result);
test.ok(result.indexOf('Live reloading lib/one.js...') === -1, 'Should not livereload when a task errors with flag and spawn=false');
test.ok(result.indexOf('Live reloading lib/one.js...') === -1,
'Should not livereload when a task errors with flag and spawn=false');
test.done();
});
},

View File

@ -34,8 +34,10 @@ exports.patterns = {
}, 3000);
}, function(result) {
helper.verboseLog(result);
test.ok(result.indexOf('File "lib' + path.sep + 'edit.js" changed') !== -1, 'Watch should have been triggered when edit.js was edited.');
test.ok(result.indexOf('File "lib' + path.sep + 'dontedit.js" changed') === -1, 'Watch should NOT have been triggered when dontedit.js was edited.');
test.ok(result.indexOf('File "lib' + path.sep + 'edit.js" changed') !== -1,
'Watch should have been triggered when edit.js was edited.');
test.ok(result.indexOf('File "lib' + path.sep + 'dontedit.js" changed') === -1,
'Watch should NOT have been triggered when dontedit.js was edited.');
test.done();
});
},

View File

@ -45,7 +45,7 @@ exports.watch = {
var cwd = path.resolve(fixtures, 'dateFormat');
var assertWatch = helper.assertTask(['watch', '--debug'], {cwd:cwd});
assertWatch(function() {
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;');
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;');
}, function(result) {
helper.verboseLog(result);
test.ok(result.indexOf('dateFormat has worked!') !== -1, 'Should have displayed a custom dateFormat.');
@ -61,7 +61,8 @@ exports.watch = {
grunt.file.write(path.join(cwd, 'lib', 'one.js'), write);
}, function(result) {
helper.verboseLog(result);
test.ok(result.indexOf('File "lib' + path.sep + 'one.js" changed') !== -1, 'Watch should have fired when oneTarget/lib/one.js has changed.');
test.ok(result.indexOf('File "lib' + path.sep + 'one.js" changed') !== -1,
'Watch should have fired when oneTarget/lib/one.js has changed.');
test.ok(result.indexOf('I do absolutely nothing.') !== -1, 'echo task should have fired.');
test.done();
});
@ -141,7 +142,8 @@ exports.watch = {
var interruptMatches = result.match(/have been interrupted/g);
test.ok(interruptMatches && interruptMatches.length === 2, 'Task should have been interrupted 2 times.');
var unInterruptMatches = result.match(/I want to be interrupted/g);
test.ok(unInterruptMatches && unInterruptMatches.length === 1, 'Only the last time should be working (without interruption)');
test.ok(unInterruptMatches && unInterruptMatches.length === 1,
'Only the last time should be working (without interruption)');
test.done();
});
},