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

Question about output #32

Closed
Sventric opened this issue Mar 11, 2015 · 8 comments
Closed

Question about output #32

Sventric opened this issue Mar 11, 2015 · 8 comments

Comments

@Sventric
Copy link

After trying to get jasmine-node to work and google-ing for all sorts of info about nodejs and jasmine-node i ran in to jasmine-npm and it just works :)

After combining it in to our build on a bamboo build server it sort of works, when i check the logs i see that non of my tests failed, but how can i change the output. Bamboo can handle test outputs in a junitreport format but how can i do this using jasmine-npm (if at all)?

@arusakov
Copy link

jasmine-reporters can help you

@amavisca
Copy link
Member

As @arusakov said, you should use a custom reporter. You can't set a custom reporter via the command line right now but you can write a bit of code to add a custom reporter.

Something like this:

var Jasmine = require('jasmine');
var jasmine = new Jasmine();
jasmine.loadConfigFile('./spec/support/jasmine.json');
jasmine.addReporter(myCoolCustomReporter);
jasmine.execute();

@Sventric
Copy link
Author

Thanks for the replies.

Started using jasmine-reporters, this did got triggered to report the various states of specs, but still no output to be found.

After some further testing i seem to have found a/my problem.

If prevent the consoleReporter to be added (in Jasmine.prototype.configureDefaultReporter in ./lib/jasmine.js @ 48) i get my output.
When i turned the consoleReporter back on i prevented my output again.

When i took a look at the ReportDispatcher and the dispatch method and added some logging i noticed that every method was tested (and called if test showed it was found) for both reporters except the jasmineDone, when jasmineDone is called the dispatcher seems to stop.
I assume the defaultOnComplete is killing the process:

  var defaultOnComplete = function(passed) {
    if(passed) {
      exit(0);
    }
    else {
      exit(1);
    }
  };

When i change the addReporter to use unshift instead of push this problem goes a way an nicely both my reporters work as expected.

Am i missing some option/setting or is this a bug in the ReportDispatcher or ConsoleReporter?

@amavisca
Copy link
Member

Yeah, the default onComplete was probably killing the process. You can override the onComplete now on the master branch by simply doing:

jasmine.onComplete(function() { 
 // custom onComplete
});

@slackersoft
Copy link
Member

We haven't heard anything else on this from the community, and we think it is probably solved in the current codebase, so I'm going to close this for now.

@pflannery
Copy link

These examples show to create a custom runner but the problem with creating a custom runner is that debugging only works when having to type a debugger statement in your tests. Its a real pain the arse.

Would be great if we could specify a custom reporter on the cli. i.e. jasmine --reporter jasmine-spec-reporter or even specify it in the jasmine.json
Cli would attempt to require the custom reporter from the users cwd\node_modules folder and throw an error if it's not present.

@slackersoft
Copy link
Member

@pflannery You should also be able to register a reporter in a helper file now.

Hope this helps.

@Wambosa
Copy link

Wambosa commented Mar 19, 2022

Throwing a note in here for any other passers by who want to demystify "You should also be able to register a reporter in a helper file now".

npm install jasmine-console-reporter (not maintained by still works)

jasmine.json

{
  "spec_dir": "spec",
  "spec_files": [
    "**/*[sS]pec.js"
  ],
  "helpers": [
    "**/*[hH]elp.js"
  ],
...
}

verbose.help.js

import JasmineConsoleReporter from 'jasmine-console-reporter'

const reporter = new JasmineConsoleReporter({
    colors: 1,           // (0|false)|(1|true)|2
    cleanStack: 1,       // (0|false)|(1|true)|2|3
    verbosity: 4,        // (0|false)|1|2|(3|true)|4|Object
    listStyle: 'indent', // "flat"|"indent"
    timeUnit: 'ms',      // "ms"|"ns"|"s"
    timeThreshold: { ok: 500, warn: 1000, ouch: 3000 }, // Object|Number
    activity: false,     // boolean or string ("dots"|"star"|"flip"|"bouncingBar"|...)
    emoji: true,
    beep: true
})

jasmine.getEnv().addReporter(reporter)

also a cli alternative

package.json

  "scripts": {
    "test": "jasmine --reporter=jasmine-console-reporter"
  },
  "devDependencies": {
    "jasmine": "^4.0.2",
    "jasmine-console-reporter": "^3.1.0"
  }

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

6 participants