Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt jasmine-node tests are running twice

I set up grunt to run node.js jasmine tests. For some reason, with this config, the results always show double the tests.

Here is my config:

I'm using jasmine-node which plugs into grunt.

/spec/some-spec.js:

var myModule = require('../src/myModule.js');
describe('test', function(){
     it('works', function(done){
         setTimeout(function(){
             expect(1).toBe(1);
             done();
         }, 100);
     });
});

Gruntfile.js:

module.exports = function(grunt) {
    grunt.initConfig({
        jasmine_node: {
            options: {
                forceExit: true
            },
            all: ['spec/']
        }
    });
    grunt.loadNpmTasks('grunt-jasmine-node');
    grunt.registerTask('default', ['jasmine_node']);
};

This results in two tests running rather than one.

> grunt
Running "jasmine_node:all" (jasmine_node) task
..

Finished in 0.216 seconds
2 tests, 2 assertions, 0 failures, 0 skipped
like image 378
d-_-b Avatar asked May 08 '15 07:05

d-_-b


1 Answers

I was able to reproduce the behavior. This is what seems to be happening:

  1. The task looks in the specified folder (spec in your case) for files with spec in the name.
  2. Then it looks again in every folder in the whole project for files with spec in the name.

What it ends up with is 2 overlapping sets of test files to run.

My first attempt at trying to coerce it into more logical behavior was to set specNameMatcher: null (default is 'spec'), and leave the folder set to 'spec/'. This results in no tests being run, since apparently both conditions (name and folder) must be met for files in the specified folder. You get the same problem if specNameMatcher is left at the default value, but the files in the folder don't have 'spec' in the name.

What does work is to set the folder (or 'test set' or whatever you want to call it) to []:

    jasmine_node: {
        options: {
            forceExit: true
        },
        all: []
    }

The catch is that if you have any other files somewhere else in the project with 'spec' in the name, they'll be mistaken for tests by jasmine.

I would consider this behavior a bug, and it should probably be reported via the project's github issues page.

like image 78
1.618 Avatar answered Sep 18 '22 19:09

1.618