Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Karma JavaScript testing with Maven

I'm adding Karma-based JS unit tests to Maven. I used the following configuration:

<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>

Tests work separately (without Maven) on my machine when I use karma start karma.conf.js, but with Maven I got the following error:

[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

Here is why I find it a bit strange: according to this class, the karma.conf.js should be found by default (@Parameter(defaultValue = "${basedir}/karma.conf.js", property = "configFile", required = true)). Also, I tried to pass the path, absolute and relative, in the -DconfigFile=... parameter, it didn't work. I used Windows, but I think it shouldn't be a problem. I'm not sure what exactly can be wrong in the configuration, an advice would be appreciated.

like image 777
John Doe Avatar asked Nov 29 '25 04:11

John Doe


1 Answers

I think it was a bug, that's already fixed.

I tried to run tests again with version 1.2-SNAPSHOT of this plugin (cloned it and built) and it started the Karma properly.

like image 72
John Doe Avatar answered Nov 30 '25 17:11

John Doe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!