2013-01-08 44 views
10

我使用Yeoman来支撑我的项目。它有几个方便的东西,包括一个PhantomJS的测试跑步者。与Yeoman和PhantomJS的摩卡测试

我的问题是,虽然我的测试在浏览器中正常运行,但它们超时尝试在CLI中使用PhantomJS运行它们。

这里是我的测试index.html看起来像:

<!doctype html> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
    <title>Mocha Spec Runner</title> 
    <link rel="stylesheet" href="lib/mocha/mocha.css"> 
</head> 
<body> 
    <div id="mocha"></div> 
    <script src="lib/mocha/mocha.js"></script> 
    <!-- assertion framework --> 
    <script src="lib/chai.js"></script> 

    <!-- include source files here... --> 
    <script data-main="scripts/main" src="scripts/vendor/require.js"></script> 

    <script> 
    mocha.setup({ui: 'bdd', ignoreLeaks: true}); 
    expect = chai.expect; 
    should = chai.should(); 
    require(['../spec/map.spec'], function() { 
     setTimeout(function() { 
     require(['../runner/mocha']); 
     }, 100); 
    }); 
    </script> 

</body> 
</html> 

这里的map.spec.js

require(['map'], function (Map) { 
    describe('Choropleth Map Generator', function() { 
    describe('Configure the map', function() { 
     it("should enforce mandatory parameters in the configuration", function() { 
     var config = {title: 'test configuration'}; 
     var map = new Map(config); 
     (function() { 
      map.getConfig(); 
     }).should.throw(Error); 
     }); 
    }); 
    }); 
}); 

现在,当我做yeoman test,我得到这个:

Running "server:phantom" (server) task 

Starting static web server on port 3501 

[...] 

Running "mocha:all" (mocha) task 
Testing index.html 
<WARN> PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue. </WARN> 

Aborted due to warnings. 

正如我所说的,yeoman server:test在br中正确显示了我的断言owser。

我使用Yeoman 0.9.6和PhantomJS 1.7.0。任何帮助表示赞赏。

回答

3

什么是你的摩卡配置在Gruntfile中。你有这样的:

mocha: { 
    all: ['http://localhost:3501/index.html'] 
}, 
+0

这是缺省情况下,'自耕农init'产生。那就是 - 'mocha:{'test/**/*。html'] },' –

+0

这让它对我有用,但是从第一次尝试开始。更多细节在这里 - https://github.com/yeoman/yeoman/issues/719 –

+0

这里有一个工作模板:https://github.com/roblevintennis/yeoman_requirejs_template – Rob

4

我解决了同样的警告通过仔细检查路径mochatest/index.html

<link rel="stylesheet" href="lib/mocha/mocha.css"> 
</head> 
<body> 
    <div id="mocha"></div> 
    <script src="lib/mocha/mocha.js"></script> 
+0

我仍然有'mocha.js'在html中引用,它并没有为我改变它。我不用我的项目骨干。 –

+1

就我而言,我认为yeoman会在运行原始webapp生成器时安装Mocha。在检查了我的索引路径以及它指向的位置之后,我看到它丢失了。 '凉亭安装摩卡'固定了我。 – austin