Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add `ignored` option, refactor tests #2

Merged
merged 4 commits into from

2 participants

@paulmillr
  • Added option ignored. Syntax: ignored: /^\./ or ignored: (file) -> check(file)
  • Use cross-platform paths in tests
  • Test runner is now non-shitty, it's mocha instead of nodeunit which allowed to greatly DRY code.

@TrevorBurnham

Pretty epic pull request. I like it.

@TrevorBurnham TrevorBurnham merged commit f403fc1 into TrevorBurnham:master
@paulmillr

@TrevorBurnham btw -- could you please prepare new release so we can use it from npm?

I'm trying to replace @brunch watcher by watchit and it seems to work perfectly.

@TrevorBurnham

Sure, version has been bumped to 0.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 9, 2012
  1. @paulmillr

    Remove npm debug log.

    paulmillr authored
  2. @paulmillr
Commits on Apr 10, 2012
  1. @paulmillr
  2. @paulmillr
This page is out of date. Refresh to see the latest.
View
3  README.mdown
@@ -92,6 +92,9 @@ In addition, watchit itself is a new project, and the test suites are
incomplete. If you run into any problems that you can replicate in a small
test case, please don't hesitate to report them.
+## Contributing
+Run tests via `./node_modules/.bin/mocha --compilers coffee:coffee-script --require test/common.js --colors --reporter spec`.
+
## License
http://trevorburnham.mit-license.org
View
28 lib/watchit.js
@@ -15,18 +15,30 @@
debounce: false,
include: false,
recurse: false,
- persistent: true
+ persistent: true,
+ ignored: null
};
watchit = function(target, options, callback) {
- var emitter, fswatcher, retainTarget, scanTargetDir, unwatchTarget, watchTarget, watchTargetDir, watchTargetFile, _ref, _ref2;
+ var emitter, fswatcher, ignored, retainTarget, scanTargetDir, unwatchTarget, watchTarget, watchTargetDir, watchTargetFile, _ref;
if (typeof options === 'function') {
callback = options;
options = {};
}
options = extend({}, defaults, options != null ? options : {});
+ ignored = function(file) {
+ if (options.ignored) {
+ if (typeof options.ignored.test === 'function') {
+ return options.ignored.test(file);
+ } else {
+ return options.ignored(file);
+ }
+ } else {
+ return false;
+ }
+ };
emitter = options.emitter = (_ref = options.emitter) != null ? _ref : new WatchitEmitter(callback);
- if ((_ref2 = emitter.targets) == null) emitter.targets = {};
+ if (emitter.targets == null) emitter.targets = {};
if (emitter.targets[target]) return null;
fswatcher = null;
emitter.close = function() {
@@ -133,7 +145,9 @@
item = items[_i];
_results.push((function(item) {
var itemPath;
- return fs.stat(itemPath = path.join(target, item), function(err, stats) {
+ if (ignored(item)) return;
+ itemPath = path.join(target, item);
+ return fs.stat(itemPath, function(err, stats) {
var isDir;
if (err) return;
isDir = stats.isDirectory();
@@ -153,9 +167,9 @@
return emitter;
};
- WatchitEmitter = (function() {
+ WatchitEmitter = (function(_super) {
- __extends(WatchitEmitter, EventEmitter);
+ __extends(WatchitEmitter, _super);
function WatchitEmitter(callback) {
this.callback = callback;
@@ -172,7 +186,7 @@
return WatchitEmitter;
- })();
+ })(EventEmitter);
extend = function() {
var obj, prop, source, sources, _i, _len;
View
271 npm-debug.log
@@ -1,271 +0,0 @@
-info it worked if it ends with ok
-verbose cli [ 'node', '/usr/local/bin/npm', 'publish' ]
-info using npm@1.0.105
-info using node@v0.6.2
-verbose /usr/local/bin/node node symlink
-verbose config file /Users/trevor/.npmrc
-verbose config file /usr/local/etc/npmrc
-verbose config file /usr/local/lib/node_modules/npm/npmrc
-verbose publish [ '.' ]
-silly testEngine { author: { name: 'Trevor Burnham', url: 'http://trevorburnham.com' },
-silly testEngine name: 'watchit',
-silly testEngine description: 'A sensible wrapper around fs.watch',
-silly testEngine version: '0.0.1',
-silly testEngine engines: { node: '>=0.6.1' },
-silly testEngine homepage: 'http://github.com/TrevorBurnham/Watchit',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/TrevorBurnham/Watchit.git' },
-silly testEngine main: 'lib/watchit.js',
-silly testEngine devDependencies: { 'coffee-script': '1.1.3', nodeunit: '0.6.2', watchit: '0.0.2' },
-silly testEngine _npmUser: { name: 'TrevorBurnham', email: 'trevorburnham@gmail.com' },
-silly testEngine _id: 'watchit@0.0.1',
-silly testEngine dependencies: {},
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.105',
-silly testEngine _nodeVersion: 'v0.6.2',
-silly testEngine _defaultsLoaded: true,
-silly testEngine scripts: {} }
-verbose caching /Users/trevor/Code/watchit/package.json
-verbose loadDefaults watchit@0.0.1
-info prepublish watchit@0.0.1
-verbose cache add [ '.', null ]
-silly cache add: name, spec, args [ undefined, '.', [ '.', null ] ]
-verbose parsed url { pathname: '.', path: '.', href: '.' }
-silly testEngine { author: { name: 'Trevor Burnham', url: 'http://trevorburnham.com' },
-silly testEngine name: 'watchit',
-silly testEngine description: 'A sensible wrapper around fs.watch',
-silly testEngine version: '0.0.1',
-silly testEngine engines: { node: '>=0.6.1' },
-silly testEngine homepage: 'http://github.com/TrevorBurnham/Watchit',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/TrevorBurnham/Watchit.git' },
-silly testEngine main: 'lib/watchit.js',
-silly testEngine devDependencies: { 'coffee-script': '1.1.3', nodeunit: '0.6.2', watchit: '0.0.2' },
-silly testEngine _npmUser: { name: 'TrevorBurnham', email: 'trevorburnham@gmail.com' },
-silly testEngine _id: 'watchit@0.0.1',
-silly testEngine dependencies: {},
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.105',
-silly testEngine _nodeVersion: 'v0.6.2',
-silly testEngine _defaultsLoaded: true,
-silly testEngine path: '/Users/trevor/Code/watchit',
-silly testEngine bundleDependencies: [] }
-verbose caching package.json
-verbose loadDefaults watchit@0.0.1
-verbose pack /Users/trevor/Code/watchit /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/tmp.tgz
-silly makeList /Users/trevor/Code/watchit
-verbose from cache /Users/trevor/Code/watchit/package.json
-verbose mkdir (expected) error ENOENT, no such file or directory '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266'
-verbose mkdir (expected) error ENOENT, no such file or directory '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974'
-verbose mkdir done: /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974 755
-verbose mkdir'ed /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974
-verbose tar about to write tar and gzip it.
-silly tar args [ '-czvf', '-', '-T', '-' ]
-silly spawning [ 'tar', [ '-czvf', '-', '-T', '-' ], '/Users/trevor/Code' ]
-verbose mkdir (expected) error ENOENT, no such file or directory '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents'
-verbose mkdir (expected) error ENOENT, no such file or directory '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm'
-verbose mkdir done: /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm 755
-verbose unpack_ uid, gid [ undefined, undefined ]
-verbose unpackTarget /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package
-silly gunzTarPerm modes [ '755', '644' ]
-silly spawning [ 'tar',
-silly spawning [ '-zmvxpf',
-silly spawning '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/tmp.tgz' ],
-silly spawning '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm' ]
-silly tar err x watchit/.gitignore
-silly tar err x watchit/Cakefile
-silly tar err x watchit/package.json
-silly tar err x watchit/README.mdown
-silly tar err x watchit/test.coffee
-silly tar err x watchit/lib/watchit.js
-silly tar err x watchit/src/watchit.coffee
-silly tar err x watchit/test/debounce.coffee
-silly tar err x watchit/test/helpers.coffee
-silly tar err x watchit/test/include.coffee
-silly tar err x watchit/test/recurse.coffee
-silly tar err x watchit/test/retain.coffee
-silly tar err x watchit/test/fixtures/parent/child.test
-silly tar err x watchit/test/fixtures/chain/1.test
-silly tar err x watchit/test/fixtures/chain/2.test
-silly tar exit 0
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/.gitignore
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/Cakefile
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/package.json
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/README.mdown
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test.coffee
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/lib
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/lib/watchit.js
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/src
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/src/watchit.coffee
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/debounce.coffee
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/helpers.coffee
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/include.coffee
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/recurse.coffee
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/retain.coffee
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/fixtures
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/fixtures/chain
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/fixtures/chain/1.test
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/fixtures/chain/2.test
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/fixtures/parent
-silly asyncMap in gTP /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit/test/fixtures/parent/child.test
-verbose gunzed /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit
-verbose rm'ed /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package
-verbose renamed [ '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/___package.npm/watchit',
-verbose renamed '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package' ]
-silly testEngine { author: { name: 'Trevor Burnham', url: 'http://trevorburnham.com' },
-silly testEngine name: 'watchit',
-silly testEngine description: 'A sensible wrapper around fs.watch',
-silly testEngine version: '0.0.1',
-silly testEngine engines: { node: '>=0.6.1' },
-silly testEngine homepage: 'http://github.com/TrevorBurnham/Watchit',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/TrevorBurnham/Watchit.git' },
-silly testEngine main: 'lib/watchit.js',
-silly testEngine devDependencies: { 'coffee-script': '1.1.3', nodeunit: '0.6.2', watchit: '0.0.2' },
-silly testEngine _npmUser: { name: 'TrevorBurnham', email: 'trevorburnham@gmail.com' },
-silly testEngine _id: 'watchit@0.0.1',
-silly testEngine dependencies: {},
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.105',
-silly testEngine _nodeVersion: 'v0.6.2',
-silly testEngine _defaultsLoaded: true,
-silly testEngine path: '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package' }
-verbose caching /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package/package.json
-verbose loadDefaults watchit@0.0.1
-verbose tarball contents [ 'package' ]
-verbose from cache /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package/package.json
-verbose pack /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package /Users/trevor/.npm/watchit/0.0.1/package.tgz
-silly makeList /var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents/package
-verbose mkdir'ed /Users/trevor/.npm/watchit/0.0.1
-verbose tar about to write tar and gzip it.
-silly tar args [ '-czvf', '-', '-T', '-' ]
-silly spawning [ 'tar',
-silly spawning [ '-czvf', '-', '-T', '-' ],
-silly spawning '/var/folders/zr/t1dlz5r97lb10hvd4crdgtt80000gn/T/npm-1322083609266/1322083609266-0.17785369604825974/contents' ]
-verbose mkdir (expected) error ENOENT, no such file or directory '/Users/trevor/.npm/watchit/0.0.1/___package.npm'
-verbose mkdir done: /Users/trevor/.npm/watchit/0.0.1/___package.npm 755
-verbose unpack_ uid, gid [ undefined, undefined ]
-verbose unpackTarget /Users/trevor/.npm/watchit/0.0.1/package
-silly gunzTarPerm modes [ '755', '644' ]
-silly spawning [ 'tar',
-silly spawning [ '-zmvxpf', '/Users/trevor/.npm/watchit/0.0.1/package.tgz' ],
-silly spawning '/Users/trevor/.npm/watchit/0.0.1/___package.npm' ]
-silly tar err x package/.gitignore
-silly tar err x package/Cakefile
-silly tar err x package/package.json
-silly tar err x package/README.mdown
-silly tar err x package/test.coffee
-silly tar err x package/lib/watchit.js
-silly tar err x package/src/watchit.coffee
-silly tar err x package/test/debounce.coffee
-silly tar err x package/test/helpers.coffee
-silly tar err x package/test/include.coffee
-silly tar err x package/test/recurse.coffee
-silly tar err x package/test/retain.coffee
-silly tar err x package/test/fixtures/chain/1.test
-silly tar err x package/test/fixtures/chain/2.test
-silly tar err x package/test/fixtures/parent/child.test
-silly tar exit 0
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/.gitignore
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/Cakefile
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/package.json
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/README.mdown
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test.coffee
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/lib
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/lib/watchit.js
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/src
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/src/watchit.coffee
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/debounce.coffee
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/helpers.coffee
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/include.coffee
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/recurse.coffee
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/retain.coffee
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/fixtures
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/fixtures/chain
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/fixtures/chain/1.test
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/fixtures/chain/2.test
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/fixtures/parent
-silly asyncMap in gTP /Users/trevor/.npm/watchit/0.0.1/___package.npm/package/test/fixtures/parent/child.test
-verbose gunzed /Users/trevor/.npm/watchit/0.0.1/___package.npm/package
-verbose rm'ed /Users/trevor/.npm/watchit/0.0.1/package
-verbose renamed [ '/Users/trevor/.npm/watchit/0.0.1/___package.npm/package',
-verbose renamed '/Users/trevor/.npm/watchit/0.0.1/package' ]
-silly testEngine { author: { name: 'Trevor Burnham', url: 'http://trevorburnham.com' },
-silly testEngine name: 'watchit',
-silly testEngine description: 'A sensible wrapper around fs.watch',
-silly testEngine version: '0.0.1',
-silly testEngine engines: { node: '>=0.6.1' },
-silly testEngine homepage: 'http://github.com/TrevorBurnham/Watchit',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/TrevorBurnham/Watchit.git' },
-silly testEngine main: 'lib/watchit.js',
-silly testEngine devDependencies: { 'coffee-script': '1.1.3', nodeunit: '0.6.2', watchit: '0.0.2' },
-silly testEngine _npmUser: { name: 'TrevorBurnham', email: 'trevorburnham@gmail.com' },
-silly testEngine _id: 'watchit@0.0.1',
-silly testEngine dependencies: {},
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.105',
-silly testEngine _nodeVersion: 'v0.6.2',
-silly testEngine _defaultsLoaded: true,
-silly testEngine dist:
-silly testEngine { shasum: '98d0abe5e426fc2bbe6edc253f290edebf6a4b8c',
-silly testEngine tarball: 'http://registry.npmjs.org/watchit/-/watchit-0.0.1.tgz' } }
-verbose caching /Users/trevor/.npm/watchit/0.0.1/package/package.json
-verbose loadDefaults watchit@0.0.1
-silly updated sha bytes 10240
-info shasum 98d0abe5e426fc2bbe6edc253f290edebf6a4b8c
-info shasum /Users/trevor/.npm/watchit/0.0.1/package.tgz
-verbose from cache /Users/trevor/.npm/watchit/0.0.1/package/package.json
-verbose chmod /Users/trevor/.npm/watchit/0.0.1/package.tgz 644
-verbose chown [ '/Users/trevor/.npm/watchit/0.0.1/package.tgz', 501, 20 ]
-silly publish { author: { name: 'Trevor Burnham', url: 'http://trevorburnham.com' },
-silly publish name: 'watchit',
-silly publish description: 'A sensible wrapper around fs.watch',
-silly publish version: '0.0.1',
-silly publish engines: { node: '>=0.6.1' },
-silly publish homepage: 'http://github.com/TrevorBurnham/Watchit',
-silly publish repository:
-silly publish { type: 'git',
-silly publish url: 'git://github.com/TrevorBurnham/Watchit.git' },
-silly publish main: 'lib/watchit.js',
-silly publish devDependencies: { 'coffee-script': '1.1.3', nodeunit: '0.6.2', watchit: '0.0.2' },
-silly publish _npmUser: { name: 'TrevorBurnham', email: 'trevorburnham@gmail.com' },
-silly publish _id: 'watchit@0.0.1',
-silly publish dependencies: {},
-silly publish _engineSupported: true,
-silly publish _npmVersion: '1.0.105',
-silly publish _nodeVersion: 'v0.6.2',
-silly publish _defaultsLoaded: true,
-silly publish dist:
-silly publish { shasum: '98d0abe5e426fc2bbe6edc253f290edebf6a4b8c',
-silly publish tarball: 'http://registry.npmjs.org/watchit/-/watchit-0.0.1.tgz' } }
-verbose PUT watchit
-verbose raw, before any munging watchit
-verbose url resolving [ 'https://registry.npmjs.org/', './watchit' ]
-verbose url resolved https://registry.npmjs.org/watchit
-verbose GET watchit
-verbose raw, before any munging watchit
-verbose url resolving [ 'https://registry.npmjs.org/', './watchit' ]
-verbose url resolved https://registry.npmjs.org/watchit
-info Already published watchit@0.0.1
-verbose uploading bin dists []
-ERR! publish fail Cannot publish over existing version.
-ERR! publish fail Bump the 'version' field, set the --force flag, or
-ERR! publish fail npm unpublish 'watchit@0.0.1'
-ERR! publish fail and try again
-ERR!
-ERR! System Darwin 11.2.0
-ERR! command "node" "/usr/local/bin/npm" "publish"
-ERR! cwd /Users/trevor/Code/watchit
-ERR! node -v v0.6.2
-ERR! npm -v 1.0.105
-ERR! code EPUBLISHCONFLICT
-verbose exit [ 1, true ]
View
5 package.json
@@ -14,7 +14,8 @@
"main": "lib/watchit.js",
"devDependencies": {
"coffee-script": "1.1.3",
- "nodeunit": "0.6.2",
- "watchit": "0.0.2"
+ "watchit": "0.0.2",
+ "mocha": "1.0.1",
+ "expect.js": "0.1.2"
}
}
View
17 src/watchit.coffee
@@ -15,12 +15,15 @@ path = require 'path'
# subdirectories will also be counted as targets.
# * `persistent` is identical to `fs.watch`'s `persistent` option. If
# disabled, the process may exit while files are being watched.
+# * `ignore` could contain RegExp pattern or function against which
+# added files will be tested.
defaults =
retain: false
debounce: false
include: false
recurse: false
persistent: true
+ ignored: null
# ## Main function
watchit = (target, options, callback) ->
@@ -31,6 +34,16 @@ watchit = (target, options, callback) ->
options = extend {}, defaults, options ? {}
+ # Generic function that will check if some file is ignored.
+ ignored = (file) ->
+ if options.ignored
+ if typeof options.ignored.test is 'function'
+ options.ignored.test(file)
+ else
+ options.ignored(file)
+ else
+ no
+
# `emitter` will be returned from the function; it emits "change", "create",
# and "unlink" events. It also emits "success" and "failure" events the
# first time a target is found or not found, respectively.
@@ -128,7 +141,9 @@ watchit = (target, options, callback) ->
return if err
for item in items
do (item) ->
- fs.stat itemPath = path.join(target, item), (err, stats) ->
+ return if ignored item
+ itemPath = path.join(target, item)
+ fs.stat itemPath, (err, stats) ->
return if err
isDir = stats.isDirectory()
if (isDir and options.recurse) or (!isDir and options.include)
View
12 test/common.coffee
@@ -0,0 +1,12 @@
+path = require 'path'
+
+global.expect = require 'expect.js'
+global.delay = (time, func) ->
+ unless func?
+ func = time
+ time = 50
+ setTimeout func, time
+global.fixture = (pathes...) -> path.join __dirname, 'fixtures', pathes...
+global.watchit = watchit = require '../src/watchit'
+global.conditionalTimeout = watchit.conditionalTimeout
+global.notifyWhenExists = watchit.notifyWhenExists
View
26 test/common.js
@@ -0,0 +1,26 @@
+var path, watchit,
+ __slice = Array.prototype.slice;
+
+path = require('path');
+
+global.expect = require('expect.js');
+
+global.delay = function(time, func) {
+ if (func == null) {
+ func = time;
+ time = 50;
+ }
+ return setTimeout(func, time);
+};
+
+global.fixture = function() {
+ var pathes;
+ pathes = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ return path.join.apply(path, [__dirname, 'fixtures'].concat(__slice.call(pathes)));
+};
+
+global.watchit = watchit = require('../lib/watchit');
+
+global.conditionalTimeout = watchit.conditionalTimeout;
+
+global.notifyWhenExists = watchit.notifyWhenExists;
View
32 test/debounce.coffee
@@ -1,19 +1,21 @@
-watchit = require '../src/watchit'
-fs = require 'fs'
+fs = require 'fs'
+path = require 'path'
-delay = (func) -> setTimeout func, 50
+describe 'watchit', ->
+ describe 'options.debounce', ->
+ it 'should group changes together by debouncing', (done) ->
+ changeCount = 0
-exports['watchit can group changes together by debouncing'] = (test) ->
- changeCount = 0
+ file = fixture 'deb.test'
+ fs.writeFileSync file, ''
+ emitter = watchit file, debounce: true
+ emitter.on 'change', -> changeCount++
- emitter = watchit 'fixtures/deb.test', debounce: true
- emitter.on 'change', -> changeCount++
+ delay ->
+ for i in [0..500] by 10
+ setTimeout (-> fs.writeFileSync file, "#{i}"), i
- delay ->
- for i in [0..500] by 10
- setTimeout (-> fs.writeFileSync 'fixtures/deb.test', "#{i}"), i
-
- setTimeout (->
- test.equal 1, changeCount
- test.done()
- ), 1050
+ setTimeout ->
+ expect(changeCount).to.be(1)
+ done()
+ , 1050
View
86 test/helpers.coffee
@@ -1,44 +1,50 @@
-{conditionalTimeout, notifyWhenExists} = require '../src/watchit'
-fs = require 'fs'
+fs = require 'fs'
+path = require 'path'
-delay = (func) -> setTimeout func, 20
+describe 'helpers', ->
+ describe 'conditionalTimeout', ->
+ it 'can be used to debounce a function', (done) ->
+ callCount = 0
+ conditionalTimeout 'foo', 10, -> callCount++
+ conditionalTimeout 'foo', 10, -> callCount++
+ conditionalTimeout 'foo', 10, -> callCount++
+ delay 20, ->
+ expect(callCount).to.be(1)
+ done()
-exports['conditionalTimeout can be used to debounce a function'] = (test) ->
- callCount = 0
- conditionalTimeout 'foo', 10, -> callCount++
- conditionalTimeout 'foo', 10, -> callCount++
- conditionalTimeout 'foo', 10, -> callCount++
- delay ->
- test.equal callCount, 1
- test.done()
+ describe 'notifyWhenExists', ->
+ it 'should call back if the target already exists', (done) ->
+ file = fixture 'a.test'
+ fs.writeFileSync file, ''
+ notifyWhenExists file, ->
+ fs.unlinkSync file
+ done()
-exports['notifyWhenExists calls back if the target already exists'] = (test) ->
- fs.writeFileSync 'fixtures/a.test', ''
- notifyWhenExists 'fixtures/a.test', ->
- fs.unlinkSync 'fixtures/a.test'
- test.done()
+ it 'should not call back before target exists', (done) ->
+ exists = no
+ file = fixture 'b.test'
+ try
+ fs.unlinkSync file
+ delay 20, ->
+ fs.writeFileSync file, ''
+ exists = yes
+ notifyWhenExists file, ->
+ expect(exists).to.be(yes)
+ done()
-exports['notifyWhenExists does not call back before target exists'] = (test) ->
- exists = false
- try
- fs.unlinkSync 'fixtures/b.test'
- delay ->
- fs.writeFileSync('fixtures/b.test', '')
- exists = true
- notifyWhenExists 'fixtures/b.test', ->
- test.equal true, exists
- test.done()
-
-exports['notifyWhenExists works if target has no parent dir'] = (test) ->
- exists = false
- try
- fs.unlinkSync 'fixtures/parent/child.test'
- try
- fs.rmdirSync 'fixtures/parent'
- delay ->
- fs.mkdirSync 'fixtures/parent'
- fs.writeFileSync 'fixtures/parent/child.test', ''
- exists = true
- notifyWhenExists 'fixtures/parent/child.test', ->
- test.equal true, exists
- test.done()
+ it 'should work if target has no parent dir', (done) ->
+ exists = no
+ parent = fixture 'parent'
+ child = fixture 'parent', 'child.test'
+ file = fixture 'parent', 'child.test'
+ try
+ fs.unlinkSync parent
+ try
+ fs.rmdirSync parent
+ delay 40, ->
+ fs.mkdirSync parent
+ fs.writeFileSync child, ''
+ exists = yes
+ notifyWhenExists child, ->
+ expect(exists).to.be(yes)
+ done()
View
19 test/ignored.coffee
@@ -0,0 +1,19 @@
+fs = require 'fs'
+path = require 'path'
+
+describe 'watchit', ->
+ describe 'options.ignored', ->
+ it 'should not watch ignored files', (done) ->
+ changed = no
+ options = {ignored: /^\./, include: yes, recurse: yes}
+ watcher = watchit 'fixtures', options, (event, file) ->
+ return unless event in ['create', 'unlink', 'change']
+ changed = yes
+ fs.writeFileSync fixture '.meh'
+ delay ->
+ expect(changed).to.be(no)
+ fs.unlinkSync fixture '.meh'
+ delay ->
+ expect(changed).to.be(no)
+ watcher.close()
+ done()
View
70 test/include.coffee
@@ -1,42 +1,42 @@
-watchit = require '../src/watchit'
-fs = require 'fs'
+fs = require 'fs'
+path = require 'path'
-delay = (func) -> setTimeout func, 50
+describe 'watchit', ->
+ describe 'options.ignored', ->
+ it 'should monitor several children', (done) ->
+ try
+ fs.mkdirSync fixture 'musketeers'
+ try
+ fs.writeFileSync (fixture 'musketeers', 'Athos.test'), ''
+ try
+ fs.unlinkSync fixture 'musketeers', 'Porthos.test'
+ try
+ fs.unlinkSync fixture 'musketeers', 'Aramis.test'
-exports['watchit can monitor several children'] = (test) ->
- try
- fs.mkdirSync 'fixtures/musketeers'
- try
- fs.writeFileSync 'fixtures/musketeers/Athos.test', ''
- try
- fs.unlinkSync 'fixtures/musketeers/Porthos.test'
- try
- fs.unlinkSync 'fixtures/musketeers/Aramis.test'
+ changeCount = 0
+ createCount = 0
+ unlinkCount = 0
- changeCount = 0
- createCount = 0
- unlinkCount = 0
+ emitter = watchit (fixture 'musketeers'), include: yes
+ emitter.on 'change', -> changeCount++
+ emitter.on 'create', -> createCount++
+ emitter.on 'unlink', -> unlinkCount++
- emitter = watchit 'fixtures/musketeers', include: true
- emitter.on 'change', -> changeCount++
- emitter.on 'create', -> createCount++
- emitter.on 'unlink', -> unlinkCount++
-
- delay ->
- fs.writeFileSync 'fixtures/musketeers/Porthos.test', ''
- delay ->
- test.equal 1, createCount, '1 file created'
- fs.writeFileSync 'fixtures/musketeers/Athos.test', 'All for one!'
delay ->
- test.equal 1, changeCount, '1 file changed'
- fs.writeFileSync 'fixtures/musketeers/Aramis.test', ''
+ fs.writeFileSync (fixture 'musketeers', 'Porthos.test'), ''
delay ->
- test.equal 2, createCount, '2 files created'
- fs.unlinkSync 'fixtures/musketeers/Athos.test'
- fs.unlinkSync 'fixtures/musketeers/Porthos.test'
- fs.unlinkSync 'fixtures/musketeers/Aramis.test'
+ expect(createCount).to.be(1)
+ fs.writeFileSync (fixture 'musketeers', 'Athos.test'), 'All for one!'
delay ->
- test.equal 1, changeCount, '1 file changed (still)'
- test.equal 2, createCount, '2 files created (still)'
- test.equal 3, unlinkCount, '3 files unlinked'
- test.done()
+ expect(changeCount).to.be(1)
+ fs.writeFileSync (fixture 'musketeers', 'Aramis.test'), ''
+ delay ->
+ expect(createCount).to.be(2)
+ fs.unlinkSync fixture 'musketeers', 'Athos.test'
+ fs.unlinkSync fixture 'musketeers', 'Porthos.test'
+ fs.unlinkSync fixture 'musketeers', 'Aramis.test'
+ delay ->
+ expect(changeCount).to.be(1)
+ expect(createCount).to.be(2)
+ expect(unlinkCount).to.be(3)
+ done()
View
57 test/retain.coffee
@@ -1,32 +1,33 @@
-watchit = require '../src/watchit'
-fs = require 'fs'
+fs = require 'fs'
+path = require 'path'
-delay = (func) -> setTimeout func, 50
+describe 'watchit', ->
+ describe 'options.retain', ->
+ it 'should emit create, unlink, and change events', (done) ->
+ file = fixture 'a.test'
+ try
+ fs.unlinkSync file
-exports['watchit emits create, unlink, and change events'] = (test) ->
- try
- fs.unlinkSync 'fixtures/a.test'
+ changeCount = 0
+ createCount = 0
+ unlinkCount = 0
- changeCount = 0
- createCount = 0
- unlinkCount = 0
+ emitter = watchit file, retain: true
+ emitter.on 'change', -> changeCount++
+ emitter.on 'create', -> createCount++
+ emitter.on 'unlink', -> unlinkCount++
- emitter = watchit 'fixtures/a.test', retain: true
- emitter.on 'change', -> changeCount++
- emitter.on 'create', -> createCount++
- emitter.on 'unlink', -> unlinkCount++
-
- fs.writeFileSync 'fixtures/a.test', ''
- test.done() # until fs.watch is fixed...
- # delay ->
- # test.equal 1, createCount
- # fs.unlinkSync 'fixtures/a.test'
- # delay ->
- # test.equal 1, unlinkCount
- # fs.writeFileSync 'fixtures/a.test', ''
- # delay ->
- # test.equal 2, createCount
- # fs.writeFileSync 'fixtures/a.test', 'cha-cha-cha-change'
- # delay ->
- # test.equal 1, changeCount
- # test.done()
+ fs.writeFileSync file, ''
+ done() # until fs.watch is fixed...
+ # delay ->
+ # expect(createCount).to.be(1)
+ # fs.unlinkSync 'fixtures/a.test'
+ # delay ->
+ # expect(unlinkCount).to.be(1)
+ # fs.writeFileSync 'fixtures/a.test', ''
+ # delay ->
+ # expect(createCount).to.be(2)
+ # fs.writeFileSync 'fixtures/a.test', 'cha-cha-cha-change'
+ # delay ->
+ # expect(changeCount).to.be(1)
+ # done()
Something went wrong with that request. Please try again.