简体   繁体   English

Grunt-Mocha`PhantomJS超时`

[英]Grunt-Mocha `PhantomJS timed out`

I keep getting this message while runnign my mocha tests from grunt. 在咕unt咕mo地进行摩卡咖啡测试时,我一直收到此消息。

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

The tests ran fine in the browser, however they fail to start from grunt. 这些测试在浏览器中运行良好,但是它们从刚开始就无法启动。 I've been using this Grunt plugin for running my brower tests , and my this is the relevant parts of my Gruntfile.js. 我一直在使用这个 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,
  }
},

Here's the test.html file 这是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>

Here's the public directory 这是public目录

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

Here's the output from grunt following up to the fail. 这是后续发出的咕unt声的输出。

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.

All the src I need for the tests is put in a single file it includes my source (and it's dependencies), mocha, and the tests. 我需要测试的所有src都放在一个文件中,该文件包括我的源代码(及其依赖项),mocha和测试。

Don't know if it is still relevant to you, but just in case anyone else faces this issue: In my case, the tests worked perfectly fine if I directly called them from command line, like: mocha-phantomjs .\\test\\src\\tests.html . 不知道它是否仍然与您相关,以防万一其他人遇到此问题:就我而言,如果我从命令行直接调用它们,例如: mocha-phantomjs .\\test\\src\\tests.html ,这些测试就可以正常工作mocha-phantomjs .\\test\\src\\tests.html It was only that grunt-mocha was unable to run them, throwing this error. 只是grunt-mocha无法运行它们,从而引发此错误。 Shifting to grunt-mocha-phantomjs fixed it for me, no code change required. 转向grunt-mocha-phantomjs为我修复了它,不需要更改代码。 Gruntfile looks like this: Gruntfile看起来像这样:

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

(You may have to escape that property name if you have set camelcase to true in your jshint settings though.) (但是,如果在jshint设置中将camelcase设置为true ,则可能必须转义该属性名称。)

mocha.run() only works when running tests in the browser. mocha.run()仅在浏览器中运行测试时有效。

To run tests in the browser and grunt do this: 要在浏览器中运行测试仔细检查,请执行以下操作:

Replace mocha.run() with: mocha.run()替换为:

if (window.mochaPhantomJS) {
    mochaPhantomJS.run();
}
else {
    mocha.run();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM