Как вы не позволяете Grunt вызывать фатальные ошибки с Zombie.js? - PullRequest
0 голосов
/ 27 августа 2018

Я пытаюсь автоматизировать тестирование с помощью 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

Поэтому, когда я проверяю битые ссылки в командной строке, он работает, но когда он запускается в grunt, он не работает.После проверки 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 я не вижупочему есть ошибка.Кто-нибудь может понять, почему средство проверки ссылок работает в командной строке, хотя оно не работает в автоматическом режиме?

...