1

Just want to know if it's possible to force casperjs to only output failed tests to the console. Has anyone tried to do that?

Thank you

1
  • What I have now is that casperjs writes PASS + 'some message' in the console for every assertion that passes in unit tests. I need to know the way how to make casperjs to output only FAIL message (for some assertion that failed) in the console. Commented Dec 19, 2014 at 18:34

1 Answer 1

2

Since you're running the CasperJS test environment, you can add the --concise option when you run CasperJS:

casperjs test --concise yourTest.js 

This hides all assertion logs, but doesn't hide the additional info of FAILs:

 Test file: test20_only_show_fail.js # type: assert # file: test20_only_show_fail.js:8 # code: test.assert(false, "false"); # subject: false # type: assert # file: test20_only_show_fail.js:13 # code: test.assert(false, "false"); # subject: false FAIL 3 tests executed in 0.027s, 1 passed, 2 failed, 0 dubious, 0 skipped. 

But now you can't distinguish them easily. You can add an event listener to the front of your test file and let it print something useful:

casper.test.on("fail", function(failure) { this.casper.echo("FAIL " + failure.message); }); 

This produces the FAIL lines that come after the additional information:

 Test file: test20_only_show_fail.js # type: assert # file: test20_only_show_fail.js:7 # code: test.assert(false, "false"); # subject: false FAIL false # type: assert # file: test20_only_show_fail.js:12 # code: test.assert(false, "false"); # subject: false FAIL false FAIL 3 tests executed in 0.028s, 1 passed, 2 failed, 0 dubious, 0 skipped. 

This is the test file (test20_only_show_fail.js) for reference:

casper.test.on("fail", function(failure) { this.casper.echo("FAIL " + failure.message); }); casper.test.begin('fail test', function(test) { test.assert(true, "true"); test.assert(false, "false"); test.assert(true, "true (2)"); }); casper.test.begin('error test', function(test) { test.assert(false, "false"); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.