未能用grunt,phantomjs和mocha设置测试环境 [英] Failing to setup a test environment with grunt, phantomjs and mocha

查看:128
本文介绍了未能用grunt,phantomjs和mocha设置测试环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用yeoman设置一个使用grunt,phantomjs和mocha的测试环境。问题是运行测试任务时,我收到以下警告:

 警告:PhantomJS超时,可能是由于缺少摩卡运行()调用。使用--force继续。 

但是我打电话给 mocha.run()在我的index.html文件中。这里是:

 <!doctype html> 
< html>
< head>
< meta charset =utf-8>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge>
< title>摩卡Spec Runner< / title>
< link rel =stylesheethref =bower_components / mocha / mocha.css>
< / head>
< body>
< div id =mocha>< / div>
< script src =bower_components / mocha / mocha.js>< / script>
< script> mocha.setup('bdd')< / script>
< script src =bower_components / chai / chai.js>< / script>
< script>
var assert = chai.assert;
var expect = chai.expect;
var should = chai.should();
< / script>

<! - 包括此处的源文件... - >

<! - 包括这里的规格文件... - >
< script src =spec / test.js>< / script>

< script>
mocha.run();
< / script>
< / body>
< / html>

我认为我的问题出现在我的Gruntfile中,我必须缺少一些东西。以下是我的一些Gruntfile:

  connect:{
test:{
options:{
端口:9001,
base:[
'.tmp',
'test',
'<%= yeoman.app%>'
]
}
},
...


摩卡:{
test:{
src:['test / * .html'],
选项:{
url:['http:// localhost:9001 / test / index.html']
}
}
}



grunt.registerTask('test',[
'clean:s​​erver',
'concurrent:test',
'autoprefixer',
'connect:test',
'mocha']);


解决方案

我有同样的错误信息,在yeoman设置中实际上是两个bower_components目录。

  $> ls -la 
...
bower_components
...
test / bower_components

当我克隆一个yo生成的应用程序的git repo时,它具有以下.gitignore文件

  node_modules 
dist
.tmp
.sass-cache
bower_components
test / bower_components

所以你需要运行这两次...

$ p
$ b $ install

一次进入[root]并且一次进入[root] / test

I'm trying to setup a test environment with grunt, phantomjs and mocha using yeoman. The problem is when run the test task I got the following warning:

Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.

But I'm calling mocha.run() in my index.html file. Here it is:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Mocha Spec Runner</title>
    <link rel="stylesheet" href="bower_components/mocha/mocha.css">
</head>
<body>
    <div id="mocha"></div>
    <script src="bower_components/mocha/mocha.js"></script>
    <script>mocha.setup('bdd')</script>
    <script src="bower_components/chai/chai.js"></script>
    <script>
        var assert = chai.assert;
        var expect = chai.expect;
        var should = chai.should();
    </script>

    <!-- include source files here... -->

    <!-- include spec files here... -->
    <script src="spec/test.js"></script>

    <script>
      mocha.run();
    </script>
</body>
</html>

I think my problem is inside my Gruntfile, I must be missing something. Here's some of my Gruntfile:

connect: {
      test: {
        options: {
          port: 9001,
          base: [
            '.tmp',
            'test',
            '<%= yeoman.app %>'
          ]
        }
      },
...


mocha: {
  test: {
    src: ['test/*.html'],
    options: {
      urls: [ 'http://localhost:9001/test/index.html' ]
    }
  }
}

...

grunt.registerTask('test', [
  'clean:server',
  'concurrent:test',
  'autoprefixer',
  'connect:test',
  'mocha'   ]);

解决方案

I had the same error message and then I realised there are actually two bower_components directories in a yeoman setup.

$> ls -la
...
bower_components
...
test/bower_components

When I cloned a git repo of a yo generated app it has the following .gitignore file

node_modules
dist
.tmp
.sass-cache
bower_components
test/bower_components

So you need to run this twice...

bower install

Once in [root] and once in [root]/test

这篇关于未能用grunt,phantomjs和mocha设置测试环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