我正在将基于Karma的JS单元测试添加到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>
当我在我的计算机上使用 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
这是我觉得有点奇怪的原因:根据这个类,
karma.conf.js
应该是默认被找到的(@Parameter(defaultValue = "${basedir}/karma.conf.js", property = "configFile", required = true)
)。同时,我尝试通过-DconfigFile=...
参数传递路径,绝对和相对路径都试了一下,但没有成功。我使用的是Windows系统,但我认为这不应该是问题所在。我不确定配置中可能出了什么问题,希望能得到您的建议。