Closed kildem closed 10 years ago
You said you saw #7, but you didn't read my response. PhantomJS not Node.js - it supports the same CommonA module loading, but the APIs are different.You can't use locomotive in phantomjs.
You should start your server up probably outside your tests, then just write your mocha-casperjs tests as normal. with casper.open('http://localhost:3000/')
. You can start a process from within phantom via require('child_process').spawn
thanks for answer
Maybe it is not the best way, but I get the result I wish if I run mocha-casperjs from this file:
var test = function() { try { command = "node web.js"; server = require('child_process').exec(command); //open the browser
command = "mocha-casperjs test/functional/contact.js";
myTest = require('child_process').exec(command); //run mocha-casperjs test file
myTest.stdout.on('data', function (data) {
if(data.length > 1) console.log(data);
});
myTest.on('close', function (code) {
console.log('process exit code ' + code);
server.kill();
myTest.kill();
});
} catch (err){
console.log('Error: ', err);
}
};
module.exports = test();
any improvement is greatly appreciated :)
Yup that was my first suggestion. As an aside, I do love JavaScript too, but you could write this with 3 lines of shell script instead of all of that (I think, had to do a bit of Googling)
node web.js & P=$!
mocha-casperjs test/functional/contact.js
trap "kill $P" INT
There are more than hammers in our toolbox :D :scissors:
thanks! I tried your suggestion. the difference is that using my solution with node I get this result: contact page
✓ I am in the home page (8281ms)
- should show contact a form
- should refuse empty submissions
- should refuse partial submissions
- should keep values on partial submissions
- should refuse invalid emails
- should accept complete submissions
1 passing (8s)
6 pending
with your shell script it works well too, the only difference is that I get much more stuff after "contact page" and the result.
anyway yours is a very short solution :)
I'm using locomotivejs and this is my test:
var locomotive = require('locomotive'); describe('contact page', function() { before(function(done) { this.server = new locomotive.Locomotive(); this.server.boot(__dirname, 'test', function() { console.log("START"); done(); });
}); it('should show contact a form'); });
and when I run mocha-casperjs I get this problem: ReferenceError: Can't find variable: process
/Users/.../fierp/node_modules/express/index.js:2 /Users/.../fierp/node_modules/express/index.js:4
If I run mocha it works.
I see this: https://github.com/nathanboktae/mocha-casperjs/issues/7 but it doesn't help me. How can I fix it? Thanks