From 5f864c123bafa1a8d2a629998506093c2b389760 Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Robinson" Date: Fri, 14 Jan 2022 19:01:11 -0800 Subject: [PATCH 1/2] When saving we were not saving the script content --- src/Script/Script.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Script/Script.ts b/src/Script/Script.ts index 7b055c025..d6b13dbff 100644 --- a/src/Script/Script.ts +++ b/src/Script/Script.ts @@ -118,7 +118,7 @@ export class Script { */ saveScript(player: IPlayer, filename: string, code: string, hostname: string, otherScripts: Script[]): void { // Update code and filename - this.code = Script.formatCode(this.code); + this.code = Script.formatCode(code); this.filename = filename; this.server = hostname; From c9391130f4c355d7d9816c53f43f92def7cacd4b Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Robinson" Date: Fri, 14 Jan 2022 19:32:44 -0800 Subject: [PATCH 2/2] Add Test --- test/Script/Script.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/Script/Script.test.ts diff --git a/test/Script/Script.test.ts b/test/Script/Script.test.ts new file mode 100644 index 000000000..f0914d3c8 --- /dev/null +++ b/test/Script/Script.test.ts @@ -0,0 +1,29 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { jest, describe, expect, test } from "@jest/globals"; + +import { Script } from "../../src/Script/Script"; +import { Player } from "../../src/Player"; + +jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", { + virtual: true, +}); + +const code = `/** @param {NS} ns **/ +export async function main(ns) { + ns.print(ns.getWeakenTime('n00dles')); +}`; + +describe("Validate Save Script Works", function () { + + it("Save", function () { + const server = "home"; + const filename = "test.js"; + const player = Player; + const script = new Script(); + script.saveScript(player, filename, code, server, []); + + expect(script.filename).toEqual(filename) + expect(script.code).toEqual(code) + expect(script.server).toEqual(server) + }); +}); \ No newline at end of file