larrymyers / jasmine-reporters

Reporter classes for the jasmine test framework. Includes JUnitXmlReporter for generating junit xml output for running in CI environments like Jenkins.
MIT License
393 stars 180 forks source link

Error on jasmine-node side #63

Closed nirkoren closed 10 years ago

nirkoren commented 10 years ago

Hi,

we get this error (TeamCity reporter) :

/home/panda/panda_git/internal/on_demand/automation/jasmine/nodejs/node_modules/jasmine-node/lib/jasmine-node/reporter.js:336 jasmineNode.TeamcityReporter.prototype = new jasmine.TeamcityReporter; ^ TypeError: undefined is not a function at /home/panda/panda_git/internal/on_demand/automation/jasmine/nodejs/node_modules/jasmine-node/lib/jasmine-node/reporter.js:336:44 at Object. (/home/panda/panda_git/internal/on_demand/automation/jasmine/nodejs/node_modules/jasmine-node/lib/jasmine-node/reporter.js:342:3) 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 Module.require (module.js:364:17) at require (module.js:380:17) at Object. (/home/panda/panda_git/internal/on_demand/automation/jasmine/nodejs/node_modules/jasmine-node/lib/jasmine-node/index.js:34:21) at Module._compile (module.js:456:26) [INFO] ---------------------------------------------

More info here: http://stackoverflow.com/questions/24553915/jasmine-node-shows-error-when-ran-from-command-prompt

FlxRobin commented 10 years ago

We're seeing the same issue with builds ran through Travis CI.

Yesterday our jasmine-node looked like: jasmine-node@1.14.3 /home/travis/.nvm/v0.10.26/lib/node_modules/jasmine-node ├── underscore@1.6.0 ├── mkdirp@0.3.5 ├── walkdir@0.0.7 ├── jasmine-growl-reporter@0.0.3 (growl@1.7.0) ├── coffee-script@1.7.1 ├── requirejs@2.1.14 ├── jasmine-reporters@0.4.1 └── gaze@0.3.4 (minimatch@0.2.14, fileset@0.1.5)

Today it looks like this (difference is in jasmine-reporters): jasmine-node@1.14.3 /home/travis/.nvm/v0.10.26/lib/node_modules/jasmine-node ├── underscore@1.6.0 ├── mkdirp@0.3.5 ├── walkdir@0.0.7 ├── jasmine-reporters@2.0.0 ├── jasmine-growl-reporter@0.0.3 (growl@1.7.0) ├── coffee-script@1.7.1 ├── requirejs@2.1.14 └── gaze@0.3.4 (minimatch@0.2.14, fileset@0.1.5)

alanning commented 10 years ago

Although the error has "reporters" in it, I'd suspect this is something to do with this commit on the main jasmine-node repo:

https://github.com/mhevery/jasmine-node/commit/98007579900165c5aa6e42db6fb77450221af3ba

Haven't isolated it yet but that section in the Teamcity constructor that references itself looks suspicious:

  jasmineNode.TeamcityReporter = function(config) {
    var callback_ = config.onComplete || false;

    (function(superFn) {
      jasmineNode.TeamcityReporter.prototype.reportRunnerResults = function(runner) {
        superFn.call(this, runner);
        if (callback_) {callback_(runner)}
      }
    }(jasmine.TeamcityReporter.prototype.reportRunnerResults));
  };
  jasmineNode.TeamcityReporter.prototype = new jasmine.TeamcityReporter;

source: https://github.com/mhevery/jasmine-node/blob/master/lib/jasmine-node/reporter.js#L330

I think that code only works if there is already a TeamcityReporter defined. Guessing there used to be another TeamcityReporter defined previously but the load order was changed so that it now gets defined later so this code now fails.

sgrebnov commented 10 years ago

+1, see the same issue

angelsmercy commented 10 years ago

+1, same issue.

nirkoren commented 10 years ago

@FlxRobin , @alanning , @sgrebnov , @larrymyers , @angelsmercy meanwhile, on order to overcome this issue until it fixed, just install jasmine-node@1.14.2. Check the pom

node_modules/npm/bin/npm-cli.js --proxy=${npm.proxy} --https-proxy=${npm.proxy} install jasmine-node@1.14.2
alanning commented 10 years ago

Thanks @nirkoren. A user on SO also reported that reverting to v1.14.2 fixes this.

This supports the hypothesis that it is the commit I referenced above causing the issue.

putermancer commented 10 years ago

A primary issue here is that your jasmine-reporters version was bumped from 0.4 to 2.0. These are incompatible updates. Jasmine-reporters@ 0.4 and 1.0 support jasmine1.x and register themselves as "jasmine.REPORTERNAME", but when you get to 2.0 the reporters only support jasmine2 and are NOT registered on the "jasmine" object.

Try changing your package.json to use jasmine-reporters@<2.0.0  — Ben Loveridge (phone--sorry for typos)

On Thu, Jul 3, 2014 at 8:14 AM, Adrian Lanning notifications@github.com wrote:

Thanks @nirkoren. A user on SO also reported that reverting to v1.14.2 fixes this.

