javascript - Grunt- Mocha ​​ `PhantomJS timed out`

标签 javascript gruntjs phantomjs mocha.js

当我从 grunt 运行 Mocha 测试时,我不断收到此消息。

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

测试在浏览器中运行良好,但无法从 grunt 启动。我一直在使用this用于运行我的浏览器测试的 Grunt 插件,这是我的 Gruntfile.js 的相关部分。

// I've checked if it does server while my tests are running & it does
connect: {
  test: {
    // public is where all my files are, of course
    base: 'public', 
    port: 8080
  }
},

mocha: {
  client: {
    urls: ['http://0.0.0.0:8080/test.html'],
    log: true,
  }
},

这是test.html 文件

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Mocha Tests</title>
    <link rel="stylesheet" href="css/mocha.css" />
  </head>
  <body>
    <div id="mocha"></div>
    <script src="js/test.js"></script>
    <script>mocha.run();</script>
  </body>
</html>

这是public目录

/public
- index.html
- test.html
 /css
  - main.css
  - mocha.css
 /js
  - main.js
  - test.js \\ contains main.js + mocha.js + my tests

这是失败后 grunt 的输出。

Running "uglify:dev" (uglify) task
File public/js/main.js created.
File public/js/test.js created.

Running "connect:test" (connect) task
Started connect web server on http://0.0.0.0:8080

Running "mocha:client" (mocha) task
Testing: http://0.0.0.0:8080/test.html

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

Aborted due to warnings.

我测试所需的所有 src 都放在一个文件中,其中包括我的源代码(及其依赖项)、mocha 和测试。

最佳答案

不知道它是否仍然与您相关,但以防其他人遇到此问题: 就我而言,如果我直接从命令行调用测试,则测试工作得非常好,例如: mocha-phantomjs .\test\src\tests.html 。只是grunt-mocha无法运行它们,引发此错误。 转移到 grunt-mocha-phantomjs 为我修复了它,无需更改代码。 Gruntfile 看起来像这样:

mocha_phantomjs: {
    all : ["./test/**/*.html"]
}

(如果您在 jshint 设置中将 camelcase 设置为 true,则可能必须转义该属性名称。)

关于javascript - Grunt- Mocha ​​ `PhantomJS timed out`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24823544/

相关文章:

phantomjs - 在 docker/Dokku 容器上安装 PhantomJS

javascript - 幻影捕获https网页

javascript - 在 Canvas 中查找多边形的坐标

node.js - 无法使用自定义 Materialise Sass 文件和 GruntJs 覆盖 node_modules 中的 Sass 变量

javascript - 将 JSHint 与 Express.js/'delete' 一起使用(保留字)

javascript - Grunt Concat Task,如何忽略所有 .min.js 文件?

javascript - mocha-phantomjs 的 mocha init 超时

javascript - 如何捕捉 Angular JS 的 ng-click 事件

javascript - WebSocket 连接失败 : Error during WebSocket handshake: Unexpected response code: 400

javascript - jQuery悬停在固定位置更改背景图像