试图设置Grunt来自动执行一些测试,测试在浏览器中正常工作,但不在命令行 [英] Trying to set up Grunt to automate some testing, testing works fine in the browser but not at the command line

查看:109
本文介绍了试图设置Grunt来自动执行一些测试,测试在浏览器中正常工作,但不在命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

<$ p $运行qunit:all(qunit)任务
测试http://用户指南:80 / test / test.html
警告:PhantomJS超时,可能是因为到缺少QUnit start()调用。使用--force继续。

由于警告而中止。

我的一些搜索有人降级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:{'b $ b all:['Gruntfile.js' ,'public / assets / js / helper / *。js','public / assets / js / specific / *。js']
},
qunit:{
all:{
选项:{
时间out:5000,
url:[
'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>测试< /标题>
< link rel =stylesheethref =/ 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>

非常感谢您的任何帮助。

解决方案

在我的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属性后起作用。


I'm currently trying to incorporate GruntJS with a few plugins (PhantomJS Qunit and Connect plugins). However, setting up a simple test is throwing me errors and I can't find the solution despite a few days of searching. I'm using a local web server (MAMP) and the website is running on a CMS.

Running the tests by accessing the test template in a browser works fine, but when trying to access the same tools via the command line using sudo grunt test PhantomJS return an odd error:

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.

Some of my searches had people downgrading their version of phantom.js to deal with similar problems, but so far none of those solutions have worked for me, and I'm afraid i'm missing something right in front of my face.

Here's the contents of my 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']);
};

Here's the simple Qunit test

<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>

Any help is greatly appreciated.

解决方案

In my test.html file I originally had just copied the example from the QUnit Cookbook

After finding a similar (possibly the same) issue here: https://stackoverflow.com/a/25053808/1814739

I updated:

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

to:

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

Running from command-line seems to work after adding http: to the src attribute.

这篇关于试图设置Grunt来自动执行一些测试,测试在浏览器中正常工作,但不在命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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