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

Reporter not compatible with WebStorm #20

Closed
ghost opened this issue Feb 3, 2015 · 13 comments
Closed

Reporter not compatible with WebStorm #20

ghost opened this issue Feb 3, 2015 · 13 comments

Comments

@ghost
Copy link

ghost commented Feb 3, 2015

The reporter is not compatible with WebStorm, I got only ...FFF.....F.. etc... in the console, but no failure details. I checked, in nodejs it runs properly.

@ghost
Copy link
Author

ghost commented Feb 3, 2015

The problem that jasmineDone never runs in the console_reporter, but I have no idea how to fix it. It runs every test, but after that it exits without reporting the failures. The suiteDone and specDone seems to run properly.

I guess the problem is in the core, so I have to dig deeper in the code. :S

@ghost
Copy link
Author

ghost commented Feb 3, 2015

Here is what I got in webstorm:
nevtelen
and here is what I got in bash:
nevtelen2

@ghost
Copy link
Author

ghost commented Feb 3, 2015

I created an issue by webstorm as well: https://youtrack.jetbrains.com/issue/WEB-15046

@ghost
Copy link
Author

ghost commented Feb 3, 2015

I think I was wrong. I added console.log("x") to the first line, and it sometimes prints the x, sometimes not. If I add multiple console.log, only the first one prints, the seconds one not. There is no character limit, I removed a test file from about 5, and after that I did not get the x. After I restored the file, I got the x again, so it is rapsodic whether it prints. When I removed that test file, it did not end every test, or at least it did not write all F-s and .-s. So this is more serious than I previously thought.

@ghost
Copy link
Author

ghost commented Feb 3, 2015

I think WebStorm forces the nodejs to close, or something like this happens. With a single test only it does not print anything. So it depends on the test count.

@ghost
Copy link
Author

ghost commented Feb 3, 2015

WebStorm and PhpStorm has the same issue with reporters. It runs the code, but stops reporting after a while. I guess it depends on how many times you call the console.log or the stdout.write. I modified https://github.com/jasmine/jasmine-npm/blob/master/lib/command.js#L65 to write only a single time. Now it works in most of the cases, but sometimes prints nothing. (I guess this should be fixed by WebStorm, not here.)

function runJasmine(jasmine, env) {
  jasmine.loadConfigFile(process.env.JASMINE_CONFIG_PATH);

  var report = "";
  jasmine.configureDefaultReporter({
    showColors: env.color,
    print: function() {
        report += util.format.apply(this, arguments);
    },
    onComplete: function(passed) {
        process.stdout.write(report);
        if(passed) {
            process.exit(0);
        }
        else {
            process.exit(1);
        }
    }
  });
  jasmine.execute(env.files);
}

I think it is sad, that currently we cannot configure the default reporter in the config file. This whole code should be placed there as something exceptional.

@slackersoft
Copy link
Member

Based on your investigation, this sounds like an issue with WebStorm terminating the jasmine command early and not jasmine-npm itself. Closing.

Thanks for using jasmine!

@ghost
Copy link
Author

ghost commented Feb 3, 2015

You are right, I think it is a WebStorm issue. It does not terminate the command, but its console stops receiving the printed data. I had the same issue with PHPStorm and SimpleTest (an old PHP testing framework). I'll check the code of jasmine-node, maybe there is a known solution in there, because jasmine-node worked properly with these IDEs. I'll send a pull request if I find something. I'll add a feature request about the custom reporter.

@ghost ghost mentioned this issue Feb 3, 2015
@ghost
Copy link
Author

ghost commented Feb 3, 2015

https://youtrack.jetbrains.com/issue/WEB-1926
It seems to be a 3 years old windows + nodejs issue which will be fixed in Node.js v0.11.12 I have the 0.10.36 now. That's all.

@ghost
Copy link
Author

ghost commented Feb 3, 2015

I have found the perfect workaround. Just replace this line: https://github.com/jasmine/jasmine-npm/blob/master/lib/jasmine.js#L43

options.onComplete = options.onComplete || defaultOnComplete;

with this:

  options.onComplete = (function (onComplete) {
      return function (){
          var context = this;
          var args = arguments;
          setTimeout(function (){
                onComplete.apply(context, args);
          },1);
      };
  })(options.onComplete || defaultOnComplete);

If you have the same issue on windows. It simply defers the exit with 1ms. That seems to be enough time to end the printing. Good day, ciao!

@segrey
Copy link

segrey commented Feb 4, 2015

Another workaround is to use https://github.com/cowboy/node-exit instead of process.exit as some other node console tools (e.g. grunt) do.

@ghost
Copy link
Author

ghost commented Feb 4, 2015

Nice, it appears to be complicated to exit properly in node :D
https://github.com/cowboy/node-exit/blob/master/lib/exit.js

Thanks segrey!

amavisca pushed a commit that referenced this issue Feb 4, 2015
- process.exit isn't properly waiting for buffers to finish writing in Windows
- issue in node fixed in v0.11.12: nodejs/node-v0.x-archive#3584

Fixes #20
@amavisca
Copy link
Member

amavisca commented Feb 4, 2015

@segrey Thanks for the workaround, I pulled in the exit module.

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

3 participants