【问题标题】:How do I get Yeoman to continuously run tests如何让 Yeoman 持续运行测试
【发布时间】:2013-08-24 03:21:02
【问题描述】:

当我运行 grunt server 时,我的文件编辑被拾取并且浏览器通过 livereload 刷新。 当我运行 grunt test 时,它运行一次并关闭。

这种行为可以通过运行来模拟

yo angular --minsafe mytest
grunt test

当我在 Gruntfile 中更改 karma.unit.singlerun = false 时,grunt 测试现在表示正在运行观察程序,但似乎没有文件更改触发再次运行测试。

如何通过类似于 linemanjs 工作方式的测试获得重新加载功能?

【问题讨论】:

    标签: gruntjs yeoman


    【解决方案1】:

    你快到了!您可以在名为autoWatch 的 Gruntfile 中设置一个额外的选项,该选项会监视您在 karma.conf.js 中指定的文件以进行更改。 Gruntfile 中的完整条目可能如下所示:

    karma: {
      unit: {
        configFile: 'karma.conf.js',
        singleRun: true,
        autoWatch: false
      },
      server: {
        configFile: 'karma.conf.js',
        singleRun: false,
        autoWatch: true
      }
    }
    

    【讨论】:

    • 太棒了!效果很好。我显然不了解任务的上下文。
    • 这很容易出错,因为业力整合目前有点半生不熟。因为 karma 和 grunt 有单独的监视机制,所以它们目前不能像应有的那样协同工作。
    • 如何让它运行“服务器”配置而不是“单元”配置?
    • 谢谢@passy。你拯救了我的一天。
    • 在一行写着 grunt.registerTask('test, [... change 'karma' to karma:server'
    【解决方案2】:

    我设置如下

    karma: {
          unit: {
            configFile: 'karma.conf.js',
            singleRun: false,
            autoWatch: true
          }
        }
    

    当我更改文件时,它可以正常运行但无法重新运行单元测试,grunt karma:unit output

    PhantomJS 1.9.7 (Linux) Controller: MainCtrl should attach a list of awesomeThings to the scope FAILED
            Expected 3 to be 100.
    PhantomJS 1.9.7 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.04 secs / 0.014 secs)
    

    找到它:我在 Virtual 中使用共享文件夹并在虚拟机外部更改它,以便 autoWatch 无法识别这些更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多