I'd like to do some BDD using Mocha and PhantomJS only.
Define a few functional paths and test 'em.
In short, I'd love to run the command phantomjs test.js
while test.js
contains something like this:
var mocha = require("mocha"); // This one fails with "ReferenceError: Can't find variable: process"..... "/node_modules/mocha/index.js:2"
var page = require('webpage').create();
describe('Empty', function(){ // Obviously this one fails too with "ReferenceError: Can't find variable: describe"
describe('tests are', function(){
it('very nice', function(done){
page.open("http://www.phantomjs.org/", function (status) {
console.log('Loading a web page');
console.log("Page is loaded");
phantom.exit(); // Or, just call `done()`, doesn't matter right now
});
})
})
})
Can you recognize the code pieces of the two?
How can I make this work? I've read on some page that I could require()
"mocha.js" of the browser version, but it doesn't seem to work very well.
------------------More details ------------------------------------
I've tried CasperJS but besides providing some really nice stuff, I miss Mocha's appealing test design (server-side).
All the examples I've seen explain how to run your Mocha tests on the webpage (browser-side) (with a script tag), rather than the NodeJS test script.
I don't like it, I want to keep the test pure-console, in addition to the fact that this approach encourages me to add testing code to my webpages.
I've seen a few projects trying to ease that approach yet I'm not content with it - it seems like they've done 95% of the requirement by bringing Mocha and PhantomJS, but the last 5% are still undone, the stuff that really connect it together.
process
is something Node provides for scripts (unavailable in browsers). – Michael Tang