bitburner-src/test/jest/FullSave.test.ts

79 lines
2.7 KiB
TypeScript
Raw Normal View History

import { saveObject } from "../../src/SaveObject";
2023-06-26 04:53:35 +02:00
import { Factions } from "../../src/Faction/Factions";
import { Player, setPlayer } from "../../src/Player";
import { PlayerObject } from "../../src/PersonObjects/Player/PlayerObject";
import { joinFaction } from "../../src/Faction/FactionHelpers";
2023-07-11 15:23:17 +02:00
import { AugmentationName, CompanyName, CrimeType, FactionName } from "../../src/Enums";
import { Augmentations } from "../../src/Augmentation/Augmentations";
import { SleeveCrimeWork } from "../../src/PersonObjects/Sleeve/Work/SleeveCrimeWork";
2023-07-11 15:23:17 +02:00
import { Companies } from "../../src/Company/Companies";
describe("Check Save File Continuity", () => {
establishInitialConditions();
beforeAll(async () => {
// Calling getSaveString forces save info to update
await saveObject.getSaveData();
});
const savesToTest = ["FactionsSave", "PlayerSave", "CompaniesSave", "GoSave"] as const;
for (const saveToTest of savesToTest) {
test(`${saveToTest} continuity`, () => {
const parsed: unknown = JSON.parse(saveObject[saveToTest]);
expect(parsed).toMatchSnapshot();
});
}
});
function establishInitialConditions() {
// Jest overrides to produce static savedata
jest.useFakeTimers().setSystemTime(1687611703623);
let i = 0.5;
Math.random = () => {
return (++i % 37) / 37;
};
// Game initializers
setPlayer(new PlayerObject());
Player.init();
Player.identifier = "Overwritten identifier";
Player.sleevesFromCovenant = 1;
Player.sourceFiles.set(10, 1);
Player.prestigeAugmentation();
/* Not comparing servers yet
// Just to reduce snapshot size, reduce server map to home + 2 servers
for (let i = serverMetadata.length - 1; i >= 0; i--) {
if (!["zer0", "n00dles"].includes(serverMetadata[i].hostname)) serverMetadata.splice(i, 1);
}
initForeignServers(Player.getHomeComputer());
*/
// Sleeves (already added in game initializers section)
Player.sleeves[0].installAugmentation(Augmentations[AugmentationName.BionicArms]);
Player.sleeves[0].startWork(new SleeveCrimeWork(CrimeType.homicide));
// Factions
const bladeburnerFaction = Factions[FactionName.Bladeburners];
const csec = Factions[FactionName.CyberSec];
const slumSnakes = Factions[FactionName.SlumSnakes];
joinFaction(bladeburnerFaction);
joinFaction(csec);
joinFaction(slumSnakes);
csec.playerReputation = 1e6;
2024-05-28 21:04:16 +02:00
csec.setFavor(20);
2023-07-11 15:23:17 +02:00
// Companies
const noodleBar = Companies[CompanyName.NoodleBar];
2024-05-28 21:04:16 +02:00
noodleBar.setFavor(100);
2023-07-11 15:23:17 +02:00
noodleBar.playerReputation = 100000;
// Bladeburner. Adding rank will also add bladeburner faction rep.
Player.startBladeburner();
Player.bladeburner?.changeRank(Player, 2000);
// Corp
Player.startCorporation("Test Corp", false);
// Gang
Player.startGang(FactionName.SlumSnakes, false);
}