benbria / coffee-coverage

Istanbul and JSCoverage-style instrumentation for CoffeeScript files.
MIT License
145 stars 31 forks source link

ENOENT, no such file or directory 'coverage/' #63

Open Kikobeats opened 9 years ago

Kikobeats commented 9 years ago

I really don't know why this happens.

I use a shellscript to run the tests:

"$PWD"/node_modules/.bin/mocha \
  -b \
  --compilers coffee:coffee-script/register \
  --require coffee-coverage/register-istanbul \
  --require should \
  --reporter spec \
  --timeout 120000 \
  --slow 300 \
  "$@"

You can see all the code here

The problem is that --require coffee-coverage/register-istanbul line throw an Error related with the coverage folder:

✓ release a new version and hook pre releases plugins in order (163ms)

  16 passing (300ms)

Failed to write coverage data Error: ENOENT, no such file or directory 'coverage/'
  at Error (native)
  at Object.fs.mkdirSync (fs.js:747:18)
  at exports.mkdirs (/Users/josefranciscoverdugambin/Projects/bumped/bumped/node_modules/coffee-coverage/lib/utils/helpers.js:43:14)
  at process.<anonymous> (/Users/josefranciscoverdugambin/Projects/bumped/bumped/node_modules/coffee-coverage/lib/register.js:116:11)
  at process.emit (events.js:107:17)
  at process.exit (node.js:600:17)
  at done (/Users/josefranciscoverdugambin/Projects/bumped/bumped/node_modules/mocha/bin/_mocha:406:32)
  at afterWrite (_stream_writable.js:361:3)
  at _stream_writable.js:349:9
  at process._tickCallback (node.js:355:11)

the strange thing is that the folder doesn't exist before I run the script (good) and after the exceptions exists.

Any idea of what happens?

jwalton commented 9 years ago

No. I'm doing (almost) exactly this, and I'm not seeing this issue. The error is in mkdirs, too, which is supposed to be creating folders. Is $PWD in fact, the current working directory here? Or is this part of a script that's setting $PWD and then changing the directory?

You can add some debug logging in ./node_modules/coffee-coverage/lib/helpers.js, inside exports.mkdirs(), and see if you can figure out the full path of the folder it's trying to create. Feels like some kind of relative path problem...

Kikobeats commented 9 years ago

You're right. Some debug logs before call mkdirs method:

if (options.writeOnExit) {
      return process.on('exit', function() {
        var dirName, ref1;
        try {
          dirName = path.dirname(options.writeOnExit);
          console.log('DEBUG ::');
          console.log(dirName);
          console.log(process.cwd());
          console.log(__dirname);
          mkdirs(dirName);
          return fs.writeFileSync(options.writeOnExit, JSON.stringify(global[options.coverageVar]));

output:

DEBUG ::
coverage
/Users/josefranciscoverdugambin/Projects/bumped/bumped/test/plugin_directory
/Users/josefranciscoverdugambin/Projects/bumped/bumped/node_modules/coffee-coverage/lib
Failed to write coverage data Error: ENOENT, no such file or directory 'coverage/'
  at Object.fs.mkdirSync (fs.js:654:18)
  at exports.mkdirs (/Users/josefranciscoverdugambin/Projects/bumped/bumped/node_modules/coffee-coverage/lib/utils/helpers.js:48:14)
  at process.<anonymous> (/Users/josefranciscoverdugambin/Projects/bumped/bumped/node_modules/coffee-coverage/lib/register.js:154:11)
  at process.emit (events.js:95:17)
  at process.exit (node.js:740:17)
  at done (/Users/josefranciscoverdugambin/Projects/bumped/bumped/node_modules/mocha/bin/_mocha:406:32)
  at afterWrite (_stream_writable.js:278:3)
  at _stream_writable.js:267:9
  at process._tickCallback (node.js:448:13)

I suppose that is important that I'm running the command using a script. I have the script in test/test.sh, so when I call the script from the root of my project using npm test could be a conflict with process.cwd and/or __dirname...