fix tests

This commit is contained in:
Olivier Gagnon 2021-09-07 14:31:47 -04:00
parent e7d77b7569
commit 82c3362adc
5 changed files with 1099 additions and 1573 deletions

2001
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -77,7 +77,7 @@
"http-server": "^13.0.1", "http-server": "^13.0.1",
"i18n-webpack-plugin": "^1.0.0", "i18n-webpack-plugin": "^1.0.0",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"jest": "^27.0.6", "jest": "^27.1.0",
"js-beautify": "^1.5.10", "js-beautify": "^1.5.10",
"jsdom": "^15.0.0", "jsdom": "^15.0.0",
"jsdom-global": "^3.0.2", "jsdom-global": "^3.0.2",

File diff suppressed because it is too large Load Diff

@ -2,32 +2,32 @@ import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions
describe("StringHelperFunctions Tests", function () { describe("StringHelperFunctions Tests", function () {
it("transforms strings", () => { it("transforms strings", () => {
expect(convertTimeMsToTimeElapsedString(1000)).toEqual("1 seconds"); expect(convertTimeMsToTimeElapsedString(1000)).equal("1 seconds");
expect(convertTimeMsToTimeElapsedString(5 * 60 * 1000 + 34 * 1000)).toEqual( expect(convertTimeMsToTimeElapsedString(5 * 60 * 1000 + 34 * 1000)).equal(
"5 minutes 34 seconds", "5 minutes 34 seconds",
); );
expect( expect(
convertTimeMsToTimeElapsedString( convertTimeMsToTimeElapsedString(
2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000, 2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000,
), ),
).toEqual("2 days 5 minutes 34 seconds"); ).equal("2 days 5 minutes 34 seconds");
expect( expect(
convertTimeMsToTimeElapsedString( convertTimeMsToTimeElapsedString(
2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000, 2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000,
true, true,
), ),
).toEqual("2 days 5 minutes 34.000 seconds"); ).equal("2 days 5 minutes 34.000 seconds");
expect( expect(
convertTimeMsToTimeElapsedString( convertTimeMsToTimeElapsedString(
2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123, 2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123,
true, true,
), ),
).toEqual("2 days 5 minutes 34.123 seconds"); ).equal("2 days 5 minutes 34.123 seconds");
expect( expect(
convertTimeMsToTimeElapsedString( convertTimeMsToTimeElapsedString(
2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123.888, 2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123.888,
true, true,
), ),
).toEqual("2 days 5 minutes 34.123 seconds"); ).equal("2 days 5 minutes 34.123 seconds");
}); });
}); });

@ -51,7 +51,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
"connect ", "connect ",
0, 0,
); );
expect(options).toEqual(["8.8.8.8", "near"]); expect(options).equal(["8.8.8.8", "near"]);
}); });
it("completes the buy command", () => { it("completes the buy command", () => {
@ -60,7 +60,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
"buy ", "buy ",
0, 0,
); );
expect(options).toEqual([ expect(options).equal([
"BruteSSH.exe", "BruteSSH.exe",
"FTPCrack.exe", "FTPCrack.exe",
"relaySMTP.exe", "relaySMTP.exe",
@ -82,14 +82,14 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
"scp ", "scp ",
0, 0,
); );
expect(options1).toEqual(["/www/script.js", "af.lit", "note.txt", "www/"]); expect(options1).equal(["/www/script.js", "af.lit", "note.txt", "www/"]);
const options2 = determineAllPossibilitiesForTabCompletion( const options2 = determineAllPossibilitiesForTabCompletion(
Player, Player,
"scp note.txt ", "scp note.txt ",
1, 1,
); );
expect(options2).toEqual([ expect(options2).equal([
Player.getHomeComputer().ip, Player.getHomeComputer().ip,
"home", "home",
"8.8.8.8", "8.8.8.8",
@ -104,16 +104,16 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
for (const command of ["kill", "tail", "mem", "check"]) { for (const command of ["kill", "tail", "mem", "check"]) {
expect( expect(
determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0), determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0),
).toEqual(["/www/script.js", "www/"]); ).equal(["/www/script.js", "www/"]);
} }
}); });
it("completes the nano commands", () => { it("completes the nano commands", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
expect( expect(determineAllPossibilitiesForTabCompletion(Player, "nano ", 0)).equal(
determineAllPossibilitiesForTabCompletion(Player, "nano ", 0), ["/www/script.js", "note.txt", ".fconf", "www/"],
).toEqual(["/www/script.js", "note.txt", ".fconf", "www/"]); );
}); });
it("completes the rm command", () => { it("completes the rm command", () => {
@ -122,33 +122,37 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
Player.getHomeComputer().messages.push(new Message("asl.msg")); Player.getHomeComputer().messages.push(new Message("asl.msg"));
Player.getHomeComputer().messages.push("af.lit"); Player.getHomeComputer().messages.push("af.lit");
expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).toEqual( expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).equal([
[
"/www/script.js", "/www/script.js",
"NUKE.exe", "NUKE.exe",
"af.lit", "af.lit",
"note.txt", "note.txt",
"linklist.cct", "linklist.cct",
"www/", "www/",
], ]);
);
}); });
it("completes the run command", () => { it("completes the run command", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
expect( expect(determineAllPossibilitiesForTabCompletion(Player, "run ", 0)).equal([
determineAllPossibilitiesForTabCompletion(Player, "run ", 0), "/www/script.js",
).toEqual(["/www/script.js", "NUKE.exe", "linklist.cct", "www/"]); "NUKE.exe",
"linklist.cct",
"www/",
]);
}); });
it("completes the cat command", () => { it("completes the cat command", () => {
Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark"); Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark");
Player.getHomeComputer().messages.push(new Message("asl.msg")); Player.getHomeComputer().messages.push(new Message("asl.msg"));
Player.getHomeComputer().messages.push("af.lit"); Player.getHomeComputer().messages.push("af.lit");
expect( expect(determineAllPossibilitiesForTabCompletion(Player, "cat ", 0)).equal([
determineAllPossibilitiesForTabCompletion(Player, "cat ", 0), "asl.msg",
).toEqual(["asl.msg", "af.lit", "/www/note.txt", "www/"]); "af.lit",
"/www/note.txt",
"www/",
]);
}); });
it("completes the download and mv commands", () => { it("completes the download and mv commands", () => {
@ -157,15 +161,15 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
for (const command of ["download", "mv"]) { for (const command of ["download", "mv"]) {
expect( expect(
determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0), determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0),
).toEqual(["/www/script.js", "note.txt", "www/"]); ).equal(["/www/script.js", "note.txt", "www/"]);
} }
}); });
it("completes the cd command", () => { it("completes the cd command", () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
expect(determineAllPossibilitiesForTabCompletion(Player, "cd ", 0)).toEqual( expect(determineAllPossibilitiesForTabCompletion(Player, "cd ", 0)).equal([
["www/"], "www/",
); ]);
}); });
it("completes the ls and cd commands", () => { it("completes the ls and cd commands", () => {
@ -173,7 +177,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
for (const command of ["ls", "cd"]) { for (const command of ["ls", "cd"]) {
expect( expect(
determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0), determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0),
).toEqual(["www/"]); ).equal(["www/"]);
} }
}); });
@ -181,6 +185,6 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
expect( expect(
determineAllPossibilitiesForTabCompletion(Player, "run ./", 0), determineAllPossibilitiesForTabCompletion(Player, "run ./", 0),
).toEqual([".//www/script.js", "NUKE.exe", "./www/"]); ).equal([".//www/script.js", "NUKE.exe", "./www/"]);
}); });
}); });