karma-runner / karma

Spectacular Test Runner for JavaScript
http://karma-runner.github.io
MIT License
11.96k stars 1.71k forks source link

When running on Travis, Karma reports 0 of N tests executed #1344

Open agibalov opened 9 years ago

agibalov commented 9 years ago

I'm trying to make my Karma/Angular tests work on Travis as described here, but it keeps saying that 0 tests were executed:

Running "karma:test" (karma) task
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser Firefox
INFO [Firefox 31.0.0 (Linux)]: Connected on socket C7AVrV2cfPpQquGp3ew4 with id 60880131
Firefox 31.0.0 (Linux): Executed 0 of 4 SUCCESS (0 secs / 0 secs)

There's no such issue when I run the same thing locally, it reports "4 of 4". There's also a blog post by @Swizec where eventually the same result described: "Executed 0 of 114 SUCCESS" (there's a screenshot at the very end).

Here's my set up:

.travis.yml
language: node_js
node_js:
 - '0.11'
before_script:
 - export DISPLAY=:99.0
 - sh -e /etc/init.d/xvfb start
karma.conf.js
module.exports = function(config) {
  var c = {
    basePath: './',

    files: [...],

    autoWatch: true,
    frameworks: ['jasmine'],
    browsers: ['Firefox'],
    plugins: [
      'karma-firefox-launcher',
      'karma-jasmine'
    ]
  };  

  config.set(c);
};
Gruntfile.js
module.exports = function(grunt) {
  grunt.initConfig({
    ...
    karma: {
      options: {
        configFile: 'karma.conf.js'
      },
      'test': {
        singleRun: true
      }
    },
    ...  
  });

  ...
  grunt.loadNpmTasks("grunt-karma");
  ...

  ...
  grunt.registerTask("fe-test", ["karma:test"]);
  ...
};

Did I miss something?

Swizec commented 9 years ago

Hey,

what do your tests look like?

The output from the project I was writing about in that blogpost looks more like this these days:

screen shot 2015-03-11 at 23 40 19

agibalov commented 9 years ago

Nothing special:

describe('AppController', function() {
  var appController;
  var $scope;
  var $location;

  beforeEach(module('app'));

  beforeEach(inject(function($controller, $rootScope, _$location_) {
    $scope = $rootScope;
    $location = _$location_;

    appController = $controller('AppController', { 
      $scope: $scope,  
      $location: $location
    });
  }));

  it('should say that "notes" is active when location is /notes', function() {    
    $location.path('/notes');
    $scope.$apply();

    expect($scope.isNavBarActive('notes')).toBe(true);
    expect($scope.isNavBarActive('categories')).toBe(false);
  });

  // 3 more like this ^^^
});
maksimr commented 9 years ago

@loki2302 can you show project or create stub project which reproduce this problem?

Thanks

agibalov commented 9 years ago

@maksimr sure:

To run the tests: npm install && bower install && grunt fe-test. Locally, the result is:

...
Running "karma:test" (karma) task
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 41.0.2272 (Linux)]: Connected on socket 0onsddvNPuRq4dm8GUnb with id 97479661
Chrome 41.0.2272 (Linux): Executed 11 of 11 SUCCESS (0.151 secs / 0.146 secs)

When running on Travis, Karma is configured to use Firefox. Outside Travis it uses Chrome. But I've already tried Firefox locally and it worked fine.

maksimr commented 9 years ago

@loki2302 thaks

Seems tests are run, but report is broken

agibalov commented 9 years ago

@maksimr Oh, that's good news. Any chance I can have it fixed via configuration file only?

tnajdek commented 9 years ago

Had the same issue (tests running but reporter says 0 out of N). Changed reporter to "dots" now says correctly N out of N.

bernardolm commented 8 years ago

To me, removing `restartOnFileChange: true' from my karma conf solved this error.