使用Grunt运行Karma时出现断开连接错误

时间:2014-05-01 16:56:19

标签: macos angularjs gruntjs karma-runner

我正在以角度js构建一个应用程序。使用Grunt进行构建和测试自动化。使用Karma进行端到端测试时控制器:

myapp.controller("LoginController", ["$rootScope","$routeParams", "$location", function($rootScope, $routeParams, $location){

       this.errorMessage = $routeParams.error;

       this.login = function(user){
            var realUser = $rootScope.userFactory.contains(user);

            if(realUser !== null){
                $rootScope.user = realUser;
                $location.path("/timeline");
            }else{
                $location.path("/login/User not found");
            }
       };

 }]);




//End to end test
describe('myapp', function() {
  beforeEach(function() {
     browser().navigateTo('/');
  });

   it('should jump to the /login path when / is accessed', function() {
    browser().navigateTo('#/');
    expect(browser().location().path()).toBe("/login");
  });

  it('ensures user can log in', function() {
    browser().navigateTo('#/login');
    expect(browser().location().path()).toBe("/login");


    input('loginController.user.email').enter('pawan@gmail.com');
    element('#login').click();

    //Hangs here
    expect(browser().location().path()).toBe("/timeline");

    expect(element('#user').text()).toContain('Pawan');
  });


});

我的应用程序工作得非常好。当我运行这个测试。我可以看到它添加了电子邮件地址并单击登录,它导航到下一页。但是当前的URL保持登录状态,并且在路径检查断言时也会挂起。然后在几首歌之后,我得到以下错误。

  

INFO [launcher]:启动浏览器PhantomJS

     

INFO [PhantomJS 1.9.7(Mac OS X)]:已连接到套接字   7nK388s7MRSern41rKPH,ID为27432528

     

PhantomJS 1.9.7(Mac OS X):执行2次成功中的1次(0秒/0.833)   秒)

     

PhantomJS 1.9.7(Mac OS X):执行1 of 2 DISCONNECTED(10.78秒/   0.833秒)

     

警告:任务"业力:e2e"失败。使用--force继续。

     

因警告而中止。

配置文件:

// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html

module.exports = function(config) {
  config.set({
    // base path, that will be used to resolve files and exclude
    basePath: '',

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['ng-scenario'],

    // list of files / patterns to load in the browser
    files: [
      'test/e2e/**/*.js'
    ],

    // list of files / patterns to exclude
    exclude: [],

    // web server port
    port: 8080,

    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,

    plugins : ['karma-ng-scenario', 'karma-jasmine', 'karma-phantomjs-launcher'],

    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false,

    // Uncomment the following lines if you are using grunt's server to run the tests
     proxies: {
       '/': 'http://0.0.0.0:9000/'
     },
    // URL root prevent conflicts with the site root
     urlRoot: '_karma_'
  });
};

0 个答案:

没有答案