karma-runner / maven-karma-plugin

Maven plugin for running tests using Karma.
Apache License 2.0
45 stars 26 forks source link

Add support for detecting and exporting 'test-results.xml' for surefire integration #15

Closed jaymes-bearden closed 10 years ago

jaymes-bearden commented 11 years ago

Currently, we have the plugin configured like so:

<plugin>
    <groupId>com.kelveden</groupId>
    <artifactId>maven-karma-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <configFile>src/main/webapp/resources/karma-0.10.2.conf.js</configFile>
        <browsers>PhantomJS</browsers>
        <autoWatch>false</autoWatch>
        <singleRun>true</singleRun>
        <reporters>dots,junit</reporters>
    </configuration>
</plugin>

which allows us to execute PhantomJS with the junit reporter exporting the results to the src/main/webapp/resources/directory as test-results.xml (using the default configuration).

We would love another configuration option that could somehow export the test-results in a manor that could integrate with Surefire.

As a workaround, we do the following:

<!-- Post Test execution goals. Move the Karma results to the surefire reports directory -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo>Moving karma test results</echo>
                    <copy file="src/main/webapp/resources/test-results.xml" tofile="${basedir}/target/surefire-reports/test-results.xml"/>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

which as you can see is slightly hacky. Perhaps there's a better way to do this?

jaymes-bearden commented 11 years ago

Note: This is for our CI server, Bamboo so we can view the results after the build has completed.

janeklb commented 10 years ago

@jaymes-bearden I managed to get this working without using antrun by adding <phase>process-test-classes</phase> to maven-karma-plugin's <execution>...</execution> in the pom. I believe this causes the karma tests to be run before surefire, which then aggregates everything in target/surefire-reports.. so as long as you output karma reports into target/surefire-reports it should be fine.

kelveden commented 10 years ago

Closed with #16.