Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-contrib-watch

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-contrib-watch - npm Package Compare versions

Comparing version 0.2.0-rc7 to 0.2.0

test/tasks/helper.js

15

package.json
{
"name": "grunt-contrib-watch",
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted.",
"version": "0.2.0rc7",
"version": "0.2.0",
"homepage": "https://github.com/gruntjs/grunt-contrib-watch",

@@ -31,10 +31,13 @@ "author": {

"dependencies": {
"gaze": "~0.3.2"
"gaze": "~0.3.3"
},
"devDependencies": {
"grunt": "0.4.0rc7",
"grunt-contrib-jshint": "0.1.1rc6",
"grunt-contrib-nodeunit": "0.1.2rc6",
"grunt-contrib-internal": "*"
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt-contrib-internal": "~0.4.0"
},
"peerDependencies": {
"grunt": "~0.4.0"
},
"keywords": [

@@ -41,0 +44,0 @@ "gruntplugin",

19

README.md

@@ -6,5 +6,8 @@ # grunt-contrib-watch [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-watch.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-watch)

## Getting Started
If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide, as it explains how to create a [gruntfile][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
This plugin requires Grunt `~0.4.0`
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
```shell

@@ -14,12 +17,15 @@ npm install grunt-contrib-watch --save-dev

[grunt]: http://gruntjs.com/
[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
```js
grunt.loadNpmTasks('grunt-contrib-watch');
```
## Watch task
_Run this task with the `grunt watch` command._
### Overview
Inside your `Gruntfile.js` file, add a section named `watch`. This section specifies the files to watch, tasks to run when an event occurs and the options used.
### Settings

@@ -132,2 +138,3 @@

* 2013-02-14   v0.2.0   First official release for Grunt 0.4.0.
* 2013-01-17   v0.2.0rc7   Updating grunt/gruntplugin dependencies to rc6. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.

@@ -146,2 +153,2 @@ * 2013-01-08   v0.2.0rc5   Updating to work with grunt v0.4.0rc5.

*This file was generated on Tue Jan 22 2013 12:59:24.*
*This file was generated on Mon Feb 18 2013 09:00:52.*

@@ -85,2 +85,3 @@ /*

// Spawn the tasks as a child process
var start = Date.now();
spawned[i] = grunt.util.spawn({

@@ -96,3 +97,9 @@ // Spawn with the grunt bin

delete spawned[i];
grunt.log.writeln('').write(waiting);
var msg = String(
'Completed in ' +
Number((Date.now() - start) / 1000).toFixed(2) +
's at ' +
(new Date()).toString()
).cyan;
grunt.log.writeln('').write(msg + ' - ' + waiting);
});

@@ -106,5 +113,8 @@ }

}
// Get patterns to glob for this target
var patterns = grunt.file.expand(target.files);
// Process into raw patterns
var patterns = grunt.util._.chain(target.files).flatten().map(function(pattern) {
return grunt.config.process(pattern);
}).value();
// Default options per target

@@ -111,0 +121,0 @@ var options = grunt.util._.defaults(target.options || {}, defaults);

@@ -6,93 +6,11 @@ 'use strict';

var fs = require('fs');
var helper = require('./helper');
// Where our fixtures are
var fixtures = path.join(__dirname, '..', 'fixtures');
var fixtures = helper.fixtures;
// If verbose flag set, display output
var verboseLog = function() {};
if (grunt.util._.indexOf(process.argv, '-v') !== -1) {
verboseLog = function() { console.log.apply(null, arguments); };
}
// helper for creating assertTasks for testing tasks in child processes
function assertTask(task, options) {
var spawn = require('child_process').spawn;
task = task || 'default';
options = options || {};
// get next/kill process trigger
var trigger = options.trigger || 'Waiting...';
delete options.trigger;
// CWD to spawn
var cwd = options.cwd || process.cwd();
delete options.cwd;
// Use grunt this process uses
var spawnOptions = [process.argv[1]];
// Turn options into spawn options
grunt.util._.each(options, function(val, key) {
spawnOptions.push('--' + key);
spawnOptions.push(val);
});
// Add the tasks to run
spawnOptions.push(task);
// Return an interface for testing this task
function returnFunc(runs, done) {
// Spawn the node this process uses
var spawnGrunt = spawn(process.argv[0], spawnOptions, {cwd:cwd});
var out = '';
if (!grunt.util._.isArray(runs)) {
runs = [runs];
}
// Append a last function to kill spawnGrunt
runs.push(function() { spawnGrunt.kill('SIGINT'); });
// After watch starts waiting, run our commands then exit
spawnGrunt.stdout.on('data', function(data) {
data = grunt.log.uncolor(String(data));
out += data;
// If we should run the next function
var shouldRun = true;
// If our trigger has been found
if (trigger !== false) {
shouldRun = (grunt.util._.indexOf(data.split("\n"), trigger) !== -1);
}
// Run the function
if (shouldRun) {
setTimeout(function() {
var run = runs.shift();
if (typeof run === 'function') { run(); }
}, 500);
}
});
// Throw errors for better testing
spawnGrunt.stderr.on('data', function(data) {
throw new Error(data);
});
// On process exit return what has been outputted
spawnGrunt.on('exit', function() {
done(out);
});
}
returnFunc.options = options;
return returnFunc;
}
// clean up before and after
function cleanUp() {
[
path.join(fixtures, 'multiTargets', 'node_modules'),
path.join(fixtures, 'oneTarget', 'node_modules'),
].forEach(function(filepath) {
if (grunt.file.exists(filepath)) { grunt.file.delete(filepath); }
});
helper.cleanUp([
'multiTargets/node_modules',
'oneTarget/node_modules'
]);
}

@@ -114,3 +32,3 @@

var cwd = path.resolve(fixtures, 'oneTarget');
var assertWatch = assertTask('watch', {cwd:cwd});
var assertWatch = helper.assertTask('watch', {cwd:cwd});
assertWatch(function() {

@@ -120,3 +38,3 @@ var write = 'var test = true;';

}, function(result) {
verboseLog(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.');

@@ -130,3 +48,3 @@ test.ok(result.indexOf('I do absolutely nothing.') !== -1, 'echo task should have fired.');

var cwd = path.resolve(fixtures, 'multiTargets');
var assertWatch = assertTask('watch', {cwd:cwd});
var assertWatch = helper.assertTask('watch', {cwd:cwd});
assertWatch(function() {

@@ -136,3 +54,3 @@ var write = 'var test = true;';

}, function(result) {
verboseLog(result);
helper.verboseLog(result);
test.ok(result.indexOf('one has changed') !== -1, 'Only task echo:one should of emit.');

@@ -146,3 +64,3 @@ test.ok(result.indexOf('two has changed') === -1, 'Task echo:two should NOT emit.');

var cwd = path.resolve(fixtures, 'multiTargets');
var assertWatch = assertTask('watch', {cwd:cwd});
var assertWatch = helper.assertTask('watch', {cwd:cwd});
assertWatch([function() {

@@ -153,3 +71,3 @@ grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var test = true;');

}], function(result) {
verboseLog(result);
helper.verboseLog(result);
test.ok(result.indexOf('one has changed') !== -1, 'Task echo:one should of emit.');

@@ -163,3 +81,3 @@ test.ok(result.indexOf('two has changed') !== -1, 'Task echo:two should of emit.');

var cwd = path.resolve(fixtures, 'multiTargets');
var assertWatch = assertTask('watch', {cwd:cwd});
var assertWatch = helper.assertTask('watch', {cwd:cwd});
assertWatch(function() {

@@ -171,3 +89,3 @@ grunt.file.write(path.join(cwd, 'lib', 'wait.js'), 'var wait = false;');

}, function(result) {
verboseLog(result);
helper.verboseLog(result);
test.ok(result.indexOf('I waited 2s') !== -1, 'Task should have waited 2s and only spawned once.');

@@ -180,3 +98,3 @@ test.done();

var cwd = path.resolve(fixtures, 'multiTargets');
var assertWatch = assertTask('watch', {cwd:cwd});
var assertWatch = helper.assertTask('watch', {cwd:cwd});
assertWatch(function() {

@@ -188,3 +106,3 @@ grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = false;');

}, function(result) {
verboseLog(result);
helper.verboseLog(result);
test.ok(result.indexOf('has been interrupted') !== -1, 'Task should have been interrupted.');

@@ -197,7 +115,7 @@ test.done();

var cwd = path.resolve(fixtures, 'multiTargets');
var assertWatch = assertTask('watch', {cwd:cwd});
var assertWatch = helper.assertTask('watch', {cwd:cwd});
assertWatch(function() {
grunt.file.write(path.join(cwd, 'lib', 'fail.js'), 'var fail = false;');
}, function(result) {
verboseLog(result);
helper.verboseLog(result);
test.ok(result.toLowerCase().indexOf('fatal') !== -1, 'Task should have been fatal.');

@@ -204,0 +122,0 @@ test.equal(grunt.util._(result).count('Waiting...'), 2, 'Should have displayed "Wating..." twice');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc