尝试设置Grunt以自动执行某些测试,测试在浏览器中工作正常但在命令行中无效

Tre*_*orP 5 qunit phantomjs gruntjs

我目前正在尝试将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.
Run Code Online (Sandbox Code Playgroud)

我的一些搜索让人们降级他们的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']);
};
Run Code Online (Sandbox Code Playgroud)

这是简单的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>
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏.

ooX*_*1sh 6

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

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

我更新了:

<script src="//code.jquery.com/qunit/qunit-1.15.0.js"></script>
Run Code Online (Sandbox Code Playgroud)

至:

<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>
Run Code Online (Sandbox Code Playgroud)

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