Skip to content

Commit

Permalink
tests: Add real tests for detecting Java
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Apr 21, 2024
1 parent f82b387 commit 5f8ce82
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: coursier/setup-action@v1
with:
jvm: temurin:17
- uses: actions/setup-node@v2
with:
node-version: "16"
Expand Down
32 changes: 32 additions & 0 deletions packages/metals-languageclient/src/__tests__/getJavaHome.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import path from "path";
import { OutputChannel } from "../interfaces/OutputChannel";

class MockOutput implements OutputChannel {
append(value: string): void {
console.log(value);
}
appendLine(value: string): void {
console.log(value);
}
}

const exampleJavaVersionString = `openjdk "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
Expand Down Expand Up @@ -26,6 +36,28 @@ describe("getJavaHome", () => {
const javaHome = await require("../getJavaHome").getJavaHome("17");
expect(javaHome).toBe(JAVA_HOME);
});

// needs to run on a machine with an actual JAVA_HOME set up
it("reads from real JAVA_HOME", async () => {
process.env = { ...originalEnv };
delete process.env.PATH;
const javaHome = await require("../getJavaHome").getJavaHome(
"17",
new MockOutput()
);
expect(javaHome).toBeDefined();
});

// needs to run on a machine with an actual java on PATH set up
it("reads from real PATH", async () => {
process.env = { ...originalEnv };
delete process.env.JAVA_HOME;
const javaHome = await require("../getJavaHome").getJavaHome(
"17",
new MockOutput()
);
expect(javaHome).toBeDefined();
});
});

function mockExistsFs(javaLinks: { binPath: String }[]): void {
Expand Down

0 comments on commit 5f8ce82

Please sign in to comment.