Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Attempted to send a message to the worker before the response from the last message was received! Worker processes can only handle one message at a time. #369

Closed
binarykitchen opened this issue May 14, 2015 · 13 comments

Comments

@binarykitchen
Copy link

Unable to run jest tests here. Getting the above error and here is the stack trace:

Error: Received multiple responses when we were only expecting one: [{"error":"TypeError: Cannot read property 'length' of undefined\n  at maybeReadMore_ (_stream_readable.js:425:18)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate [as _immediateCallback] (timers.js:368:17)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate [as _immediateCallback] (timers.js:368:17)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate (timers.js:368:17)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate (timers.js:368:17)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate [as _immediateCallback] (timers.js:368:17)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate (timers.js:368:17)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate (timers.js:368:17)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate [as _immediateCallback] (timers.js:368:17)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate (timers.js:368:17)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"},{"error":"TypeError: Cannot read property 'length' of undefined\n  at onwriteDrain (_stream_writable.js:359:12)\n  at afterWrite (_stream_writable.js:349:5)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at Immediate._tickCallback [as _onImmediate] (node.js:344:13)\n  at processImmediate (timers.js:368:17)\n  at /Users/michael-heuberger/Development/(...)/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7\n  at doNTCallback0 (node.js:415:9)\n  at process._tickCallback (node.js:344:13)\n"}]
@pitu7dg
Copy link

pitu7dg commented May 26, 2015

#227

This also worked for me to

sudo npm run test

@binarykitchen
Copy link
Author

No, sudo does not help here and does not make sense at all. Still cannot run the tests.

@whroman
Copy link

whroman commented Jun 1, 2015

@binarykitchen
I was experiencing this issue until I removed a console.log from the script specified in the project's package.json Jest flag scriptPreprocessor

package.json

{
  ...
  "jest": {
      "scriptPreprocessor": "Spec/preprocessor.js"
  }
  ...
}

@binarykitchen
Copy link
Author

Huh? @whroman do you mean, you removed a console.log call within the Jest source code? If so, can you point to the exact line of that repository? And why hasn't this been already modified and published yet?

@binarykitchen
Copy link
Author

In my case, I call jest within a gulp task and have this scriptPreprocessor defined:

var coffee    = require('coffee-script'),
    transform = require('coffee-react-transform')

module.exports = {
  process: function(src, path) {

    if (coffee.helpers.isCoffee(path) || (path.match(/\.cjsx/))) {
      return coffee.compile(transform(src), {'bare': true})
    } else
      return src
  }
}

There is no console.log and everything looks right. But why do jest tests still do not work? (they work with older node.js or io.js versions but not with newer ones)

@whroman
Copy link

whroman commented Jun 2, 2015

@binarykitchen
No, this particular project does not use a coffee-react-transform. I'm rolling with a preprocessor that I stole from the Jest site:

# preprocessor.js
var coffee = require('coffee-script');

module.exports = {
  process: function(src, path) {
    // CoffeeScript files can be .coffee, .litcoffee, or .coffee.md
    if (coffee.helpers.isCoffee(path)) {
      return coffee.compile(src, {'bare': true});
    }
    return src;
  }
};

I had thrown a console.log into the preprocessor and that was giving me the same error that you describe.

If it helps, I wrote my own Gulp task for running the Jest test runner, so maybe you can adapt it to your situation to see if doesn't raise your error.

Gulpfile.coffee

gulp = require 'gulp'
spawn = require('child_process').spawn
gulp.task 'js:test', ['js:build'], ->
    childProcess = spawn 'npm', ['test']

    print = (data) ->
        if data
            console.log String(data)

    childProcess.stdout.on 'data', print
    childProcess.stderr.on 'data', print

Edit: It may be worth noting that this project does not use JSX.

@binarykitchen
Copy link
Author

I think we aren't on the same page here. The error I reported has nothing to do with your custom preprocessor and looks more likely a bug within jest.

This is my gulp script

gulp.task('test:jest', ->
  # Workaround until https://github.com/facebook/jest/issues/270 is solved
  process.env.NODE_PATH = __dirname + '/' + paths.frontend

  gulp.src("#{paths.frontend}")
    .pipe(plugins.jest(
      testDirectoryName:  "__jest__"

      testFileExtensions: ['cjsx']
      moduleFileExtensions: [
        "js"
        "json"
        "coffee"
        "cjsx"
      ]
    ))
)

You see, it has no pre-processor and it still happens:

 FAIL  mailboxes/components/__jest__/Filter.cjsx
TypeError: Cannot read property 'length' of undefined
  at maybeReadMore_ (_stream_readable.js:426:18)
  at /home/michael-heuberger/Development/xxx/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7
  at doNTCallback0 (node.js:408:9)
  at process._tickCallback (node.js:337:13)

 FAIL  components/__jest__/Fieldset.cjsx
Error: Attempted to send a message to the worker before the response from the last message was received! Worker processes can only handle one message at a time.
 FAIL  archiving/components/__jest__/AutocompleteInput.cjsx
TypeError: Cannot read property 'length' of undefined
  at maybeReadMore_ (_stream_readable.js:426:18)
  at /home/michael-heuberger/Development/xxx/node_modules/gulp-jest/node_modules/jest-cli/src/lib/FakeTimers.js:329:7
  at doNTCallback0 (node.js:408:9)
  at process._tickCallback (node.js:337:13)

@binarykitchen
Copy link
Author

Repeating: my gulp task worked until I switched to iojs

@binarykitchen
Copy link
Author

See #340

@binarykitchen
Copy link
Author

Ah, it's most likely related to this one monster thread: #243 where one of the latest comments mentioned a jsdom issue. So I guess #267 is going to fix this one problem.

@gwing33
Copy link

gwing33 commented Jul 21, 2015

Just want to note that switching from gulp-jest to your forked gulp-jest-iojs version @binarykitchen solved this problem for me. Thank you.

@amasad
Copy link
Contributor

amasad commented Oct 7, 2015

Should be fixed via #540 (will go out with version 0.6). Please reopen if that's not the case.

@amasad amasad closed this as completed Oct 7, 2015
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants