Skip to content

Instantly share code, notes, and snippets.

@jonataswalker
Forked from n1k0/Howto.md
Created May 4, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonataswalker/bd48899e59c4906dedbac9716379e1cc to your computer and use it in GitHub Desktop.
Save jonataswalker/bd48899e59c4906dedbac9716379e1cc to your computer and use it in GitHub Desktop.
CasperJS test cli hooks example

Put test1.js and test2.js into a tests/ directory, then run the suite:

$ casperjs test tests/ --pre=pre.js --includes=inc.js --post=post.js
Test file: /Users/nperriault/tmp/pre-inc/pre.js                                 
Hey, I'm executed before the suite.
Test file: /Users/nperriault/tmp/pre-inc/tests/test1.js                         
# this is test 1
Hi, I've been included.
PASS Subject is strictly true
Test file: /Users/nperriault/tmp/pre-inc/tests/test2.js                         
# this is test 2
Hi, I've been included.
PASS Subject is strictly true
Test file: /Users/nperriault/tmp/pre-inc/post.js                                
Hey, I'm executed after the suite.
PASS 2 tests executed, 2 passed, 0 failed.                                      

A more colorful output:

casper.sayHi = function sayHi() {
this.echo("Hi, I've been included.");
};
casper.echo("Hey, I'm executed after the suite.");
casper.test.done();
casper.echo("Hey, I'm executed before the suite.");
casper.test.done();
casper.test.comment('this is test 1');
casper.sayHi();
casper.test.assertTrue(true);
casper.test.done();
casper.test.comment('this is test 2');
casper.sayHi();
casper.test.assertTrue(true);
casper.test.done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment