Fix tests syntax for jest

Most tests could not run with jest because of syntax difference between
the old test runner.
This commit is contained in:
Martin Fournier
2021-12-19 04:42:16 -05:00
parent 890b1df593
commit d1696148c4
5 changed files with 340 additions and 313 deletions
@@ -1,3 +1,4 @@
/* eslint-disable no-await-in-loop */
import { Player } from "../../src/Player";
import { determineAllPossibilitiesForTabCompletion } from "../../src/Terminal/determineAllPossibilitiesForTabCompletion";
import { Server } from "../../src/Server/Server";
@@ -5,6 +6,10 @@ import { AddToAllServers, prestigeAllServers } from "../../src/Server/AllServers
import { LocationName } from "../../src/Locations/data/LocationNames";
import { CodingContract } from "../../src/CodingContracts";
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', {
virtual: true,
});
describe("determineAllPossibilitiesForTabCompletion", function () {
let closeServer: Server;
let farServer: Server;
@@ -41,14 +46,14 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
AddToAllServers(farServer);
});
it("completes the connect command", () => {
const options = determineAllPossibilitiesForTabCompletion(Player, "connect ", 0);
expect(options).equal(["8.8.8.8", "near"]);
it("completes the connect command", async () => {
const options = await determineAllPossibilitiesForTabCompletion(Player, "connect ", 0);
expect(options).toEqual(["near"]);
});
it("completes the buy command", () => {
const options = determineAllPossibilitiesForTabCompletion(Player, "buy ", 0);
expect(options).equal([
it("completes the buy command", async () => {
const options = await determineAllPossibilitiesForTabCompletion(Player, "buy ", 0);
expect(options.sort()).toEqual([
"BruteSSH.exe",
"FTPCrack.exe",
"relaySMTP.exe",
@@ -58,45 +63,48 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
"DeepscanV2.exe",
"AutoLink.exe",
"ServerProfiler.exe",
]);
"Formulas.exe",
].sort());
});
it("completes the scp command", () => {
it("completes the scp command", async () => {
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
Player.getHomeComputer().messages.push("af.lit");
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
const options1 = determineAllPossibilitiesForTabCompletion(Player, "scp ", 0);
expect(options1).equal(["/www/script.js", "af.lit", "note.txt", "www/"]);
const options1 = await determineAllPossibilitiesForTabCompletion(Player, "scp ", 0);
expect(options1).toEqual(["/www/script.js", "af.lit", "note.txt", "www/"]);
const options2 = determineAllPossibilitiesForTabCompletion(Player, "scp note.txt ", 1);
expect(options2).equal([Player.getHomeComputer().ip, "home", "8.8.8.8", "near", "4.4.4.4", "far"]);
const options2 = await determineAllPossibilitiesForTabCompletion(Player, "scp note.txt ", 1);
expect(options2).toEqual(["home", "near", "far"]);
});
it("completes the kill, tail, mem, and check commands", () => {
it("completes the kill, tail, mem, and check commands", async () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
for (const command of ["kill", "tail", "mem", "check"]) {
expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal(["/www/script.js", "www/"]);
const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0);
expect(options).toEqual(["/www/script.js", "www/"]);
}
});
it("completes the nano commands", () => {
it("completes the nano commands", async () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
expect(determineAllPossibilitiesForTabCompletion(Player, "nano ", 0)).equal([
const options = await determineAllPossibilitiesForTabCompletion(Player, "nano ", 0);
expect(options).toEqual([
"/www/script.js",
"note.txt",
".fconf",
"www/",
]);
});
it("completes the rm command", () => {
it("completes the rm command", async () => {
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
Player.getHomeComputer().messages.push("asl.msg");
Player.getHomeComputer().messages.push("af.lit");
expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).equal([
const options = await determineAllPossibilitiesForTabCompletion(Player, "rm ", 0);
expect(options).toEqual([
"/www/script.js",
"NUKE.exe",
"af.lit",
@@ -106,10 +114,11 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
]);
});
it("completes the run command", () => {
it("completes the run command", async () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
expect(determineAllPossibilitiesForTabCompletion(Player, "run ", 0)).equal([
const options = await determineAllPossibilitiesForTabCompletion(Player, "run ", 0);
expect(options).toEqual([
"/www/script.js",
"NUKE.exe",
"linklist.cct",
@@ -117,11 +126,12 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
]);
});
it("completes the cat command", () => {
it("completes the cat command", async () => {
Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark");
Player.getHomeComputer().messages.push("asl.msg");
Player.getHomeComputer().messages.push("af.lit");
expect(determineAllPossibilitiesForTabCompletion(Player, "cat ", 0)).equal([
const options = await determineAllPossibilitiesForTabCompletion(Player, "cat ", 0);
expect(options).toEqual([
"asl.msg",
"af.lit",
"/www/note.txt",
@@ -129,11 +139,13 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
]);
});
it("completes the download and mv commands", () => {
it("completes the download and mv commands", async () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
for (const command of ["download", "mv"]) {
expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal([
const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0);
expect(options).toEqual([
"/www/script.js",
"note.txt",
"www/",
@@ -141,21 +153,24 @@ describe("determineAllPossibilitiesForTabCompletion", function () {
}
});
it("completes the cd command", () => {
it("completes the cd command", async () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
expect(determineAllPossibilitiesForTabCompletion(Player, "cd ", 0)).equal(["www/"]);
const options = await determineAllPossibilitiesForTabCompletion(Player, "cd ", 0);
expect(options).toEqual(["www/"]);
});
it("completes the ls and cd commands", () => {
it("completes the ls and cd commands", async () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
for (const command of ["ls", "cd"]) {
expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal(["www/"]);
const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0);
expect(options).toEqual(["www/"]);
}
});
it("completes commands starting with ./", () => {
it("completes commands starting with ./", async () => {
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
expect(determineAllPossibilitiesForTabCompletion(Player, "run ./", 0)).equal([
const options = await determineAllPossibilitiesForTabCompletion(Player, "run ./", 0);
expect(options).toEqual([
".//www/script.js",
"NUKE.exe",
"./www/",