grunt not running QUnit tests on phantom

前端 未结 2 1233
無奈伤痛
無奈伤痛 2020-12-11 05:38

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 m

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 06:26

    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:

    
    
    
        QUnit + RequireJS + PhantomJS
        
    
    
        

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

提交回复
热议问题