简体   繁体   English

Jasmine节点测试执行了两次

[英]Jasmine-node tests executed twice

My jasmine-node tests are executed twice. 我的茉莉花节点测试执行了两次。

I run those test from Grunt task and also from Jasmine command. 我从Grunt任务和Jasmine命令运行那些测试。 Result is the same my tests are run twice. 结果与我的测试运行两次相同。 My package.json : 我的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 : 这是我的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');

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 我有4个断言的2个测试文件

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 ? 你有什么想法吗?

All credit to 1.618 . 全部归功于1.618 He answered the question here: grunt jasmine-node tests are running twice 他在这里回答了这个问题: grunt jasmine-node测试运行了两次

This looks likes some buggy behaviour. 这看起来像一些越野行为。 The quick fix is to configure jasmine_node in your Gruntfile like this: 速战速决是配置jasmine_nodeGruntfile这样的:

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

The key is the all parameter. 关键是all参数。 The grunt plugin is looking for files with spec in the name. grunt插件正在寻找名称中带有spec的文件。 For some reason, it looks in the spec/ directory and everywhere else. 出于某种原因,它在spec/目录其他地方查找。 If you specify the spec directory, its files get picked up twice. 如果指定spec目录,则会将其文件拾取两次。 If you don't specify, it only gets set once, but then you can't put spec in any of your non-test filenames. 如果您没有指定,它只会被设置一次,但是您不能将spec放入任何非测试文件名中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM