Search code examples
node.jstddjasminejasmine-node

Jasmine-node tests executed twice


My jasmine-node tests are executed twice.

I run those test from Grunt task and also from Jasmine command. Result is the same my tests are run twice. My package.json :

{
  "name": "test",
  "version": "0.0.0",
  "dependencies": {
    "express": "4.x",
    "mongodb": "~2.0"
  },
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-jasmine-node":"~0.3.1 "
  }
}

Here is my Gruntfile.js extract :

    grunt.initConfig({
    jasmine_node: {
      options: {
        forceExit: true,
        match: '.',
        matchall: true,
        extensions: 'js',
        specNameMatcher: 'spec'
      },
      all: ['test/']
    }
  });
  grunt.loadNpmTasks('grunt-jasmine-node');
  grunt.registerTask('jasmine', 'jasmine_node');

One of my test file :

describe("Configuration setup", function() {
    it("should load local configurations", function(next) {
        var config = require('../config')();
        expect(config.mode).toBe('local');
        next();
    });
    it("should load staging configurations", function(next) {
        var config = require('../config')('staging');
        expect(config.mode).toBe('staging');
        next();
    });
    it("should load production configurations", function(next) {
        var config = require('../config')('production');
        expect(config.mode).toBe('production');
        next();
    });
});

I have 2 test files for 4 assertions

Here is my prompt :

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

Finished in 1.781 seconds
8 tests, 8 assertions, 0 failures, 0 skipped

Have you got any idea ?


Solution

  • All credit to 1.618. He answered the question here: grunt jasmine-node tests are running twice

    This looks likes some buggy behaviour. The quick fix is to configure jasmine_node in your Gruntfile like this:

    jasmine_node: {
        options: {
            forceExit: true,
            host: 'http://localhost:' + port + '/',
            match: '.',
            matchall: false,
            extensions: 'js',
            specNameMatcher: '[sS]pec'
        },
        all: []
    }
    

    The key is the all parameter. The grunt plugin is looking for files with spec in the name. For some reason, it looks in the spec/ directory and everywhere else. If you specify the spec directory, its files get picked up twice. If you don't specify, it only gets set once, but then you can't put spec in any of your non-test filenames.