This supports the hypothesis that it is the commit I referenced above causing the issue.

Reply to this email directly or view it on GitHub: https://github.com/larrymyers/jasmine-reporters/issues/63#issuecomment-47934818

alanning commented 10 years ago

Ok, I think I traced this down. This code in reporter.js needs to come after TeamcityReporter is defined:

  // Extend Teamcity Reporter
  jasmineNode.TeamcityReporter = function(config) {
    var callback_ = config.onComplete || false;

    (function(superFn) {
      jasmineNode.TeamcityReporter.prototype.reportRunnerResults = function(runner) {
        superFn.call(this, runner);
        if (callback_) {callback_(runner)}
      }
    }(jasmine.TeamcityReporter.prototype.reportRunnerResults));
  };
  jasmineNode.TeamcityReporter.prototype = new jasmine.TeamcityReporter;

source: https://github.com/mhevery/jasmine-node/blob/master/lib/jasmine-node/reporter.js#L326-L336

That code runs as soon as the reporter.js file is loaded... ...but in jasmine-node/index.js, the reporter.js file is loaded before TeamcityReporter is defined.

var nodeReporters = require('./reporter').jasmineNode;
jasmine.TerminalVerboseReporter = nodeReporters.TerminalVerboseReporter;
jasmine.TerminalReporter = nodeReporters.TerminalReporter;
jasmine.TeamcityReporter = nodeReporters.TeamcityReporter;

source: https://github.com/mhevery/jasmine-node/blob/master/lib/jasmine-node/index.js#L34-L37

To resolve this, I'd suggest that the "extending of TeamcityReporter" be moved from jasmine-node index.js into the jasmine-reporters repo proper.

kacperus commented 10 years ago

We've experienced exactly the same problem today. Downgrading "jasmine-node" version to "1.14.2" from "1.14.3" didn't solve the problem. Manually removing "jasmine-reporters@2.0.0" and installing version "0.4.1" did the job.

alanning commented 10 years ago

Published a fork of jasmine-node to npm in case anyone wants to use it temporarily until this gets fixed upstream.

jasmine-node-reporter-fix v0.0.2

It's a fork of jasmine-node v1.14.3 which includes a patch for getting junit reports working and also specifies jasmine-reporters@<2.0.0

angelsmercy commented 10 years ago

fixed for me, thank you.

amoilanen commented 10 years ago

Until this problem is fixed as a workaround you can also go to the installed jasmine-node and comment out the TeamCity related code that causes this error:

In the file node_modules/jasmine-node/lib/jasmine-node/reporter.js in the end comment out:

/*
  // Extend Teamcity Reporter
  jasmineNode.TeamcityReporter = function(config) {
    var callback_ = config.onComplete || false;

    (function(superFn) {
      jasmineNode.TeamcityReporter.prototype.reportRunnerResults = function(runner) {
        superFn.call(this, runner);
        if (callback_) {callback_(runner)}
      }
    }(jasmine.TeamcityReporter.prototype.reportRunnerResults));
  };
  jasmineNode.TeamcityReporter.prototype = new jasmine.TeamcityReporter;
*/

This solved the problem for me.

termie commented 10 years ago

+1, same issue :/

mochipful commented 10 years ago

+1 same issue. Can we get an ETA?

