Skip to content

Commit a0f00e6

Browse files
committed
integrationTestFailureAfterPostIntegration flag delegates integration test failures to fail maven build during verify phase; requires a verify execution phase
1 parent 80f3d49 commit a0f00e6

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Last public release: [![Maven Central](https://maven-badges.herokuapp.com/maven-
44

55
## Changelog
66

7+
### 1.9.2
8+
9+
* 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.
10+
711
### 1.9.0
812

913
* Copy npm scripts, so they are available for execution ([#868](https://github.com/eirslett/frontend-maven-plugin/pull/868))

frontend-maven-plugin/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>frontend-plugins</artifactId>
66
<groupId>com.github.eirslett</groupId>
7-
<version>1.9.1</version>
7+
<version>1.9.2-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>frontend-maven-plugin</artifactId>

frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.eirslett.maven.plugins.frontend.mojo;
22

33
import java.io.File;
4+
import java.util.HashMap;
45
import java.util.Map;
56

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

1819
public abstract class AbstractFrontendMojo extends AbstractMojo {
1920

21+
public static final String INTEGRATION_TEST_FAILED_KEY = "integrationTestFailed";
2022
@Component
2123
protected MojoExecution execution;
2224

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

40+
/**
41+
* Set this to true to delegate test failures until after 'post-integration' has executed.
42+
*
43+
* @since 1.9.2
44+
*/
45+
@Parameter(property = "maven.it.failure.after.postIntegration", defaultValue = "false")
46+
protected boolean integrationTestFailureAfterPostIntegration;
47+
3848
/**
3949
* The base directory for running all Node commands. (Usually the directory that contains package.json)
4050
*/
@@ -71,7 +81,17 @@ private boolean skipTestPhase() {
7181
*/
7282
private boolean isTestingPhase() {
7383
String phase = execution.getLifecyclePhase();
74-
return "test".equals(phase) || "integration-test".equals(phase);
84+
return "test".equals(phase) || isIntegrationTestingPhase();
85+
}
86+
87+
private boolean isIntegrationTestingPhase(){
88+
String phase = execution.getLifecyclePhase();
89+
return "integration-test".equals(phase);
90+
}
91+
92+
private boolean isVerifyPhase(){
93+
String phase = execution.getLifecyclePhase();
94+
return "verify".equals(phase);
7595
}
7696

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

84104
@Override
85105
public void execute() throws MojoFailureException {
106+
if(isVerifyPhase() && integrationTestsHaveFailed()){
107+
throw new MojoFailureException("Some integration tests have failed during integration-test phase.");
108+
}
86109
if (testFailureIgnore && !isTestingPhase()) {
87110
getLog().info("testFailureIgnore property is ignored in non test phases");
88111
}
@@ -96,6 +119,9 @@ public void execute() throws MojoFailureException {
96119
} catch (TaskRunnerException e) {
97120
if (testFailureIgnore && isTestingPhase()) {
98121
getLog().error("There are test failures.\nFailed to run task: " + e.getMessage(), e);
122+
} else if (integrationTestFailureAfterPostIntegration && isIntegrationTestingPhase()) {
123+
storeIntegrationTestFailed();
124+
getLog().error("There are test failures.\nFailed to run task: " + e.getMessage(), e);
99125
} else {
100126
throw new MojoFailureException("Failed to run task", e);
101127
}
@@ -107,4 +133,20 @@ public void execute() throws MojoFailureException {
107133
}
108134
}
109135

136+
private Boolean integrationTestsHaveFailed() {
137+
Object failed = getPluginContext().get(INTEGRATION_TEST_FAILED_KEY);
138+
return failed != null && (Boolean) failed;
139+
}
140+
141+
private void storeIntegrationTestFailed() {
142+
Map<String, Object> pluginContext;
143+
if(getPluginContext() != null){
144+
pluginContext = getPluginContext();
145+
} else {
146+
pluginContext = new HashMap<>();
147+
}
148+
pluginContext.put(INTEGRATION_TEST_FAILED_KEY, true);
149+
setPluginContext(pluginContext);
150+
}
151+
110152
}

frontend-plugin-core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<artifactId>frontend-plugins</artifactId>
55
<groupId>com.github.eirslett</groupId>
6-
<version>1.9.1</version>
6+
<version>1.9.2-SNAPSHOT</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.github.eirslett</groupId>
55
<artifactId>frontend-plugins</artifactId>
6-
<version>1.9.1</version>
6+
<version>1.9.2-SNAPSHOT</version>
77
<packaging>pom</packaging>
88

99
<properties>

0 commit comments

Comments
 (0)