从phantomjs运行摩卡

我只想用Mocha和PhantomJS做一些BDD。
定义一些functionpath并testing它们。

总之,我很想运行命令phantomjs test.jstest.js包含这样的东西:

 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 }); }) }) }) 

你能认出两者的代码片吗?

我怎样才能做这个工作? 我已经阅读了一些我可能require()浏览器版本的“mocha.js”的页面,但是它似乎不能很好地工作。

– – – – – – – – – 更多细节 – – – – – – – – – – – – – – – ——

我尝试过CasperJS,但除了提供一些非常好的东西外,我错过了Mocha吸引人的testingdevise( 服务器端 )。

我所见过的所有示例都解释了如何在网页(浏览器端)(使用脚本标记)运行Mochatesting,而不是NodeJStesting脚本。
我不喜欢它,我想保持testing纯控制台,除了这种方法鼓励我添加testing代码到我的网页。

我已经看到一些项目试图缓解这种做法,但我不满足于它 – 他们似乎已经完成了95%的要求,通过引入摩卡和PhantomJS,但最后的5%仍然没有完成,东西真的把它连接起来

您可能想要在Node上下文( node test.js )中运行testing,但是使用类似节点幻像库的节点来控制phantomJS。

TJ Holowaychuk在他的所有库中都有这个process.env.COV检查 (我个人不明白),但PhantomJS很可能不支持该stream程variables。

你也许可以通过设置window.processwindow.process.env来清空对象来欺骗Mocha,不过我猜你以后会碰到更多的PhantomJS / Node问题。

通过节点桥接运行phantomjs可能不是最好的select。

有phantomjs-nodeify模块(我从http://github.com/jgonera分叉出来)使得phantomjs环境更像节点环境 – 它将模块进程,事件等添加到phantomjs中。

有一个webspecter的框架,实现了,老幻影和老摩卡虽然。

在虚拟2.0中运行摩卡testing似乎是可能的。