We can't use any of these fixes because our test infrastructure is automated. We're using grunt-jasmine-node (https://github.com/jasmine-contrib/grunt-jasmine-node) which has a dependency on jasmine-node, so we can't directly patch in jasmine-reporters in package.json. And it doesn't make sense for grunt-jasmine-node to patch in a fix when jasmine-reporters is the problem.

Is there an ETA on when this issue will be resolved?

nsk-mironov commented 10 years ago

@mochipful, We are using grunt-jasmine-node as well and we have found another workaround. Adding "jasmine-reporters": "~0.4" as a dependency to the root package.json solves the problem.

nirkoren commented 10 years ago

Is anyone knows if this issue is about to be fixed soon?

lukaszwit commented 10 years ago

downgrade works for me

vampserv commented 10 years ago

downgrade only worked for me if I didn't use --junitreport flag with jasmine-node cli.

mochipful commented 10 years ago

@mironov-nsk You're a god. Thank you! To test my own understanding... this works because grunt-jasmine-node -> jasmine-node ~1.7.1 -> jasmine-reporters >=0.2.0, and since jasmine-reporters 0.4.0 is already a dev dependency, it uses the existing package?

This is pretty cool. I had always thought that node_modules packages were sandboxed, but it makes a lot more sense to reuse the existing ones.

nsk-mironov commented 10 years ago

@mochipful, yes, npm tries to avoid duplicate dependencies whenever possible.

artkoshelev commented 10 years ago

downgrade works for me

ricardohbin commented 10 years ago

downgrade works here too

putermancer commented 10 years ago

As has been noted, this is not a problem with jasmine-reporters, but instead is a problem with how the dependency in jasmine-node is defined (>=0.2.0, which is a very risky way to define dependencies). There are several pull requests to solve this in various ways inside jasmine-node, of which the best is probably https://github.com/mhevery/jasmine-node/pull/333.

Thanks everyone for the tips on how to work around this issue until a proper fix has landed in jasmine-node. I am closing this issue. Please move further discussion and upvoting to https://github.com/mhevery/jasmine-node/pull/333.

henrytseng commented 10 years ago

throwing in a pull request for a downgrade! This is an important issue for us since we're running a CI environment

ntobekoJ commented 10 years ago

I am still encountering this issue when using jasmine-node@1.14.2 together with jasmine-reporters@2.0.3

Error thrown when trying to run jasmine-reporters: C:\Users\Me\myProject\protractor.conf.js:25

jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('outputdir/', true, ^ TypeError: undefined is not a function at Object. (C:\Users\Me\myProject\protractor.conf.js:25:30) 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 Module.require (module.js:364:17) at require (module.js:380:17) at ConfigParser.addFileConfig (C:\Users\Me\AppData\Roaming\npm\node_mod ules\protractor\lib\configParser.js:171:20) at Object.init (C:\Users\Me\AppData\Roaming\npm\node_modules\protractor \lib\launcher.js:30:18) at Object. (C:\Users\Me\AppData\Roaming\npm\node_modules\pro tractor\lib\cli.js:129:23)

putermancer commented 10 years ago

You will absolutely get an error when you try to use jasmine-reporters@2.x with protractor -- in the example you just posted, you are trying to instantiating using jasmine-reporters@1.x style, which leads to the undefined error you posted because the reporters are no longer defined on the global jasmine object. Protractor is jasmine 1.x only, so even if you used the correct syntax to create the reporter you wouldn't get the results you expect. — Ben Loveridge (phone--sorry for typos)

On Wed, Sep 17, 2014 at 3:45 AM, ntobekoJ notifications@github.com wrote:

I am still encountering this issue when using jasmine-node@1.14.2 together with jasmine-reporters@2.0.3 Error thrown when trying to run jasmine-reporters: C:\Users\Me\myProject\protractor.conf.js:25 jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('outputdir/', true, ^ TypeError: undefined is not a function at Object. (C:\Users\Me\myProject\protractor.conf.js:25:30) 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 Module.require (module.js:364:17) at require (module.js:380:17) at ConfigParser.addFileConfig (C:\Users\Me\AppData\Roaming\npm\node_mod ules\protractor\lib\configParser.js:171:20) at Object.init (C:\Users\Me\AppData\Roaming\npm\node_modules\protractor \lib\launcher.js:30:18) at Object. (C:\Users\Me\AppData\Roaming\npm\node_modules\pro

tractor\lib\cli.js:129:23)

Reply to this email directly or view it on GitHub: https://github.com/larrymyers/jasmine-reporters/issues/63#issuecomment-55871350

ntobekoJ commented 10 years ago

thanks Ben, so are you saying that I should rather be using vanilla webdriver?

putermancer commented 10 years ago

The primary reasons to use protractor over vanilla webdriver are a: it ties into the angular life cycle, so if you are using angular this is very convenient, and b: it modifies jasmine to understand webdriver promises, allowing you to write tests that look synchronous and are much cleaner and easier to follow. 

If you are using angular, I would recommend using protractor and jasmine-reporters@1.x. If you need something from jasmine2, then you will need to use vanilla webdriver and write your tests using asynchronous patterns yourself -- in which can you can also use jasmine-reporters@2.x. 

If you can get by with jasmine1.x, I think you will find you greatly prefer the protractor enhancements to jasmine over doing it in your own.  — Ben Loveridge (phone--sorry for typos)

On Wed, Sep 17, 2014 at 8:02 AM, ntobekoJ notifications@github.com wrote:

thanks Ben, so are you saying that I should rather be using vanilla webdriver?

Reply to this email directly or view it on GitHub: https://github.com/larrymyers/jasmine-reporters/issues/63#issuecomment-55897542

ntobekoJ commented 10 years ago

Perhaps a new ticket is needed for this...my biggest issue is that version 1.x.x seems to no longer be available so I am unable to downgrade. Error: version not found: jasmine@1.3.1

cehbz commented 10 years ago

Try 1.4? On Sep 18, 2014 5:16 PM, "ntobekoJ" notifications@github.com wrote:

Perhaps a new ticket is needed for this...my biggest issue is that version 1.x.x seems to no longer be available so I am unable to downgrade. Error: version not found: jasmine@1.3.1

— Reply to this email directly or view it on GitHub https://github.com/larrymyers/jasmine-reporters/issues/63#issuecomment-56003139 .

ntobekoJ commented 10 years ago

the major version 1.x.x is not available

npm ERR! notarget No compatible version found: jasmine@'>=1.0.0-0 <2.0.0-0' npm ERR! notarget Valid install targets: npm ERR! notarget ["2.0.1"]

I have changed my implementation considering this limitation. I wonder though if this is not a cause for concern to the wider community

cscleison commented 9 years ago

It's case sensitive. Try new jasmineReporters.TeamCityReporter()