visionmedia/mocha — Issue #298: emacs temporary files causing mocha to throw exception
Author: michaelsbradleyjr
Created: 2012-02-27 20:51:14+00:00
State: open

I use emacs (crazy, I know) and have run into an issue where the temporary symbolic links automatically created by emacs when I'm modifying a file (they go away after a save operation) cause mocha to throw an exception.

Suppose I start editing `mytest.js` in `myPackage/test`, and then I invoke `mocha` in the terminal prior to saving the file. I'll get the following:

```
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module '/path/to/myPackage/test/.#mytest.js'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at /Users/michael/.nvm/v0.6.11/lib/node_modules/mocha/bin/_mocha:237:27
at Array.forEach (native)
at load (/Users/michael/.nvm/v0.6.11/lib/node_modules/mocha/bin/_mocha:234:9)
at Object. (/Users/michael/.nvm/v0.6.11/lib/node_modules/mocha/bin/_mocha:225:1)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
```

Relevant information: [Why does emacs create temporary symbolic links for modified files?](http://stackoverflow.com/questions/5738170/why-does-emacs-create-temporary-symbolic-links-for-modified-files)

One "solution" is to never invoke mocha until I've saved my changes. However, that doesn't work well if I'm using the "watch" option.

A better solution would be for Mocha to ignore these kinds of symbolic links, which I think can be detected witha a combination of `fs.stat` and looking for error code `ENOENT`.

I can start poking at Mocha's source to see if I can provide a patch, but I was hoping it might be something that the author or another contributor knows how to fix quickly without a lot of r&d.