我正在向Maven添加基于Karma的JS单元测试。我使用了以下配置:
<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>
当我使用karma start karma.conf.js
时,测试在我的机器上单独工作(没有Maven),但是对于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,但我认为这应该不是问题。我不确定配置中究竟出现了什么问题,建议将不胜感激。
答案 0 :(得分:1)
我认为这是一个错误,已经修复了。
我尝试使用此插件的版本1.2-SNAPSHOT
再次运行测试(克隆并构建)并正确启动了Karma。
答案 1 :(得分:0)
在我看来karma.conf.js就位(即参数确实有效)但是“karma”可执行文件不是,根据
final ProcessBuilder builder = new ProcessBuilder("karma", "start", configFile.getAbsolutePath());
来自您提到过的文件。