mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
JEST: Add Jest test to test migration from v2 to v3 (#2305)
This commit is contained in:
40
test/jest/Migration/Migration.test.ts
Normal file
40
test/jest/Migration/Migration.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Player } from "@player";
|
||||
import fs from "node:fs";
|
||||
import type { ScriptFilePath } from "../../../src/Paths/ScriptFilePath";
|
||||
import { loadGame } from "../../../src/SaveObject";
|
||||
import * as db from "../../../src/db";
|
||||
import * as FileUtils from "../../../src/utils/FileUtils";
|
||||
|
||||
describe("v3", () => {
|
||||
test("v2.8.1 to v3.0.0", async () => {
|
||||
const saveData = new Uint8Array(fs.readFileSync("test/jest/Migration/save-files/v2.8.1.gz"));
|
||||
|
||||
// Simulate loading the data in IndexedDB
|
||||
const mockedLoad = jest.spyOn(db, "load");
|
||||
/**
|
||||
* We must use structuredClone(saveData) instead of saveData; otherwise, the check of mockedDownload won't catch
|
||||
* wrong changes in evaluateVersionCompatibility (e.g., unexpectedly mutating saveData before passing it to
|
||||
* downloadContentAsFile).
|
||||
*/
|
||||
mockedLoad.mockReturnValue(Promise.resolve(structuredClone(saveData)));
|
||||
|
||||
const mockedDownload = jest.spyOn(FileUtils, "downloadContentAsFile");
|
||||
|
||||
await loadGame(await db.load());
|
||||
|
||||
// Check if auto-migration works
|
||||
expect(
|
||||
Player.getHomeComputer()
|
||||
.scripts.get("a.js" as ScriptFilePath)
|
||||
?.code.includes("ns.ui.openTail()"),
|
||||
).toStrictEqual(true);
|
||||
if (!Player.corporation) {
|
||||
throw new Error("The save file does not have corporation data");
|
||||
}
|
||||
expect(Object.keys(Player.corporation.upgrades).includes("DreamSense")).toStrictEqual(false);
|
||||
expect(Player.corporation.funds).toStrictEqual(110e9);
|
||||
|
||||
// Check if evaluateVersionCompatibility correctly loads the data in IndexedDB and passes it to downloadContentAsFile
|
||||
expect(mockedDownload).toHaveBeenCalledWith(saveData, "bitburnerSave_backup_2.8.1_1756913326.json.gz");
|
||||
});
|
||||
});
|
||||
BIN
test/jest/Migration/save-files/v2.8.1.gz
Normal file
BIN
test/jest/Migration/save-files/v2.8.1.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user