jmreidy / grunt-browserify

Grunt task for node-browserify
MIT License
573 stars 146 forks source link

Incompatibility between grunt-mocha-test and grunt-browserify #224

Open mbernath opened 10 years ago

mbernath commented 10 years ago

Hi there,

here is a presumably rare but nasty bug and its workaround, that cost me the last couple of hours. The bug only occurs when grunt-mocha-test and grunt-browserify are run together in one project. This set-up might not be too rare, though.

I'm wondering where to file this issue - either here or with grunt-mocha-test. So any advice is appreciated.

Steps to reproduce

Run grunt-mocha-test and grunt-browserify in a row with a configuration like this (first grunt-mocha-test, then grunt-browserify):

// From Gruntfile.js
mochaTest: {
  all: {
    options: {
      reporter: 'spec',
      require: ['test/_test.js'],
      clearRequireCache: true
    },
    src: ['test/*-test.js']
  }
},
browserify: {
  client: {
    files: {
      'client/target.js':'lib/source-client.js'
    }
  },
  options: {
    exclude: ['underscore','domain']
  }
}

// ...
grunt.registerTask('causeError', ['mochaTest:all','browserify']);

This produces the following error, when grunt runs grunt-browserify:

/.../node_modules/grunt-browserify/node_modules/browserify/node_modules/module-deps/node_modules/duplexer2/node_modules/readable-stream/lib/_stream_writable.js:207
  if (state.ended)
           ^
TypeError: Cannot read property 'ended' of undefined
    at DuplexWrapper.Writable.write (/.../node_modules/grunt-browserify/node_modules/browserify/node_modules/module-deps/node_modules/duplexer2/node_modules/readable-stream/lib/_stream_writable.js:207:12)
    at write (_stream_readable.js:582:24)
    at flow (_stream_readable.js:591:7)
    at ReadStream.pipeOnReadable (_stream_readable.js:623:5)
    at ReadStream.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:407:10)
    at emitReadable (_stream_readable.js:403:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at ReadStream.Readable.push (_stream_readable.js:127:10)
    at onread (fs.js:1563:12) 

The error does not occur, when grunt-mocha-test and grunt-browserify are run with separately like this:

grunt mochaTest:all   # successfull
grunt browserify         # successfull

This is how far I could nail down the error...

Workaround

I tried to workaround with many versions of grunt, grunt-browserify and grunt-mocha-test, but the only working solution was to set one mochaTest option to false: clearRequireCache: false. Then everything works as expected.

Configuration

Here are the relevant dependencies with which I could reproduce the error on node version 0.10.28:

"devDependencies": {
  "grunt": "^0.4.2",
  "grunt-browserify": "^2.1.4",
  "grunt-mocha": "^0.4.11",
  "grunt-mocha-test": "^0.11.0",
  "mocha": "^1.21.3",
  // ...
}
jmreidy commented 10 years ago

I'm not entirely sure if this is a grunt-browserify issue, a grunt-mocha-test issue, or a grunt issue. grunt-concurrent might solve the issue...

reimerp commented 9 years ago

I'm also not entirely sure but I have a similar problem but with grunt-mocha-test and grunt-contrib-compress involved so it might be a grunt-mocha-test issue. My dependencies:

  "devDependencies": {
      "grunt": "0.4.x",
      "grunt-contrib-compress": "^0.13.0",
      "grunt-mocha-test": "0.12.x"

I can run the compress and test tasks seperately but not in sequence test->compress. It's also working the other way around. The problem occurs in node 0.10.38 and in node 0.12.3.

Everything is quiet but the compression never terminates. I do not have a stacktrace but when using DEBUG I found a similar Exception.

Running "compress:dist" (compress) task
[D] Task source: .../node_modules/grunt-contrib-compress/tasks/compress.js
Verifying property compress.dist exists in config...OK
Options: archive="build/artefact.tgz", mode="tgz", level=1
  mocha:runner uncaught exception Cannot read property 'ended' of undefined +12ms

Your workaround using clearRequireCache: false did work as well.