【问题标题】:how do I modify a mocha reporter before a grunt test run?如何在 grunt 测试运行之前修改 mocha 记者?
【发布时间】:2013-05-20 14:18:21
【问题描述】:

我已经用 mocha 设置了 grunt。它运行良好,但如果测试不时失败,我想获得更详细的报告。自然我只想运行grunt detailedTest 而不是每次都修改 grunt 文件。我以为我可以:

  • 创建一个名为detailedTest 的新grunt 任务
  • 设置该测试以更改摩卡测试仪的配置
  • 然后运行测试

看起来像:

  grunt.initConfig
    watch:
  ...
  mochaTest:
      files: [ 'test/calc/*.coffee', 'test/*.coffee']
    mochaTestConfig:
      options:
        reporter: 'nyan'
        timeout: 500

grunt.registerTask "spectest", ->
  grunt.config "mochaTestConfig:options:reporter", "spec"
  grunt.log.writeln('done with config: ' 
    + grunt.config "mochaTestConfig:options:reporter")
  grunt.task.run('mochaTest')

然后输出:

$ grunt spectest
Running "spectest" task
done with config: spec

Running "mochaTest:files" (mochaTest) task
 230 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ ...etc 

该死的,那不是规格记者。如何在测试前修改配置?或者我应该以某种方式从命令行将值传递给 grunt?

【问题讨论】:

    标签: coffeescript mocha.js gruntjs


    【解决方案1】:

    5 分钟后,自然而然。诀窍是访问 grunt 测试是在命令行中使用: 完成的:grunt watch:coffee。但是您可以通过. 符号修改该配置:

    grunt.registerTask "spectest", ->
        configPos = "mochaTestConfig.options.reporter"
        grunt.log.writeln('before modif config: ' + grunt.config configPos) # nyan
        grunt.config configPos, "spec"
        grunt.log.writeln('after modif with config: ' + grunt.config configPos) # spec 
        grunt.task.run('mochaTest')
    

    【讨论】:

    • 有什么理由不使用grunt-mocha
    • @kmiyashiro 是什么让你认为我不是?
    • mochaTest, mochaTestConfig
    • @kmiyashiro github.com/pghalliday/grunt-mocha-test;根据 grunt-mocha 页面,grunt-mocha 用于客户端。
    猜你喜欢
    • 2016-10-14
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 2019-09-28
    • 2015-11-28
    • 2014-10-21
    • 1970-01-01
    相关资源
    最近更新 更多