简体   繁体   English

使用Zombie.js验证Qunit的结果

[英]Verifying Qunit's results with Zombie.js

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. 我正在使用Qunit进行测试驱动的开发:创建一个新函数时,我为此编写了测试,创建了该函数,重新加载了页面,如果所有测试都通过了,我会继续前进...尽管在开始时效果很好,一段时间后,它开始成为一个耗时的过程,因为所有测试都需要花费几秒钟来运行,因此每次刷新浏览器时都需要等待。

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 (eg $ 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). 为了解决该问题,我考虑过引入Zombie.js进行无头测试:想法是让Zombie.js连续检查网页(例如$ watch -n1 "node queryTheWebpage.js" )并向我在编码时使用Qunits的结果( Zombie.js ,由于Zombie.js不是“真正的”浏览器,所以我会打开浏览器并手动检查页面以进行验证)。

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);
});

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. 在控制台输出中,我确实看到Qunit测试容器<ol id="qunit-tests"></ol>但它为空,这意味着当调用visit回调函数时,测试尚未运行。

I've tried to use the wait function to wait for the tests to run, but unsuccessfully: 我尝试使用wait函数来等待测试运行,但未成功:

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>
    });    
});

I tried to play with the waitFor option (eg set to 5000 ms) but that didn't help either. 我尝试使用waitFor选项(例如,设置为5000 ms),但那也没有帮助。

Q1: Is what I'm trying to do making sense, or is there a much simpler way of doing something similar? Q1:我想做的事情有意义吗,或者有做类似事情的简单得多的方法吗?

Q2: Do you know how I could get Zombie.js to wait for the Qunit tests to run? 问题2:您知道如何让Zombie.js等待Qunit测试运行吗?

我不知道这是否对您有帮助,但是请看一下: http : //api.qunitjs.com/QUnit.done/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM