I'm using Jasmine via the jasmine-maven-plugin, and I would like to see console.log() messages in the Maven build output. Is there a way to achieve this?
If console.log() cannot be redirected, is there any other way to log from my tests so that they show up on the Maven build output?
I'm running these tests on Jenkins in a headless fashion, and would like a means to get some debug output from the tests.
Try
console.info('foo')
From the test javascripts.
You can use:
jasmine.log("I've got a big log.");
NB: See douglas-treadwell's comment below.
This refers to Jasmine 1.x. With Jasmine 2.0 just use console.log directly.
If you are running in a node env. You could use
process.stdout.write("this will be send to the console");
I'm using jasmine 2
via guard
and phantom js
and have found that standard console.log
messages within tests are output to the jasmine spec runner's console just fine.
I've also found that console.log
messages within the javascript code elements that I am testing do get written out to stdout
but not console.log
messages within the tests themselves.
I think it is not possible.
I had to overwrite the console.log implementation in the spec loader. i.e (using jQuery):
var console = {
panel: $('body').append('<div>').css({position:'fixed', top:0, right:0,background:'transparent'}),
log: function(m){
this.panel.prepend('<div>'+m+'</div>');
}
};
console.log('message 1');
console.log('message 2');
here your have a functional example
If you're desperate for any output in a Terminal window so you can have data to review after the test has completed and the browser has closed, console.error()
seems to do the trick.
Ran into the same issue using grunt/karma/jasmine (karma-jasmine 0.2.2) -
To go along with what Dave Sag said, I've found that all my console.log
messages from the code I'm testing run fine, however nothing from my describe() {}
and it() {}
blocks log anything.
I did find that you can log from a beforeEach() {}
block. At least it worked for me :
beforeEach(function() {
this.model = new blahModel();
console.log('this.model = ', this.model);
});
Note that this only logs in the browser console and for some reason won't log in command line. Somewhat strange when the console.log statements from the tested code block do log in the command line. I've also found what seems to be a better approach for consistent logging here.
UPDATE : I'm actually seeing the logging working for it blocks as well, I believe I had other errors that were preventing this.
1) Go to your project directory where you have your pom.xml. Run the following command in cmd. mvn jasmine:bdd
2) You will get the localhost URL : localhost:8234 (just an example).
3) Run this URL in the browser. Now all your test cases gets executed.
4) Do the Inspect element of this page. In the browser console you will be able to see all the console.log() or console.error() traces.
来源:https://stackoverflow.com/questions/11049996/redirect-calls-to-console-log-to-standard-output-in-jasmine-tests