Skip to content

Commit f646b4d

Browse files
committed
first unittest npm
1 parent a59bb6a commit f646b4d

File tree

54 files changed

+200
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+200
-25
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.devonfw.tools.ide.commandlet.FileExtractor;
22

33
enum ExtractorFileType {
4-
ZIP, JAR, DMG, MSI, PKG
4+
ZIP, JAR, DMG, MSI, PKG, TAR, GZ, TGZ
55
}

cli/src/main/java/com/devonfw/tools/ide/tool/npm/Npm.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,21 @@ public void postInstall() {
4040

4141
FileAccess fileAccess = context.getFileAccess();
4242
Path nodeHomePath = this.context.getSoftwarePath().resolve("node/");
43-
Path npmBinBath = nodeHomePath.resolve("node_modules/npm/bin/");
44-
String npm = "npm";
45-
String npx = "npx";
46-
String cmd = ".cmd";
47-
48-
fileAccess.delete(nodeHomePath.resolve(npm));
49-
fileAccess.delete(nodeHomePath.resolve(npm + cmd));
50-
fileAccess.delete(nodeHomePath.resolve(npx));
51-
fileAccess.delete(nodeHomePath.resolve(npx + cmd));
52-
53-
fileAccess.copy(npmBinBath.resolve(npm), nodeHomePath.resolve(npm));
54-
fileAccess.copy(npmBinBath.resolve(npm + cmd), nodeHomePath.resolve(npm + cmd));
55-
fileAccess.copy(npmBinBath.resolve(npx), nodeHomePath.resolve(npx));
56-
fileAccess.copy(npmBinBath.resolve(npx + cmd), nodeHomePath.resolve(npx + cmd));
43+
if(context.getSystemInfo().isWindows()) {
44+
Path npmBinBath = nodeHomePath.resolve("node_modules/npm/bin/");
45+
String npm = "npm";
46+
String npx = "npx";
47+
String cmd = ".cmd";
48+
49+
fileAccess.delete(nodeHomePath.resolve(npm));
50+
fileAccess.delete(nodeHomePath.resolve(npm + cmd));
51+
fileAccess.delete(nodeHomePath.resolve(npx));
52+
fileAccess.delete(nodeHomePath.resolve(npx + cmd));
53+
54+
fileAccess.copy(npmBinBath.resolve(npm), nodeHomePath.resolve(npm));
55+
fileAccess.copy(npmBinBath.resolve(npm + cmd), nodeHomePath.resolve(npm + cmd));
56+
fileAccess.copy(npmBinBath.resolve(npx), nodeHomePath.resolve(npx));
57+
fileAccess.copy(npmBinBath.resolve(npx + cmd), nodeHomePath.resolve(npx + cmd));
58+
}
5759
}
5860
}

cli/src/test/java/com/devonfw/tools/ide/commandlet/InstallCommandletTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.devonfw.tools.ide.commandlet;
22

3-
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4-
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5-
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
3+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
64

75
import java.io.IOException;
86
import java.nio.file.Files;
@@ -28,14 +26,14 @@ public class InstallCommandletTest extends AbstractIdeContextTest {
2826
private static Path resourcePath = Path.of("src/test/resources");
2927

3028
@BeforeAll
31-
static void setUp() throws IOException {
29+
static void setUp() {
3230

3331
server = new WireMockServer(WireMockConfiguration.wireMockConfig().port(1111));
3432
server.start();
3533
}
3634

3735
@AfterAll
38-
static void tearDown() throws IOException {
36+
static void tearDown() {
3937

4038
server.shutdownServer();
4139
}

cli/src/test/java/com/devonfw/tools/ide/tool/jmc/JmcTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.devonfw.tools.ide.tool.jmc;
22

3-
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4-
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5-
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
3+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
64

75
import java.io.IOException;
86
import java.nio.file.Files;
@@ -34,7 +32,7 @@ public class JmcTest extends AbstractIdeContextTest {
3432
private static final Path RESOURCE_PATH = Path.of("src/test/resources");
3533

3634
@BeforeAll
37-
static void setUp() throws IOException {
35+
static void setUp() {
3836

3937
// TODO use random port number and create url file dynamically in project
4038
// TODO ISSUE:https://github.com/devonfw/IDEasy/issues/223
@@ -44,7 +42,7 @@ static void setUp() throws IOException {
4442
}
4543

4644
@AfterAll
47-
static void tearDown() throws IOException {
45+
static void tearDown() {
4846

4947
server.shutdownServer();
5048
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,64 @@
11
package com.devonfw.tools.ide.tool.npm;
22

3+
import java.io.IOException;
4+
import java.nio.file.Path;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.devonfw.tools.ide.commandlet.CommandLetExtractorMock;
39
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
10+
import com.devonfw.tools.ide.context.IdeContext;
11+
import com.devonfw.tools.ide.context.IdeTestContext;
12+
import com.devonfw.tools.ide.log.IdeLogLevel;
13+
import com.devonfw.tools.ide.repo.ToolRepositoryMock;
414

515
public class NpmTest extends AbstractIdeContextTest {
616

17+
@Test
18+
public void npmPostInstallShouldMoveFiles() throws IOException {
19+
// arrange
20+
String path = "workspaces/foo-test/my-git-repo";
21+
String projectTestCaseName = "npm";
22+
23+
ToolRepositoryMock toolRepositoryMock = buildToolRepositoryMockForNpm(projectTestCaseName);
24+
25+
IdeContext context = newContext(projectTestCaseName, path, true, toolRepositoryMock);
26+
toolRepositoryMock.setContext(context);
27+
28+
CommandLetExtractorMock commandLetExtractorMock = new CommandLetExtractorMock(context);
29+
Npm commandlet = new Npm(context);
30+
commandlet.setCommandletFileExtractor(commandLetExtractorMock);
31+
32+
assertThat(context.getSoftwarePath().resolve("node/npm")).hasContent("# This is npm");
33+
assertThat(context.getSoftwarePath().resolve("node/npx")).hasContent("# This is npx");
34+
35+
// act
36+
commandlet.install();
37+
38+
// assert
39+
String expectedMessage = "Successfully installed npm in version 9.9.2";
40+
assertLogMessage((IdeTestContext) context, IdeLogLevel.SUCCESS, expectedMessage, false);
41+
if (context.getSystemInfo().isWindows()) {
42+
Path test = context.getSoftwarePath();
43+
assertThat(context.getSoftwarePath().resolve("node/npm")).exists();
44+
assertThat(context.getSoftwarePath().resolve("node/npm.cmd")).exists();
45+
assertThat(context.getSoftwarePath().resolve("node/npx")).exists();
46+
assertThat(context.getSoftwarePath().resolve("node/npx.cmd")).exists();
47+
48+
assertThat(context.getSoftwarePath().resolve("node/npm")).hasContent("# This is npm bin");
49+
assertThat(context.getSoftwarePath().resolve("node/npx")).hasContent("# This is npx bin");
50+
}
51+
}
52+
53+
private static ToolRepositoryMock buildToolRepositoryMockForNpm(String projectTestCaseName) {
54+
55+
String windowsFileFolder = "npm-9.9.2";
56+
57+
ToolRepositoryMock toolRepositoryMock = new ToolRepositoryMock("npm", "9.9.2", projectTestCaseName,
58+
windowsFileFolder, "", "");
59+
60+
toolRepositoryMock.addAlreadyInstalledTool("node", "v18.19.1");
61+
62+
return toolRepositoryMock;
63+
}
764
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.19.1

cli/src/test/resources/ide-projects/npm/_ide/software/default/node/node/v18.19.1/node_modules/npm/bin/npm

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/_ide/software/default/node/node/v18.19.1/node_modules/npm/bin/npm.cmd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/_ide/software/default/node/node/v18.19.1/node_modules/npm/bin/npx

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/_ide/software/default/node/node/v18.19.1/node_modules/npm/bin/npx.cmd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is npm
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo Dummy npm 9.9.2 on windows> npmTestResult.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is npx
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo Dummy npx on windows> npxTestResult.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the tool repository
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dummy text file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# node-gyp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo Dummy node-gyp> nodeGypTestResult.txt

cli/src/test/resources/ide-projects/npm/downloadMockLocation/npm-9.9.2/package/node_modules/color-name/LICENSE

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#********************************************************************************
2+
# This file contains project specific environment variables defined by the user
3+
#********************************************************************************
4+
5+
M2_REPO=~/.m2/repository
6+
7+
SOME=some-${UNDEFINED}
8+
9+
TEST_ARGS1=${TEST_ARGS1} conf1
10+
TEST_ARGS2=${TEST_ARGS2} conf2
11+
TEST_ARGS5=${TEST_ARGS5} conf5
12+
TEST_ARGS6=${TEST_ARGS6} conf6
13+
TEST_ARGS7=${TEST_ARGS7} conf7
14+
TEST_ARGS8=${TEST_ARGS8} conf8
15+
TEST_ARGSa=${TEST_ARGS1} ${TEST_ARGS3} confa
16+
TEST_ARGSc=${TEST_ARGSc} confc
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#********************************************************************************
2+
# This file contains the global configuration from the user HOME directory.
3+
#********************************************************************************
4+
5+
DOCKER_EDITION=docker
6+
FOO=foo-${BAR}
7+
8+
TEST_ARGS1=${TEST_ARGS1} user1
9+
TEST_ARGS2=${TEST_ARGS2} user2
10+
TEST_ARGS3=${TEST_ARGS3} user3
11+
TEST_ARGS7=user7
12+
TEST_ARGS10=user10
13+
TEST_ARGSb=userb
14+
TEST_ARGSc=${TEST_ARGS1} userc
15+
TEST_ARGSd=${TEST_ARGS1} userd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugin_url=https://raw.githubusercontent.com/iloveeclipse/plugins/latest/
2+
plugin_id=AnyEditTools.feature.group
3+
plugin_active=false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the download cache
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the users HOME directory
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the IDE_HOME directory
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
the IDE CLI bash script
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugin_url=https://raw.githubusercontent.com/iloveeclipse/plugins/latest/
2+
plugin_id=AnyEditTools.feature.group
3+
plugin_active=true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugin_url=https://checkstyle.org/eclipse-cs-update-site
2+
plugin_id=net.sf.eclipsecs.feature.group
3+
plugin_active=true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#********************************************************************************
2+
# This file contains project specific environment variables
3+
#********************************************************************************
4+
5+
JAVA_VERSION=17*
6+
MVN_VERSION=3.9.*
7+
ECLIPSE_VERSION=2023-03
8+
INTELLIJ_EDITION=ultimate
9+
10+
IDE_TOOLS=mvn,eclipse
11+
12+
BAR=bar-${SOME}
13+
14+
TEST_ARGS1=${TEST_ARGS1} settings1
15+
TEST_ARGS4=${TEST_ARGS4} settings4
16+
TEST_ARGS5=${TEST_ARGS5} settings5
17+
TEST_ARGS6=${TEST_ARGS6} settings6
18+
TEST_ARGS7=${TEST_ARGS7} settings7
19+
TEST_ARGS8=settings8
20+
TEST_ARGS9=settings9
21+
TEST_ARGSb=${TEST_ARGS10} settingsb ${TEST_ARGSa} ${TEST_ARGSb}
22+
TEST_ARGSc=${TEST_ARGSc} settingsc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
just a marker for detection of IDE_HOME
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.19.1

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/LICENSE.md

Lines changed: 1 addition & 0 deletions

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/README.md

Lines changed: 1 addition & 0 deletions

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/dist/dummy.txt

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/dist/lib/dummy.txt

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/shims/nodewin/npm

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/shims/nodewin/npm.cmd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/shims/npm

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/corepack/shims/npm.cmd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/npm/bin/npm

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/npm/bin/npm.cmd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/npm/bin/npx

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/npm/bin/npx.cmd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/test/resources/ide-projects/npm/project/software/node/node_modules/readme

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is npm
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo Dummy npm 9.9.2 on windows> npmTestResult.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is npx
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo Dummy npx on windows> npxTestResult.txt
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#********************************************************************************
2+
# Type of {@link EnvironmentVariables} from the
3+
# {@link com.devonfw.tools.ide.context.IdeContext#getWorkspacePath() workspace directory}.
4+
#********************************************************************************
5+
TEST_ARGS1=${TEST_ARGS1} workspace1
6+
TEST_ARGS3=${TEST_ARGS3} workspace3
7+
TEST_ARGS6=${TEST_ARGS6} workspace6
8+
TEST_ARGS7=${TEST_ARGS7} workspace7
9+
TEST_ARGS8=${TEST_ARGS8} workspace8
10+
TEST_ARGS9=${TEST_ARGS9} workspace9
11+
TEST_ARGS10=${TEST_ARGS10} workspace10
12+
TEST_ARGSd=${TEST_ARGSd} workspaced
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
my-git-repo in foo-test workspace of jmc test case
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the foo-test workspace of jmc test case
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the main workspace of jmc test case
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the IDE_ROOT directory

0 commit comments

Comments
 (0)