forked from jfrog/ide-plugins-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
927c2b5
commit f974dce
Showing
2 changed files
with
85 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
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 |
---|---|---|
|
@@ -16,6 +16,9 @@ | |
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
|
@@ -46,17 +49,8 @@ enum Project { | |
|
||
@BeforeMethod | ||
public void setUp(Object[] testArgs) { | ||
try { | ||
tempProject = Files.createTempDirectory("ide-plugins-common-yarn").toFile(); | ||
tempProject.deleteOnExit(); | ||
FileUtils.copyDirectory(((Project) testArgs[0]).path.toFile(), tempProject); | ||
Path projectDir = tempProject.toPath(); | ||
descriptorFilePath = projectDir.resolve("package.json").toString(); | ||
YarnTreeBuilder yarnTreeBuilder = new YarnTreeBuilder(projectDir, descriptorFilePath, null); | ||
depTree = yarnTreeBuilder.buildTree(new NullLog()); | ||
assertNotNull(depTree); | ||
} catch (IOException e) { | ||
fail(e.getMessage(), e); | ||
if (!yarnDriver.isYarnInstalled()) { | ||
throw new SkipException("Skip test, yarn is not installed."); | ||
} | ||
} | ||
|
||
|
@@ -74,10 +68,15 @@ private Object[][] yarnTreeBuilderProvider() { | |
} | ||
|
||
@Test(dataProvider = "yarnTreeBuilderProvider") | ||
public void yarnTreeBuilderTest(Project project, int expectedChildren) { | ||
if (!yarnDriver.isYarnInstalled()) { | ||
throw new SkipException("Skip test, yarn is not installed."); | ||
} | ||
public void yarnTreeBuilderTest(Project project, int expectedChildren) throws IOException { | ||
tempProject = Files.createTempDirectory("ide-plugins-common-yarn").toFile(); | ||
tempProject.deleteOnExit(); | ||
FileUtils.copyDirectory((project).path.toFile(), tempProject); | ||
Path projectDir = tempProject.toPath(); | ||
descriptorFilePath = projectDir.resolve("package.json").toString(); | ||
YarnTreeBuilder yarnTreeBuilder = new YarnTreeBuilder(projectDir, descriptorFilePath, null); | ||
depTree = yarnTreeBuilder.buildTree(new NullLog()); | ||
assertNotNull(depTree); | ||
String expectedProjectName = project.name; | ||
checkDependencyTree(expectedProjectName, expectedChildren); | ||
} | ||
|
@@ -117,4 +116,73 @@ private void fourChildrenScenario() { | |
} | ||
assertEquals(count, 4); | ||
} | ||
|
||
@Test | ||
public void extractSinglePathTest() { | ||
String projectRootId = "root"; | ||
String packageFullName = "pkg:1.0.0"; | ||
String rawDependency = "{\"type\":\"info\",\"data\":\"This module exists because \\\"pkg#subpkg#dep\\\" depends on it.\"}"; | ||
|
||
YarnTreeBuilder yarnTreeBuilder = new YarnTreeBuilder(Paths.get(""), "", null); | ||
List<String> pathResult = yarnTreeBuilder.extractSinglePath(projectRootId, packageFullName, rawDependency); | ||
|
||
assertNotNull(pathResult); | ||
assertEquals(pathResult.size(), 2); | ||
assertEquals(pathResult.get(0), projectRootId); | ||
assertEquals(pathResult.get(1), packageFullName); | ||
} | ||
|
||
@Test | ||
public void extractMultiplePathsTest() { | ||
String projectRootId = "root"; | ||
String packageFullName = "pkg:1.0.0"; | ||
List<String> rawDependencyPaths = List.of( | ||
"{\"type\":\"reasons\",\"items\":[\"Specified in \\\"dependencies\\\"\",\"Hoisted from \\\"pkg#dep1\\\"\",\"Hoisted from \\\"pkg#dep2\\\"\"]}", | ||
"{\"type\":\"reasons\",\"items\":[\"Specified in \\\"devDependencies\\\"\",\"Hoisted from \\\"pkg#dep3\\\"\"]}" | ||
); | ||
|
||
YarnTreeBuilder yarnTreeBuilder = new YarnTreeBuilder(Paths.get(""), "", null); | ||
List<List<String>> paths = yarnTreeBuilder.extractMultiplePaths(projectRootId, packageFullName, rawDependencyPaths); | ||
|
||
assertNotNull(paths); | ||
assertEquals(paths.size(), 2); | ||
assertEquals(paths.get(0).size(), 4); | ||
assertEquals(paths.get(0).get(0), projectRootId); | ||
assertEquals(paths.get(0).get(1), packageFullName); | ||
assertEquals(paths.get(0).get(2), "pkg#dep1"); | ||
assertEquals(paths.get(0).get(3), "pkg#dep2"); | ||
|
||
assertEquals(paths.get(1).size(), 3); | ||
assertEquals(paths.get(1).get(0), projectRootId); | ||
assertEquals(paths.get(1).get(1), packageFullName); | ||
assertEquals(paths.get(1).get(2), "pkg#dep3"); | ||
} | ||
|
||
@Test | ||
public void findDependencyImpactPathsTest() throws IOException { | ||
String projectRootId = "root"; | ||
String packageName = "pkg"; | ||
Set<String> packageVersions = Set.of("1.0.0", "2.0.0"); | ||
List<String> yarnWhyOutput = List.of( | ||
"{\"type\":\"info\",\"data\":\"Found \\\"[email protected]\\\"\"}", | ||
"{\"type\":\"list\",\"data\":{\"type\":\"reasons\",\"items\":[\"Specified in \\\"dependencies\\\"\",\"Hoisted from \\\"pkg#dep1\\\"\",\"Hoisted from \\\"pkg#dep2\\\"\"]}}" | ||
); | ||
|
||
YarnTreeBuilder yarnTreeBuilder = new YarnTreeBuilder(Paths.get(""), "", null); | ||
Map<String, List<List<String>>> paths = yarnTreeBuilder.findDependencyImpactPaths(new NullLog(), projectRootId, packageName, packageVersions); | ||
|
||
assertNotNull(paths); | ||
assertEquals(paths.size(), 1); | ||
|
||
List<List<String>> pkgPaths = paths.get("pkg:1.0.0"); | ||
assertNotNull(pkgPaths); | ||
assertEquals(pkgPaths.size(), 1); | ||
|
||
List<String> singlePath = pkgPaths.get(0); | ||
assertEquals(singlePath.size(), 4); | ||
assertEquals(singlePath.get(0), projectRootId); | ||
assertEquals(singlePath.get(1), "pkg:1.0.0"); | ||
assertEquals(singlePath.get(2), "pkg#dep1"); | ||
assertEquals(singlePath.get(3), "pkg#dep2"); | ||
} | ||
} |