运行茉莉花测试时Grunt超时

时间:2014-07-11 17:47:46

标签: gruntjs jasmine phantomjs

我正在努力学习使用Grunt ......

当我在Jasmine spec runner中运行以下测试时:

http://memory-card-game.herokuapp.com/spec-runner.html

他们工作......需要时间,因为最后一次测试会玩整个游戏。我将该测试的超时时间提高到60000,并且它可以在Jasmine中运行

但是当我尝试使用Grunt运行测试时,它不允许完成游戏测试。如何启动PhantomJS超时以使此测试有足够的时间来完成?

Game Card
   ✓ can be created with a value   
   ✓ has a DOM element for the card   
   ✓ can flip   
   ✓ can be discarded   
 Game Deck
   ✓ can be created   
   ✓ can hold cards   
   ✓ can shuffle   
 Event Caller
   ✓ can be created   
   ✓ can be inherited   
   ✓ should add subscribers   
   ✓ should remove subscribers   
   ✓ should emit events   
   ✓ should emit with arguments   
 Memory Game
   Starting the Game
     ✓ should be able to create a new game   
     ✓ should deal the game cards to a DOM Element   
     ✓ should emit 'deal' event   
     ✓ should deal shuffled cards   
     ✓ should be able to create a game in debug mode   
   Playing the Game
     ✓ should be able to flip over one card   
     flipping over two cards
       ✓ should emit 'match' event   
       ✓ should flip over mismatched cards   
       ✓ should remove matched cards   
       ✓ should not allow a third card flip   
   Ending the Game
     - should emit 'end' event...
Warning: PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue.

Grunt文件:

module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        jasmine: {
            src: ["public/js/*.js", "!public/js/main.js"],
            timeout: 60000,
            options: {
                specs: "public/test/*-spec.js"
            },
            phantomjs : {
                resourceTimeout : 60000
            }
        }
    });
    grunt.loadNpmTasks("grunt-contrib-jasmine");
    grunt.registerTask("test", ["jasmine"]);
    grunt.registerTask("default", ["test"]);
};

2 个答案:

答案 0 :(得分:0)

我有类似的问题。在我的例子中,我使用innerHTML创建了一个动态HTML。 我用innerHTML取代了夹具,解决了问题。

答案 1 :(得分:0)

我一直在努力修复与Warning: PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue错误相关的类似问题。

我认为这是因为我们使用的Jasmine异步测试与PhantomJS / Grunt / grunt-contrib-jasmine结合使用。但经过大量的时间和调查,我发现它与我们的一些测试被清理的方式有关:

afterEach(function () {
    $body.empty();
});

在这个例子中,我们清空了为测试注入DOM的所有元素。但这并没有解除所有在后台徘徊并导致PhantomJS最终超时的JS代码。这阻止了进一步的Grunt任务运行报告。

这是更好的技巧:

afterEach(function () {
    $element.remove();
    $nav.remove();
});

应该单独删除添加到DOM中的元素,以确保正确删除和清理与其关联的所有JS,为下一个规范做好准备。

这意味着我们可以在没有PhantomJS超时的情况下完成大量的77个规格。