使用Zombie.js验证Qunit的结果 [英] Verifying Qunit's results with Zombie.js

查看:88
本文介绍了使用Zombie.js验证Qunit的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Qunit 进行测试驱动的开发:创建新功能时,我为它,创建函数,重新加载页面,如果所有测试都通过了,那么我继续进行下去...虽然这在开始时效果很好,但一段时间后它开始成为一个耗时的过程,因为所有测试都需要几秒钟的时间才能运行,那就是每次刷新浏览器时都必须等待的时间.

I am doing test-driven development with Qunit: when creating a new function, I write tests for it, create the function, reload the page, and if all the tests pass I move on... Whilst this works fine at the beginning, it starts to become a time consuming process after a while as all the tests take several seconds to run, and that's the time I have to wait for every time I refresh my browser.

为解决该问题,我考虑过引入 Zombie.js 来实现无头测试:想法是让Zombie.js连续检查网页(例如$ watch -n1 "node queryTheWebpage.js"),并在编码时向我报告Qunits的结果(有时会出现,因为Zombie.js不是真实的").浏览器,我将打开浏览器并手动检查页面以进行验证.)

In an attempt to workaround that problem, I thought about introducing Zombie.js to perform head-less testing: the idea is to have Zombie.js continuously check the webpage (e.g. $ watch -n1 "node queryTheWebpage.js") and report to me Qunits's results while coding (once in a while, as Zombie.js isn't a "real" browser, I would open up a browser and check the page manually to validate).

到目前为止,这里是我的节点/僵尸代码段的内容:

So far here is what I have for my node/Zombie piece of code:

browser.visit("http://localhost/mywebpage.html", function () {
        var qunit_tests = browser.query('body');
        console.log(qunit_tests.innerHTML);
});

在控制台输出中,我确实看到了Qunit测试容器<ol id="qunit-tests"></ol>,但是它为空,这意味着当调用visit回调函数时,测试没有运行.

In the console output I do see the Qunit tests container <ol id="qunit-tests"></ol> but it is empty which means when the visit callback function is called, the tests haven't run.

我尝试使用wait函数来等待测试运行,但未成功:

I've tried to use the wait function to wait for the tests to run, but unsuccessfully:

function waitForQunitToEnd(window) {
    var last = window.document.querySelector('selectorOfMyLastTest');
    var first_failed = window.document.querySelector('li.failed');
    return (last || first_failed);
}

browser.visit("http://localhost/mywebpage.html", function () {
    browser.wait(waitForQunitToEnd, function() {
        var qunit_tests = browser.query('body');
        console.log(qunit_tests.innerHTML); // still gives me empty <ol id="qunit-tests"></ol>
    });    
});

我尝试使用waitFor选项(例如设置为5000 ms),但这也无济于事.

I tried to play with the waitFor option (e.g. set to 5000ms) but that didn't help either.

问题1:我想做的是有意义的,还是有更简单的方法来做类似的事情?

第二季度:您知道如何让Zombie.js等待Qunit测试运行吗?

推荐答案

我不知道这是否对您有帮助,但请看以下内容:

I don't know if it will help you but look this : http://api.qunitjs.com/QUnit.done/

这篇关于使用Zombie.js验证Qunit的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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