10

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

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

yo angular --minsafe mytest
grunt test

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

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

4

2 回答 2

16

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

karma: {
  unit: {
    configFile: 'karma.conf.js',
    singleRun: true,
    autoWatch: false
  },
  server: {
    configFile: 'karma.conf.js',
    singleRun: false,
    autoWatch: true
  }
}
于 2013-08-24T17:31:46.740 回答
0

我设置如下

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 无法识别这些更改。

于 2014-05-08T16:16:06.180 回答