如何使用Zombie.js阻止Grunt导致致命错误

时间:2018-08-26 23:11:59

标签: gruntjs mocha zombie.js broken-links

我正在尝试使用Grunt自动化测试,到目前为止,我的Mocha测试和JSHint测试运行良好,但是当我尝试检查断开的链接时,Grunt会导致错误。

这是我的Gruntfile:

module.exports = function(grunt) {
    // load plugins
    [
        'grunt-cafe-mocha',
        'grunt-contrib-jshint',
        'grunt-exec'
    ].forEach(function(task) {
        grunt.loadNpmTasks(task);
    });

    // configure plugins
    grunt.initConfig({
        cafemocha: {
            all: {src: 'qa/tests-*.js', options: {ui: 'tdd'}, }
        },
        jshint: {
            app: ['meadowlark.js', 'public/js/**/*.js', 'lib/**/*.js'],
            qa: ['Gruntfile.js', 'public/qa/**/*.js', 'qa/**/*.js'],
        },
        exec: {
            blc: {command: 'blc -ro http://localhost:3000'}
        },
    });

    // register tasks
    grunt.registerTask('default', ['cafemocha', 'jshint', 'exec']);
};

其中blc是断开链接检查器节点模块。

运行grunt时,得到以下输出:

user:meadowlark-travel user$ grunt --stack
Running "cafemocha:all" (cafemocha) task

  ․ Cross-Page Tests requesting a group rate quote from the hood river tour page should populate the referrer field: 57ms
  ․ Cross-Page Tests requesting a group rate quote from the oregon coast tour page should populatte the referrer field: 13ms
  ․ Cross-Page Tests visiting the "request group rate" page should directly result in an empty referrer field: 5ms
  ․ Fortune Cookie Tests getFortune() should return a fortune: 1ms

  4 passing (301ms)


Running "jshint:app" (jshint) task
>> 2 files lint free.

Running "jshint:qa" (jshint) task
>> 5 files lint free.

Running "exec:blc" (exec) task
Fatal error: No link matching '.requestGroupRate'
AssertionError: No link matching '.requestGroupRate'
  at Browser.clickLink (/Users/user/Desktop/GitHub/meadowlark-travel/node_modules/zombie/lib/index.js:553:5)
  at /Users/user/Desktop/GitHub/meadowlark-travel/qa/tests-crosspage.js:19:21
  at EventLoop.done (/Users/user/Desktop/GitHub/meadowlark-travel/node_modules/zombie/lib/eventloop.js:424:9)
  at EventLoop.g (events.js:292:16)
  at emitNone (events.js:91:20)
  at EventLoop.emit (events.js:185:7)
  at Immediate.error (/Users/user/Desktop/GitHub/meadowlark-travel/node_modules/zombie/lib/eventloop.js:515:65)
  at runCallback (timers.js:672:20)
  at tryOnImmediate (timers.js:645:5)
  at processImmediate [as _immediateCallback] (timers.js:617:5)

无论如何运行blc -ro http://localhost:3000,我都会得到以下输出:

Getting links from: http://localhost:3000/
├───OK─── http://localhost:3000/img/logo.jpg
├───OK─── http://localhost:3000/about
Finished! 3 links found. 1 excluded. 0 broken.

Getting links from: http://localhost:3000/about
├───OK─── http://localhost:3000/tours/hood-river
├───OK─── http://localhost:3000/tours/oregon-coast
Finished! 4 links found. 2 excluded. 0 broken.

Getting links from: http://localhost:3000/tours/hood-river
├───OK─── http://localhost:3000/tours/request-group-rate
Finished! 3 links found. 2 excluded. 0 broken.

Getting links from: http://localhost:3000/tours/oregon-coast
Finished! 3 links found. 3 excluded. 0 broken.

Getting links from: http://localhost:3000/tours/request-group-rate
Finished! 2 links found. 2 excluded. 0 broken.

Finished! 15 links found. 10 excluded. 0 broken.
Elapsed time: 0 seconds

因此,当我在命令行中检查断开的链接时,它可以工作,但是当它运行在咕run声中时,它不起作用。在检查qa/tests-crosspage.js:19:21的错误来源之后,它似乎是由qa / tests-crosspage.js中的以下代码行引起的:

it('requesting a group rate quote from the hood river tour page ' +
        'should populate the referrer field', function() {
        var referrer = 'http://localhost:3000/tours/hood-river';
        browser.visit(referrer, function() {
       -->  browser.clickLink('.requestGroupRate', function(done) {
                assert.equal(browser.field('referrer').value, referrer);
                done();
            });
        });
    });

检查Zombie文档和Mocha文档之后,我看不到为什么出现错误。有人能看到为什么链接检查器在命令行中可以工作,而自动化时却不能工作吗?

0 个答案:

没有答案