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

mocha crashes with no method 'getWindowSize' (on process.stdout or tty) #4

Closed
carchrae opened this issue Apr 21, 2014 · 2 comments
Closed

Comments

@carchrae
Copy link

I upgraded to the latest package versions in my project and started to get this error when using mocha-multi.

I suspect it may be because of how mocha-multi fakes the stdout/tty.

/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:141
      throw err;
            ^
TypeError: Object #<Object> has no method 'getWindowSize'
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/reporters/base.js:114:13)

Here is my fix. It is not particularly nice, but perhaps it helps someone. I add mocha --require ./fix-mocha.js --reporter mocha-multi ...

fix-mocha.js

var tty = require('tty');
if (!tty.getWindowSize){
  tty.getWindowSize = function(){ return [80,75]; } ;
  console.log("patched missing function in tty");
}

If case you're curious, tty has these properties:

[ 'isatty', 'setRawMode', 'ReadStream', 'WriteStream' ]

and the isatty returns

{ 'tty.isatty(1)': true, 'tty.isatty(2)': true }

It seems related to mochajs/mocha#36 - but that is such an old issue I wonder why it resurfaced.

Stack trace:

/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:141
      throw err;
            ^
TypeError: Object #<Object> has no method 'getWindowSize'
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/reporters/base.js:114:13)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/reporters/index.js:2:16)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/mocha.js:26:21)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/index.js:4:5)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/lib/reporters/cobertura.js:6:15)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/index.js:2:18)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at safeRequire (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:138:12)
    at resolveReporter (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:127:16)
    at /home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:114:22
    at withReplacedStdout (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:216:5)
    at /home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:113:5
    at Array.map (native)
    at initReportersAndStreams (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:104:16)
    at new MochaMulti (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:39:17)
    at Mocha.run (/home/tom/projects/some-project/node_modules/mocha/lib/mocha.js:345:18)
    at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha/bin/_mocha:351:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
@glenjamin
Copy link
Owner

This is caused by having more than one mocha floating around.

Normally, base.js is loaded early enough to not be affected by all the monkey patching (https://github.com/glenjamin/mocha-multi/blob/master/mocha-multi.js#L6)

For some reason, your custom reportering (this one? https://github.com/sjonnet19/mocha-cobertura-reporter) declare mocha as a "dependency", when it should really be a "peerDependency".

This causes a second base.js to be loaded - which only happens after the tty stuff has fired.

The simplest fix would be to add | cat onto the end of your mocha command, so it's not a tty and this code-path gets skipped.

Unfortunately mocha has quite a bit of hidden state, so there's not a huge amount I can do here.

@carchrae
Copy link
Author

Thanks for the explanation and easy fix, Glen. I suspect my fix above does not work correctly - and one of my reporters is using the additional base.js and not writing the output via mocha-multi.

I'm using a few different mocha reporters, and none of them declare the dependency correctly. Boo.

jan-molak added a commit to jan-molak/mocha-cobertura-reporter that referenced this issue Jul 14, 2014
priley86 added a commit to priley86/mocha-junit-reporter that referenced this issue Dec 20, 2015
So mocha-junit-reporter can be used with mocha-multi.

See:
glenjamin/mocha-multi#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants