amasad/sane — pull request #29 by jgoz (2014-10-10 22:02:36+00:00)
Title: Fix unhandled EPERM error (and other tests) on Windows

Fixes #28.

As described in the issue, node on Windows appears to emit `EPERM` errors instead of `ENOENT` when calling `fs.stat` on a directory that was recently deleted.

This PR also fixes the `"closes watchers when dirs are deleted"` test, which was broken on Windows due to `add` events leaking between tests:

```bash
22 passing (30s)
1 failing

1) sane in normal mode sane(file) closes watchers when dirs are deleted:
Uncaught AssertionError: {"sub_1":true,"sub_1\\file_1":true} deepEqual {"sub_x9254":true,"sub_1":true}
at Watcher. ('C:\path\to\sane\test\test.js':204:20)
at Watcher.emit (events.js:106:17)
at Watcher. ('C:\path\to\sane\index.js:361':10)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
```

In the above output, `sub_x9254` is a dir created by the previous test, "adding in a new subdir will trigger an add event". The fix I implemented was to filter out unexpected `add` events, but alternate suggestions are welcome.