SCRIPTS: Script modules are reused when they are imported (#461)

Also corrects some compile race conditions.
This commit is contained in:
Snarling
2023-04-07 00:33:51 -04:00
committed by GitHub
parent f5cddb6984
commit 04d49e3a6d
67 changed files with 428 additions and 561 deletions

View File

@@ -7,16 +7,6 @@ import { loadAllServers, saveAllServers } from "../../src/Server/AllServers";
// without requiring burdensome levels of maintenance when legitimate changes
// are made.
// Get a stable clock so we don't have time-based diffs.
function freezeTime() {
// You're about to hack time, are you sure? YES/NO
const RealDate = Date;
Date = function () {
return new RealDate(1678834800000);
};
Date.now = () => 1678834800000;
}
// Savegame generated from dev on 2023-03-12, mostly empty game with a few
// tweaks. A RunningScript was added in-game to test the one bit of
// non-trivial machinery involved in save/load.
@@ -147,7 +137,6 @@ test("load/saveAllServers", () => {
// Feed a JSON object through loadAllServers/saveAllServers.
// The object is a pruned set of servers that was extracted from a real (dev) game.
freezeTime();
loadStandardServers();
// Re-stringify with indenting for nicer diffs
@@ -159,7 +148,6 @@ test("load/saveAllServers pruning RunningScripts", () => {
// Feed a JSON object through loadAllServers/saveAllServers.
// The object is a pruned set of servers that was extracted from a real (dev) game.
freezeTime();
loadStandardServers();
// Re-stringify with indenting for nicer diffs

View File

@@ -10,7 +10,7 @@ describe("Validate Save Script Works", function () {
const server = "home";
const filename = "test.js";
const script = new Script();
script.saveScript(filename, code, server, []);
script.saveScript(filename, code, server);
expect(script.filename).toEqual(filename);
expect(script.code).toEqual(code);

View File

@@ -29,26 +29,16 @@ exports[`load/saveAllServers 1`] = `
"args": [],
"dataMap": {},
"filename": "script.js",
"logs": [],
"logUpd": true,
"offlineExpGained": 0,
"offlineMoneyMade": 0,
"offlineRunningTime": 0.01,
"onlineExpGained": 0,
"onlineMoneyMade": 0,
"onlineRunningTime": 7.210000000000004,
"pid": 2,
"ramUsage": 1.6,
"server": "home",
"threads": 1,
"temporary": false,
"dependencies": [
{
"filename": "script.js",
"url": "blob:http://localhost/302fe9e5-2ec3-4ed7-bb5a-4f8f4a85f46d",
"moduleSequenceNumber": 2
}
]
"temporary": false
}
}
],
@@ -58,27 +48,7 @@ exports[`load/saveAllServers 1`] = `
"data": {
"code": "/** @param {NS} ns */\\\\nexport async function main(ns) {\\\\n return ns.asleep(1000000);\\\\n}",
"filename": "script.js",
"url": "",
"module": {},
"dependencies": [
{
"filename": "script.js",
"url": "blob:http://localhost/e0abfafd-2c73-42fc-9eea-288c03820c47",
"moduleSequenceNumber": 5
}
],
"dependents": [],
"ramUsage": 1.6,
"queueCompile": false,
"server": "home",
"moduleSequenceNumber": 5,
"ramUsageEntries": [
{
"type": "misc",
"name": "baseCost",
"cost": 1.6
}
]
"server": "home"
}
}
],
@@ -172,27 +142,7 @@ exports[`load/saveAllServers pruning RunningScripts 1`] = `
"data": {
"code": "/** @param {NS} ns */\\\\nexport async function main(ns) {\\\\n return ns.asleep(1000000);\\\\n}",
"filename": "script.js",
"url": "",
"module": {},
"dependencies": [
{
"filename": "script.js",
"url": "blob:http://localhost/e0abfafd-2c73-42fc-9eea-288c03820c47",
"moduleSequenceNumber": 5
}
],
"dependents": [],
"ramUsage": 1.6,
"queueCompile": false,
"server": "home",
"moduleSequenceNumber": 5,
"ramUsageEntries": [
{
"type": "misc",
"name": "baseCost",
"cost": 1.6
}
]
"server": "home"
}
}
],