This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
forked from linsolas/casperjs-runner-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'casperjs/master'
Conflicts: src/main/java/com/github/casperjs/casperjsrunner/AbstractCasperJSRunnerMojo.java
- Loading branch information
Showing
9 changed files
with
264 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
invoker.goals=verify | ||
invoker.buildResult=failure | ||
invoker.failureBehavior=fail-at-end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.github.casperjs</groupId> | ||
<artifactId>integration-test</artifactId> | ||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
|
||
<name>CasperJS Runner :: integration-test</name> | ||
|
||
<url>no-url</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<casperjs.verbose>true</casperjs.verbose> | ||
</properties> | ||
|
||
<build> | ||
|
||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.casperjs</groupId> | ||
<artifactId>casperjs-runner-maven-plugin</artifactId> | ||
<version>@pom.version@</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>com.github.casperjs</groupId> | ||
<artifactId>casperjs-runner-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>integration-test</id> | ||
<goals> | ||
<goal>integration-test</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>verify</id> | ||
<goals> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<ignoreTestFailures>true</ignoreTestFailures> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
|
||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
file = new File(basedir, 'build.log'); | ||
assert file.exists(); | ||
assert file.text.contains('casperjs-runner-maven-plugin'); | ||
assert file.text.contains('Execution of test test.js'); | ||
assert file.text.contains('Test \'test.js\' has failure'); | ||
assert file.text.contains('Execution of test test.coffee'); | ||
assert file.text.contains('Test \'test.coffee\' has failure'); | ||
assert file.text.contains('FAIL 2 tests executed'); | ||
assert file.text.contains('1 passed, 1 failed'); | ||
assert file.text.contains('Tests run: 2, Success: 0 Failures: 2. Time elapsed:'); | ||
assert file.text.contains('Integration test verification error'); | ||
|
||
return true; |
4 changes: 4 additions & 0 deletions
4
src/it/casperjs-runner/integration-test/src/test/casperjs/test.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
casper.test.begin 'Fake test', 2, (test) -> | ||
test.assert true, 'true is so true' | ||
test.assert false, 'false is so wrong' | ||
test.done() |
5 changes: 5 additions & 0 deletions
5
src/it/casperjs-runner/integration-test/src/test/casperjs/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
casper.test.begin('Fake test', 2, function(test) { | ||
test.assert(true, 'true is so true'); | ||
test.assert(false, 'false is so wrong'); | ||
test.done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/com/github/casperjs/casperjsrunner/CasperJSRunnerIntegrationTestMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.github.casperjs.casperjsrunner; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Runs JavaScript and/or CoffeScript test files on CasperJS instance, but in "integration-test" mode. IE does not fails the build if there are test | ||
* errors, letting the verify Mojo doing it. | ||
* | ||
* @author Vilmos Nagy (vilmos dot nagy at outlook dot com) | ||
*/ | ||
@Mojo(name = "integration-test", defaultPhase = LifecyclePhase.INTEGRATION_TEST) | ||
public class CasperJSRunnerIntegrationTestMojo extends AbstractCasperJSRunnerMojo { | ||
|
||
/** | ||
* A file in which the count of failed tests will be written. We'll check this file in the verify phase to fail the build, if the testFailures | ||
* ignored during the test mojo. | ||
*/ | ||
@Parameter(property = "casperjs.testFailure.countFile", defaultValue = "${project.build.directory}/casperjsFailureCount") | ||
private File testFailureCountFile; | ||
|
||
@Override | ||
protected void afterTestExecution(final Result globalResult) throws MojoFailureException, MojoExecutionException { | ||
writeFailedTestCount(globalResult); | ||
} | ||
|
||
private void writeFailedTestCount(final Result globalResult) throws MojoExecutionException { | ||
try { | ||
tryToWriteFailedTestCount(globalResult); | ||
} catch (final IOException e) { | ||
throw new MojoExecutionException("Could not write the failed tests' count to disk.", e); | ||
} | ||
} | ||
|
||
private void tryToWriteFailedTestCount(final Result globalResult) throws IOException { | ||
createParentDirectoryIfNecessary(testFailureCountFile); | ||
writeFailedTestCountToExistingDir(globalResult); | ||
} | ||
|
||
private void writeFailedTestCountToExistingDir(final Result globalResult) throws IOException { | ||
BufferedWriter bufferedWriter = null; | ||
try { | ||
bufferedWriter = new BufferedWriter(new FileWriter(testFailureCountFile, false)); | ||
bufferedWriter.write(globalResult.getFailures() + "\n"); | ||
} finally { | ||
if (bufferedWriter != null) { | ||
try { | ||
bufferedWriter.close(); | ||
} catch (final Exception ignored) { | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void createParentDirectoryIfNecessary(final File destinationFile) throws IOException { | ||
final File parentDir = destinationFile.getParentFile(); | ||
if (!parentDir.exists()) { | ||
final boolean success = parentDir.mkdirs(); | ||
if (!success) { | ||
throw new IOException("Cannot create directory for output file: " + destinationFile.toString()); | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/github/casperjs/casperjsrunner/CasperJSRunnerTestMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.casperjs.casperjsrunner; | ||
|
||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
/** | ||
* Runs JavaScript and/or CoffeScript test files on CasperJS instance | ||
* | ||
* @author Benoit Guerin | ||
* @author Vilmos Nagy (vilmos dot nagy at outlook dot com) | ||
*/ | ||
@Mojo(name = "test", defaultPhase = LifecyclePhase.TEST, threadSafe = true) | ||
public class CasperJSRunnerTestMojo extends AbstractCasperJSRunnerMojo { | ||
|
||
/** | ||
* Do we ignore the tests failures. If yes, the plugin will not fail at the end if there was tests failures. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
@Parameter(property = "casperjs.ignoreTestFailures", defaultValue = "${maven.test.failure.ignore}") | ||
private boolean ignoreTestFailures = false; | ||
|
||
@Override | ||
protected void afterTestExecution(final Result globalResult) throws MojoFailureException { | ||
if (!ignoreTestFailures && globalResult.getFailures() > 0) { | ||
throw new MojoFailureException("There are " + globalResult.getFailures() + " tests failures"); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/github/casperjs/casperjsrunner/CasperJSVerifyMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.github.casperjs.casperjsrunner; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Verifies that there was no test failure during the integration-test Mojo. | ||
* | ||
* @author Vilmos Nagy (vilmos dot nagy at outlook dot com) | ||
*/ | ||
@Mojo(name = "verify", defaultPhase = LifecyclePhase.VERIFY) | ||
public class CasperJSVerifyMojo extends AbstractMojo { | ||
|
||
/** | ||
* A file in which the count of failed tests will be written. We'll check this file in the verify phase to fail the build, if the testFailures | ||
* ignored during the test mojo. | ||
*/ | ||
@Parameter(property = "casperjs.testFailure.countFile", defaultValue = "${project.build.directory}/casperjsFailureCount") | ||
private File testFailureCountFile; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
if (!testFailureCountFile.exists()) { | ||
throw new MojoFailureException( | ||
"The testFailureCountFile " + testFailureCountFile.getAbsolutePath() + " doesn't exists. Run tests before the verify phase!"); | ||
} | ||
|
||
final String firstLine = readFirstLineOfFile(); | ||
final Integer failedTestCount = Integer.valueOf(firstLine); | ||
if (failedTestCount > 0) { | ||
throw new MojoFailureException("Integration test verification error: There are " + failedTestCount + " tests failures"); | ||
} | ||
} | ||
|
||
private String readFirstLineOfFile() throws MojoExecutionException { | ||
try { | ||
return tryToReadFirstLineOfFile(); | ||
} catch (final IOException e) { | ||
throw new MojoExecutionException("", e); | ||
} | ||
} | ||
|
||
private String tryToReadFirstLineOfFile() throws IOException { | ||
BufferedReader bufferedReader = null; | ||
try { | ||
bufferedReader = new BufferedReader(new FileReader(testFailureCountFile)); | ||
return bufferedReader.readLine(); | ||
} finally { | ||
if (bufferedReader != null) { | ||
try { | ||
bufferedReader.close(); | ||
} catch (final Exception ignored) { | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |