Skip to content
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

closes #534: Do not fail the Maven build for a failed test #564

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,6 +26,13 @@ public abstract class AbstractFrontendMojo extends AbstractMojo {
@Parameter(property = "skipTests", required = false, defaultValue = "false")
protected Boolean skipTests;

/**
* Set this to "true" to ignore a failure during testing. Its use is NOT RECOMMENDED, but quite convenient on
* occasion.
*/
@Parameter(property = "maven.test.failure.ignore", defaultValue = "false")
protected Boolean testFailureIgnore;

/**
* The base directory for running all Node commands. (Usually the directory that contains package.json)
*/
Expand Down Expand Up @@ -64,6 +71,10 @@ private boolean skipTestPhase() {
return skipTests && isTestingPhase();
}

private boolean ignoreTestFailure() {
return testFailureIgnore && isTestingPhase();
}

/**
* Determines if the current execution is during a testing phase (e.g., "test" or "integration-test").
*/
Expand Down Expand Up @@ -92,9 +103,18 @@ public void execute() throws MojoFailureException {
new RepositoryCacheResolver(repositorySystemSession)
));
} catch (TaskRunnerException e) {
throw new MojoFailureException("Failed to run task", e);
if (!ignoreTestFailure()) {
throw new MojoFailureException("Failed to run task", e);
} else {
getLog().error("Failed to run task", e);
}
} catch (FrontendException e) {
throw MojoUtils.toMojoFailureException(e);
MojoFailureException mojoFailed = MojoUtils.toMojoFailureException(e);
if (!ignoreTestFailure()) {
throw mojoFailed;
} else {
getLog().error(mojoFailed);
}
}
} else {
LoggerFactory.getLogger(AbstractFrontendMojo.class).info("Skipping test phase.");
Expand Down
Expand Up @@ -2,10 +2,10 @@

import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;

import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.slf4j.LoggerFactory;


@Mojo(name="karma", defaultPhase = LifecyclePhase.TEST)
Expand All @@ -17,12 +17,6 @@ public final class KarmaRunMojo extends AbstractFrontendMojo {
@Parameter(defaultValue = "karma.conf.js", property = "karmaConfPath")
private String karmaConfPath;

/**
* Whether you should continue build when some test will fail (default is false)
*/
@Parameter(property = "maven.test.failure.ignore", required = false, defaultValue = "false")
private Boolean testFailureIgnore;

/**
* Skips execution of this mojo.
*/
Expand All @@ -36,17 +30,6 @@ protected boolean skipExecution() {

@Override
public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
try {
factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables);
}
catch (TaskRunnerException e) {
if (testFailureIgnore) {
LoggerFactory.getLogger(KarmaRunMojo.class)
.warn("There are ignored test failures/errors for: " + workingDirectory);
}
else {
throw e;
}
}
factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables);
}
}