forked from Voxelum/minecraft-launcher-core-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.e2e.test.ts
More file actions
145 lines (137 loc) · 5.94 KB
/
launch.e2e.test.ts
File metadata and controls
145 lines (137 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { ChildProcess, spawnSync } from "child_process";
import { EOL } from "os";
import * as path from "path";
import { launch, LaunchOption, launchServer } from "./launch";
declare const tempDir: string;
declare const inCI: boolean;
function getJavaVersion(javaPath: string) {
const { stderr } = spawnSync(javaPath, ["-version"], { encoding: "utf8" });
const line = stderr.split(EOL)[0];
if (stderr.startsWith("java version")) {
const parts = line.split(" ")[2].replace(/"/g, "").split(".");
if (parts[0] === "1") {
return Number.parseInt(parts[1].replace(/[^0-9]/g, ""), 10);
} else {
return (Number.parseInt(parts[0].replace(/[^0-9]/g, ""), 10));
}
} else {
return (Number.parseInt(line.split(" ")[1].split(".")[0], 10));
}
}
function waitGameProcess(process: ChildProcess, ...hints: string[]) {
const found = new Array<boolean>(hints.length);
found.fill(false);
return new Promise<void>((resolve, reject) => {
process.stdout!.on("data", (chunk) => {
const content = chunk.toString();
for (let i = 0; i < hints.length; i++) {
if (content.indexOf(hints[i]) !== -1) {
found[i] = true;
}
}
if (found.every((f) => f)) {
process.kill("SIGINT");
}
});
process.stderr!.on("data", (chunk) => {
console.warn(chunk.toString());
});
process.on("exit", (code, signal) => {
if (signal === "SIGINT" || code === 130) {
resolve();
} else {
reject({ code, signal });
}
});
});
}
describe("Launcher", () => {
let javaPath: string;
let javaVersion: number;
jest.setTimeout(10000000);
if (process.env.JAVA_HOME) {
javaPath = `${process.env.JAVA_HOME}/bin/java`;
javaVersion = getJavaVersion(javaPath);
} else {
javaPath = "java";
try {
javaVersion = getJavaVersion(javaPath);
} catch {
javaPath = "";
}
}
describe.skip("#launch", () => {
describe("1.6.4", () => {
let t = test;
if ((javaVersion && javaVersion > 8) || !javaPath) { t = test.skip; }
test("should launch 1.6.4", async () => {
const option: LaunchOption = { version: "1.6.4", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "OpenAL initialized.");
});
});
describe("1.17.10", () => {
let t = test;
if ((javaVersion && javaVersion > 8) || !javaPath) { t = test.skip; }
test("should launch with forge", async () => {
const option: LaunchOption = { version: "1.7.10-Forge10.13.3.1400-1.7.10", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "OpenAL initialized.");
});
});
describe("1.12.2", () => {
let t = test;
if ((javaVersion && javaVersion > 8) || !javaPath) { t = test.skip; }
test("should launch normal minecraft", async () => {
const option: LaunchOption = { version: "1.12.2", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "[Client thread/INFO]: Created: 1024x512 textures-atlas");
});
t("should launch server", async () => {
const option: LaunchOption = {
version: "1.12.2", gamePath: tempDir, javaPath, server: {
ip: "127.0.0.1",
port: 25565,
},
};
await waitGameProcess(await launch(option), "[Client thread/INFO]: Connecting to 127.0.0.1, 25565");
});
t("should launch forge minecraft", async () => {
const option: LaunchOption = { version: "1.12.2-forge1.12.2-14.23.5.2823", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "[main/INFO] [FML]:");
});
t("should launch liteloader minecraft", async () => {
const option: LaunchOption = { version: "1.12.2-Liteloader1.12.2-1.12.2-SNAPSHOT", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "LiteLoader begin POSTINIT");
});
t("should launch forge liteloader minecraft", async () => {
const option: LaunchOption = { version: "1.12.2-forge1.12.2-14.23.5.2823-Liteloader1.12.2-1.12.2-SNAPSHOT", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "LiteLoader begin POSTINIT", "[main/INFO] [FML]:");
});
});
describe("1.14.4", () => {
let t = test;
if (!javaPath) { t = test.skip; }
t("should launch normal minecraft", async () => {
const option: LaunchOption = { version: "1.14.4", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "[Client thread/INFO]: OpenAL initialized");
});
});
describe("1.15.2", () => {
let t = test;
if (!javaPath) { t = test.skip; }
t("should launch normal minecraft", async () => {
const option: LaunchOption = { version: "1.15.2", gamePath: tempDir, javaPath };
await waitGameProcess(await launch(option), "OpenAL initialized.");
});
});
});
describe.skip("#launchServer", () => {
test("should launch 1.12.2", async () => {
const process = await launchServer({
version: "1.12.2",
path: tempDir,
javaPath,
cwd: path.resolve(".")
})
await waitGameProcess(process, "You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
});
});
});