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

fix!: fix tasks skipping conditions and dependencies #207

Merged
merged 1 commit into from
Aug 23, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,27 @@ void setUp() throws IOException {
}

@Test
void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"))
.assembleScript("run assemble")
.packageJsonDirectory(packageJsonDirectoryPath);
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);
}

@Test
void should_skip_task_when_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), packageJsonDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand All @@ -56,7 +76,7 @@ void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
}

@Test
void should_skip_plugin_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
void should_skip_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), packageJsonDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@
* distributions, to avoid the download overhead. The 'yarn' and 'npm' executables in these distributions simply call
* the 'node' executable with the same arguments.
*/
class CheckTaskFuncTest {
class CheckFrontendTaskFuncTest {

@TempDir
Path projectDirectoryPath;

@Test
void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"))
.checkScript("run check");
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CHECK_TASK_NAME);

assertCheckTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CHECK_TASK_NAME);

assertCheckTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);
}

@Test
void should_skip_task_when_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand All @@ -47,7 +66,7 @@ void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
}

@Test
void should_skip_plugin_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
void should_skip_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@
* distributions, to avoid the download overhead. The 'yarn' and 'npm' executables in these distributions simply call
* the 'node' executable with the same arguments.
*/
class CleanTaskFuncTest {
class CleanFrontendTaskFuncTest {

@TempDir
Path projectDirectoryPath;

@Test
void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"))
.cleanScript("run clean");
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CLEAN_TASK_NAME);

assertCleanTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CLEAN_TASK_NAME);

assertCleanTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);
}

@Test
void should_skip_task_when_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand All @@ -47,7 +66,7 @@ void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
}

@Test
void should_skip_plugin_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
void should_skip_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ class InstallFrontendTaskFuncTest {
@TempDir
Path projectDirectoryPath;

@Test
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"));
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.INSTALL_FRONTEND_TASK_NAME);

assertTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.INSTALL_FRONTEND_TASK_NAME);

assertTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED);
}

@Test
void should_succeed_with_default_script() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.siouan.frontendgradleplugin.test.GradleBuildAssertions.assertTaskOutcomes;
import static org.siouan.frontendgradleplugin.test.GradleBuildFiles.createBuildFile;
import static org.siouan.frontendgradleplugin.test.GradleHelper.runGradle;
import static org.siouan.frontendgradleplugin.test.GradleHelper.runGradleAndExpectFailure;
import static org.siouan.frontendgradleplugin.test.Resources.getResourcePath;
import static org.siouan.frontendgradleplugin.test.Resources.getResourceUrl;

Expand All @@ -28,6 +29,42 @@ class InstallPackageManagerTaskFuncTest {
@TempDir
Path projectDirectoryPath;

@Test
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"));
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath,
FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME);

assertTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED);

final BuildResult result2 = runGradle(projectDirectoryPath,
FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME);

assertTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED);
}

@Test
void should_fail_when_corepack_executable_is_not_a_file() throws IOException {
// The fact that the corepack executable is not present is enough to simulate the following use cases:
// - The Node.js distribution is already provided, but the install directory was not set accordingly.
// - The Node.js distribution is already provided, but the install directory contains a non-supported release.
// - The Node.js distribution was downloaded but is a non-supported release.
// - The Node.js distribution was downloaded but was corrupted later so as the corepack executable is not
// present anymore.
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
Files.createDirectory(projectDirectoryPath.resolve(FrontendGradlePlugin.DEFAULT_NODE_INSTALL_DIRECTORY_NAME));
createBuildFile(projectDirectoryPath, new FrontendMapBuilder().nodeDistributionProvided(true).toMap());

final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath,
FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME);

assertTaskOutcomes(result, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.FAILED);
}

@Test
void should_install_package_managers() throws IOException {
Files.copy(getResourcePath("package-npm.json"), projectDirectoryPath.resolve("package.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ResolvePackageManagerTaskFuncTest {
Path projectDirectoryPath;

@Test
void should_be_skipped_when_package_json_file_is_not_readable() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
Files.createDirectory(projectDirectoryPath.resolve(FrontendGradlePlugin.PACKAGE_JSON_FILE_NAME));
createBuildFile(projectDirectoryPath, new FrontendMapBuilder().nodeDistributionProvided(true).toMap());

final BuildResult result = runGradle(projectDirectoryPath,
Expand All @@ -50,7 +51,10 @@ void should_be_skipped_when_package_json_file_is_not_readable() throws IOExcepti
@Test
void should_fail_when_package_manager_property_is_not_set_in_package_json_file() throws IOException {
Files.copy(getResourcePath("package-no-manager.json"), projectDirectoryPath.resolve("package.json"));
createBuildFile(projectDirectoryPath, new FrontendMapBuilder().nodeDistributionProvided(true).toMap());
createBuildFile(projectDirectoryPath, new FrontendMapBuilder()
.nodeDistributionProvided(true)
.nodeInstallDirectory(getResourcePath("node-dist-provided"))
.toMap());

final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath,
FrontendGradlePlugin.RESOLVE_PACKAGE_MANAGER_TASK_NAME);
Expand All @@ -67,8 +71,10 @@ void should_fail_when_package_manager_property_is_not_set_in_package_json_file()
@Test
void should_fail_when_package_manager_property_is_invalid_in_package_json_file() throws IOException {
Files.copy(getResourcePath("package-invalid-manager.json"), projectDirectoryPath.resolve("package.json"));
createBuildFile(projectDirectoryPath,
new FrontendMapBuilder().nodeDistributionProvided(true).nodeDistributionProvided(true).toMap());
createBuildFile(projectDirectoryPath, new FrontendMapBuilder()
.nodeDistributionProvided(true)
.nodeInstallDirectory(getResourcePath("node-dist-provided"))
.toMap());

final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath,
FrontendGradlePlugin.RESOLVE_PACKAGE_MANAGER_TASK_NAME);
Expand Down
Loading
Loading