咕噜声未在幻像上运行QUnit测试 [英] grunt not running QUnit tests on phantom

查看:132
本文介绍了咕噜声未在幻像上运行QUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与travis集成的存储库。我有一些QUnit测试,我想从grunt / node服务器端和AMD(requirejs)运行。这是我的AMD init.js的源代码:

 (function(){
require.config({
baseUrl:../src
});

require([../ test / suites / basic,
'../test/ qunit-extend',
'qunit'
],函数(BasicTests){
QUnit.config.autoload = false;
QUnit.config.autostart = false;
)BasicTests.run();
QUnit.load();
QUnit.start();
});
}());

当我在浏览器中运行这些QUnit测试时 - 一切正常。但是,当我尝试从grunt级别(服务器端使用phantomjs)运行它们时,失败。我得到:

 运行qunit:all(qunit)任务
测试test / index.html
警告:PhantomJS超时,可能是由于缺少QUnit start()调用。使用--force继续。

所有时间。我试图按照和本教程,但我仍然得到错误的结果(幻像被绞死,而不是服务QUnit测试)...

解决方案

我使用 grunt-contrib-qunit 通过grunt运行QUnit测试。它在内部使用phantomjs。



在将grunt-contrib-qunit升级到最新版本(0.7.0)后,我得到与OP相同的错误:


$ b $

PhantomJS超时,可能是由于缺少QUnit start()调用。



为了解决这个问题,我必须先通过 require()加载QUnit,然后执行 QUnit.start()
$ b

HTML文件看起来像这样: pre> <!DOCTYPE html>
< html>
< head>
< title> QUnit + RequireJS + PhantomJS< / title>
< link rel =stylesheethref =lib / qunit / qunit / qunit.css>
< / head>
< body>
< div id =qunit>< / div>
< div id =qunit-fixture>< / div>
< script src =lib / requirejs / require.js>< / script>
< script src =mytests.js>< / script>
< / body>
< / html>

然后 mytests.js 文件:

  require.config({
paths:{
'qunit':'lib / qunit / qunit / qunit'
}
});

require(['qunit'],function(QUnit){

QUnit.start();

QUnit.module('My Module ');

QUnit.test('some normal test',function(assert){

assert.ok(true,'可以运行正常的QUnit测试');
$)

QUnit.test('一些异步测试',函数(assert){

var done = assert.async();

setTimeout(function(){

assert.ok(true,'可以运行异步QUnit测试');
done();

},50);
});
});


I've got a repository which is integrated with travis. I've got QUnit tests which I'd like to run from grunt/node server side and AMD (requirejs). This is the source of my AMD init.js:

(function () {
    require.config({
        baseUrl: "../src"
    });

    require(["../test/suites/basic",
        '../test/qunit-extend',
        'qunit'
    ], function(BasicTests) {
        QUnit.config.autoload = false;
        QUnit.config.autostart = false;
        BasicTests.run();
        QUnit.load();
        QUnit.start();
    });
}());

When I run those QUnit tests within my browser - everything works perfectly. But when I try to run them from grunt level (server-side using phantomjs), it fails. I get:

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

all the time. I was trying to do evetyrhing the same way as it's done in this tutorial, but still I get wrong results (phantom being hanged instead serving QUnit tests)...

解决方案

I am using grunt-contrib-qunit to run QUnit tests via grunt. It uses phantomjs internally.

I was getting the same error as the OP after upgrading grunt-contrib-qunit to the latest version (0.7.0):

PhantomJS timed out, possibly due to a missing QUnit start() call.

To fix this problem, I had to first load QUnit via require() and then execute QUnit.start() and define all my QUnit modules and tests after that.

The HTML file looks something like this:

<!DOCTYPE html>
<html>
<head>
    <title>QUnit + RequireJS + PhantomJS</title>
    <link rel="stylesheet" href="lib/qunit/qunit/qunit.css">
</head>
<body>
    <div id="qunit"></div>
    <div id="qunit-fixture"></div>
    <script src="lib/requirejs/require.js"></script>
    <script src="mytests.js"></script>
</body>
</html>

Then the mytests.js file:

require.config({
    paths: {
        'qunit': 'lib/qunit/qunit/qunit'
    }
});

require(['qunit'], function(QUnit) {

    QUnit.start();

    QUnit.module('My Module');

    QUnit.test('some normal test', function(assert) {

        assert.ok(true, 'can run a normal QUnit test');
    });

    QUnit.test('some asynchronous test', function(assert) {

        var done = assert.async();

        setTimeout(function() {

            assert.ok(true, 'can run an asynchronous QUnit test');
            done();

        }, 50);
    });
});

这篇关于咕噜声未在幻像上运行QUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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