Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any "mocha maven plugin"?

I would like to check if there is any plugin that exists for running mocha test cases in maven test phase, and to return BUILD SUCCESS or FAILURE based on test result

-lucky

like image 716
lucky Avatar asked Nov 07 '13 06:11

lucky


1 Answers

I was interested in the question too. I'm testing the nodejs code, so it may be not very relevant. No success so far discovering the plugin I need, but if you need only the failing build process you can use maven-antrun-plugin like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>

        <execution>
            <id>test-nodejs</id>
            <phase>test</phase>
            <configuration>
                <tasks name="Run mocha tests">
                    <exec dir="${basedir}"
                          executable="npm"
                          failonerror="true">
                        <arg value="test"/>
                    </exec>
                </tasks>
            </configuration>

            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Pay attention to failonerror argument.

One more thing to note (in case of NodeJS) - you need to setup the package.json file to support npm test command, e.g.

"scripts": {
  "test" : "mocha -R tap"
},

and your tests should reside in test folder. Also, mocha treats subfolder well enough, so you can make reasonable test case folder structure.

like image 160
Mr_Mig Avatar answered Oct 02 '22 08:10

Mr_Mig