2013-04-16 104 views
3

我將基於Karma的JS單元測試添加到Maven。我使用了以下配置:我的機器上將Karma JavaScript測試與Maven集成

<plugin> 
    <groupId>com.kelveden</groupId> 
    <artifactId>maven-karma-plugin</artifactId> 
    <version>1.0</version> 
    <executions> 
     <execution> 
      <goals> 
       <goal>start</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <browsers>Chrome</browsers> 
    </configuration> 
</plugin> 

測試單獨進行工作(無Maven的)當我使用karma start karma.conf.js,但與Maven我得到了以下錯誤:

[ERROR] Failed to execute goal com.kelveden:maven-karma-plugin:1.0:start (default) 
on project web: There was an error executing Karma. Cannot run program "karma": 
CreateProcess error=2, The system cannot find the file specified -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal 
com.kelveden:maven-karma-plugin:1.0:start (default) on project web: 
There was an error executing Karma. 
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217) 
... 
Caused by: java.io.IOException: Cannot run program "karma": CreateProcess error=2, 
The system cannot find the file specified 
     at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) 
     at com.kelveden.karma.StartMojo.createKarmaProcess(StartMojo.java:151) 
     ... 22 more 
Caused by: java.io.IOException: CreateProcess error=2, 
The system cannot find the file specified 
     at java.lang.ProcessImpl.create(Native Method) 
     at java.lang.ProcessImpl.<init>(ProcessImpl.java:81) 
     at java.lang.ProcessImpl.start(ProcessImpl.java:30) 
     at java.lang.ProcessBuilder.start(ProcessBuilder.java:453) 
     ... 23 more 

這是爲什麼我覺得這有點奇怪:根據this class,默認應該找到karma.conf.js@Parameter(defaultValue = "${basedir}/karma.conf.js", property = "configFile", required = true))。另外,我試圖在-DconfigFile=...參數中傳遞絕對路徑和相對路徑,但它不起作用。我使用Windows,但我認爲這不應該是一個問題。我不確定配置中究竟會發生什麼錯誤,我們將不勝感激。

回答

1

我認爲這是一個bug,已經修復了。

我試着用這個插件的版本1.2-SNAPSHOT再次運行測試(克隆它並構建),它正確地開始了Karma。

0

它看起來對我說karma.conf.js到位(即參數不工作),而是「因果報應」可執行文件不存在,按照

final ProcessBuilder builder = new ProcessBuilder("karma", "start", configFile.getAbsolutePath());

從您已將檔案提及。