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 c77f6f4
Showing 1 changed file with 32 additions and 0 deletions.
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 c77f6f4

Please sign in to comment.