茉莉花节点测试执行了两次

Jasmine-node tests executed twice

我的 jasmine-node 测试执行了两次。

I 运行 那些来自 G运行t 任务和 Jasmine 命令的测试。结果是一样的,我的测试是 运行 两次。 我的 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 "
  }
}

这是我的 Gruntfile.js 摘录:

    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');

我的一个测试文件:

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();
    });
});

我有 2 个测试文件用于 4 个断言

这是我的提示:

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

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

你有什么想法吗?

全部归功于1.618. He answered the question here:

这看起来像是一些错误行为。快速修复是在 Gruntfile 中配置 jasmine_node,如下所示:

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

关键是all参数。 grunt 插件正在寻找名称中带有 spec 的文件。出于某种原因,它会在 spec/ 目录 其他任何地方查找。如果您指定 spec 目录,它的文件会被拾取两次。如果你不指定,它只会被设置一次,但是你不能把 spec 放在你的任何非测试文件名中。