将测试日志保存到磁盘?

时间:2014-09-20 09:28:37

标签: gruntjs mocha

这是我的Gruntfile:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    mochaTest: {
      test: {

        options: {
          reporter: 'spec',
          clearRequireCache: true,
          require: ['./index.js']
        },
        src: ['test/**/*.coffee']
      },
      report: {

        options: {
          reporter: 'markdown',
          clearRequireCache: true,
          require: ['./index.js']
        },
        src: ['test/**/*.coffee'],
        dest: './FEATURES.md'
      }

    },
    watch: {
      test: {
        options: {
          spawn: false,
        },
        files: ['src/**/*.coffee', 'test/**/*.coffee'],
        tasks: ['coffee:main', 'mochaTest']
      }
    },
    coffee: {

      main: {
        options: {
          bare: true
        },

        files: [{
          expand: true,
          cwd: "./src",
          src: ["**/*.coffee"],
          dest: "./lib",
          ext: ".js"
        }]
      },


    }
  });
  grunt.loadNpmTasks('grunt-contrib-coffee');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-mocha-test');

  // Default task(s).
  grunt.registerTask('default', ['coffee:main', 'mochaTest:test', 'watch']);
  grunt.registerTask('test', ['coffee:main', 'mochaTest:test']);
  grunt.registerTask('report', ['coffee:main', 'mochaTest:report']);

};

当我运行grunt时,它会测试并使用报告作为规范进行监视,但是当我运行grunt report时,它会向我显示markdown中的输出,尽管在项目的根目录中没有创建文件。是否有可能使markdown报告输出coffeescript代码标签而不是js?有没有办法通过y代码删除任何记录的输出?

1 个答案:

答案 0 :(得分:1)

grunt-mocha-test 插件没有 dest 选项。我认为您正在寻找 captureFile

要从控制台删除所有输出,您可以将安静设置为true。

这是您更新的mochaTest:report

report: {
  options: {
    reporter: 'markdown',
    clearRequireCache: true,
    require: ['./index.js'],
    quiet: true,
    captureFile: 'FEATURES.md'
  },
  src: ['test/**/*.coffee']
}

对于您的第二个问题,您可以查看所有摩卡记者here的列表和更简洁的列表here,但还没有咖啡。