Skip to content

integrationTestFailureAfterPostIntegration flag delegates integration… #892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Last public release: [![Maven Central](https://maven-badges.herokuapp.com/maven-

## Changelog

### 1.9.2

* Parameter **integrationTestFailureAfterPostIntegration** logs the failures during *integration-test* phase but only fails the build during the *verify* phase. This allows the *post-integration-test* phase to finish. An execution with *verify* phase is required.

### 1.9.0

* Copy npm scripts, so they are available for execution ([#868](https://github.com/eirslett/frontend-maven-plugin/pull/868))
Expand Down
2 changes: 1 addition & 1 deletion frontend-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>frontend-plugins</artifactId>
<groupId>com.github.eirslett</groupId>
<version>1.9.1</version>
<version>1.9.2-SNAPSHOT</version>
</parent>

<artifactId>frontend-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.eirslett.maven.plugins.frontend.mojo;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -17,6 +18,7 @@

public abstract class AbstractFrontendMojo extends AbstractMojo {

public static final String INTEGRATION_TEST_FAILED_KEY = "integrationTestFailed";
@Component
protected MojoExecution execution;

Expand All @@ -35,6 +37,14 @@ public abstract class AbstractFrontendMojo extends AbstractMojo {
@Parameter(property = "maven.test.failure.ignore", defaultValue = "false")
protected boolean testFailureIgnore;

/**
* Set this to true to delegate test failures until after 'post-integration' has executed.
*
* @since 1.9.2
*/
@Parameter(property = "maven.it.failure.after.postIntegration", defaultValue = "false")
protected boolean integrationTestFailureAfterPostIntegration;

/**
* The base directory for running all Node commands. (Usually the directory that contains package.json)
*/
Expand Down Expand Up @@ -71,7 +81,17 @@ private boolean skipTestPhase() {
*/
private boolean isTestingPhase() {
String phase = execution.getLifecyclePhase();
return "test".equals(phase) || "integration-test".equals(phase);
return "test".equals(phase) || isIntegrationTestingPhase();
}

private boolean isIntegrationTestingPhase(){
String phase = execution.getLifecyclePhase();
return "integration-test".equals(phase);
}

private boolean isVerifyPhase(){
String phase = execution.getLifecyclePhase();
return "verify".equals(phase);
}

protected abstract void execute(FrontendPluginFactory factory) throws FrontendException;
Expand All @@ -83,6 +103,9 @@ private boolean isTestingPhase() {

@Override
public void execute() throws MojoFailureException {
if(isVerifyPhase() && integrationTestsHaveFailed()){
throw new MojoFailureException("Some integration tests have failed during integration-test phase.");
}
if (testFailureIgnore && !isTestingPhase()) {
getLog().info("testFailureIgnore property is ignored in non test phases");
}
Expand All @@ -96,6 +119,9 @@ public void execute() throws MojoFailureException {
} catch (TaskRunnerException e) {
if (testFailureIgnore && isTestingPhase()) {
getLog().error("There are test failures.\nFailed to run task: " + e.getMessage(), e);
} else if (integrationTestFailureAfterPostIntegration && isIntegrationTestingPhase()) {
storeIntegrationTestFailed();
getLog().error("There are test failures.\nFailed to run task: " + e.getMessage(), e);
} else {
throw new MojoFailureException("Failed to run task", e);
}
Expand All @@ -107,4 +133,20 @@ public void execute() throws MojoFailureException {
}
}

private Boolean integrationTestsHaveFailed() {
Object failed = getPluginContext().get(INTEGRATION_TEST_FAILED_KEY);
return failed != null && (Boolean) failed;
}

private void storeIntegrationTestFailed() {
Map<String, Object> pluginContext;
if(getPluginContext() != null){
pluginContext = getPluginContext();
} else {
pluginContext = new HashMap<>();
}
pluginContext.put(INTEGRATION_TEST_FAILED_KEY, true);
setPluginContext(pluginContext);
}

}
2 changes: 1 addition & 1 deletion frontend-plugin-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>frontend-plugins</artifactId>
<groupId>com.github.eirslett</groupId>
<version>1.9.1</version>
<version>1.9.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.github.eirslett</groupId>
<artifactId>frontend-plugins</artifactId>
<version>1.9.1</version>
<version>1.9.2-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down