5

我目前正在尝试将 GruntJS 与一些插件(PhantomJS Qunit 和 Connect 插件)结合起来。但是,设置一个简单的测试会给我带来错误,尽管搜索了几天,我还是找不到解决方案。我正在使用本地 Web 服务器 (MAMP),并且该网站在 CMS 上运行。

通过在浏览器中访问测试模板运行测试工作正常,但是当尝试使用sudo grunt testPhantomJS 通过命令行访问相同的工具时返回一个奇怪的错误:

Running "qunit:all" (qunit) task
Testing http://user-guides:80/test/test.html 
Warning: PhantomJS timed out, possibly due to a missing QUnit start() call. Use --force to continue.

Aborted due to warnings.

我的一些搜索让人们降级他们的 phantom.js 版本来处理类似的问题,但到目前为止,这些解决方案都没有对我有用,而且我担心我错过了一些就在我面前的东西。

这是我的 Gruntfile.js 的内容

    module.exports = function(grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),   
        connect: {
            server: {
                options: {
                    hostname: 'user-guides',
                    port: 80,
                    base: 'public'
                }
            }
        },
        jshint: {
            all: ['Gruntfile.js', 'public/assets/js/helper/*.js', 'public/assets/js/specific/*.js']
        },
        qunit: {
        all: {
          options: {
            timeout: 5000,
            urls: [
              'http://user-guides:80/test/test.html',
            ]
          }
        }
    }
    }
    );

    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-qunit');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.registerTask('test', ['connect', 'qunit']);
};

这是简单的 Qunit 测试

<html>
<head>
  <meta charset="utf-8">
  <title>Tests</title>
  <link rel="stylesheet" href="/assets/lib/qunit.css">
</head>
<body>
  <div id="qunit"></div>
  <script src="/assets/lib/qunit.js"></script>

  <script>
console.log("====TEST===");
    start();
    test( "hello test", function() {
      ok( 1 == "1", "Passed!" );
    });
  </script>
</body>
</html>

任何帮助是极大的赞赏。

4

1 回答 1

6

在我的 test.html 文件中,我最初只是从QUnit Cookbook中复制了示例

在此处找到类似(可能相同)的问题后: https ://stackoverflow.com/a/25053808/1814739

我更新了:

<script src="//code.jquery.com/qunit/qunit-1.15.0.js"></script>

至:

<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>

将 http: 添加到 src 属性后,从命令行运行似乎有效。

于 2014-10-28T14:23:36.453 回答