Fix renamed functions from 1.0 release in tests

This commit is contained in:
Martin Fournier 2021-12-19 12:10:06 -05:00
parent d1696148c4
commit 92e8b42d18
3 changed files with 111 additions and 108 deletions

@ -4,6 +4,8 @@ module.exports = {
transform: { transform: {
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest", "^.+\\.(js|jsx|ts|tsx)$": "babel-jest",
}, },
// testMatch: ["**/?(*.)+(test).[jt]s?(x)"], testPathIgnorePatterns: [
'.cypress', 'node_modules', 'dist',
],
testEnvironment: "jsdom", testEnvironment: "jsdom",
}; };

@ -9,6 +9,11 @@ jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', {
virtual: true, virtual: true,
}); });
jest.mock("../../src/Netscript/killWorkerScript", () => ({
__esModule: true,
killWorkerScript: jest.fn(),
}));
const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost; const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost;
describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
@ -158,7 +163,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
runPotentiallyAsyncFunction(curr); runPotentiallyAsyncFunction(curr);
} catch (e) {} } catch (e) {}
} else { } else {
throw new Error(`Invalid function specified: [${fndesc}]`); throw new Error(`Invalid function specified: [${fnDesc}]`);
} }
testEquality(workerScript.dynamicRamUsage, ScriptBaseCost); testEquality(workerScript.dynamicRamUsage, ScriptBaseCost);
@ -192,13 +197,13 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("hackAnalyzePercent()", async function () { it("hackAnalyze()", async function () {
const f = ["hackAnalyzePercent"]; const f = ["hackAnalyze"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("hackChance()", async function () { it("hackAnalyzeChance()", async function () {
const f = ["hackChance"]; const f = ["hackAnalyzeChance"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
@ -289,6 +294,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
it("exec()", async function () { it("exec()", async function () {
const f = ["exec"]; const f = ["exec"];
jest.spyOn(console, 'log').mockImplementation(() => {}); // eslint-disable-line
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
@ -454,32 +460,32 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
it("write()", async function () { it("write()", async function () {
const f = ["write"]; const f = ["write"];
await testNonzeroDynamicRamCost(f); await testZeroDynamicRamCost(f);
}); });
it("tryWrite()", async function () { it("tryWritePort()", async function () {
const f = ["tryWrite"]; const f = ["tryWritePort"];
await testNonzeroDynamicRamCost(f); await testZeroDynamicRamCost(f);
}); });
it("read()", async function () { it("read()", async function () {
const f = ["read"]; const f = ["read"];
await testNonzeroDynamicRamCost(f); await testZeroDynamicRamCost(f);
}); });
it("peek()", async function () { it("peek()", async function () {
const f = ["peek"]; const f = ["peek"];
await testNonzeroDynamicRamCost(f); await testZeroDynamicRamCost(f);
}); });
it("clear()", async function () { it("clear()", async function () {
const f = ["clear"]; const f = ["clear"];
await testNonzeroDynamicRamCost(f); await testZeroDynamicRamCost(f);
}); });
it("getPortHandle()", async function () { it("getPortHandle()", async function () {
const f = ["getPortHandle"]; const f = ["getPortHandle"];
await testNonzeroDynamicRamCost(f); await testZeroDynamicRamCost(f);
}); });
it("rm()", async function () { it("rm()", async function () {
@ -581,88 +587,88 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
}); });
describe("TIX API", function () { describe("TIX API", function () {
it("getStockSymbols()", async function () { it("stock.getSymbols()", async function () {
const f = ["getStockSymbols"]; const f = ["stock", "getSymbols"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getStockPrice()", async function () { it("stock.getPrice()", async function () {
const f = ["getStockPrice"]; const f = ["stock", "getPrice"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getStockAskPrice()", async function () { it("stock.getBidPrice()", async function () {
const f = ["getStockAskPrice"]; const f = ["stock", "getBidPrice"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getStockBidPrice()", async function () { it("stock.getBidPrice()", async function () {
const f = ["getStockBidPrice"]; const f = ["stock", "getBidPrice"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getStockPosition()", async function () { it("stock.getPosition()", async function () {
const f = ["getStockPosition"]; const f = ["stock", "getPosition"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getStockMaxShares()", async function () { it("stock.getMaxShares()", async function () {
const f = ["getStockMaxShares"]; const f = ["stock", "getMaxShares"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("buyStock()", async function () { it("stock.buy()", async function () {
const f = ["buyStock"]; const f = ["stock", "buy"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("sellStock()", async function () { it("stock.sell()", async function () {
const f = ["sellStock"]; const f = ["stock", "sell"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("shortStock()", async function () { it("stock.short()", async function () {
const f = ["shortStock"]; const f = ["stock", "short"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("sellShort()", async function () { it("stock.sellShort()", async function () {
const f = ["sellShort"]; const f = ["stock", "sellShort"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("placeOrder()", async function () { it("stock.placeOrder()", async function () {
const f = ["placeOrder"]; const f = ["stock", "placeOrder"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("cancelOrder()", async function () { it("stock.cancelOrder()", async function () {
const f = ["cancelOrder"]; const f = ["stock", "cancelOrder"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getOrders()", async function () { it("stock.getOrders()", async function () {
const f = ["getOrders"]; const f = ["stock", "getOrders"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getStockVolatility()", async function () { it("stock.getVolatility()", async function () {
const f = ["getStockVolatility"]; const f = ["stock", "getVolatility"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getStockForecast()", async function () { it("stock.getForecast()", async function () {
const f = ["getStockForecast"]; const f = ["stock", "getForecast"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("purchase4SMarketData()", async function () { it("stock.purchase4SMarketData()", async function () {
const f = ["purchase4SMarketData"]; const f = ["stock", "purchase4SMarketData"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("purchase4SMarketDataTixApi()", async function () { it("stock.purchase4SMarketDataTixApi()", async function () {
const f = ["purchase4SMarketDataTixApi"]; const f = ["stock", "purchase4SMarketDataTixApi"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
}); });
@ -975,11 +981,6 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);
}); });
it("getCityEstimatedCommunities()", async function () {
const f = ["bladeburner", "getCityEstimatedCommunities"];
await testNonzeroDynamicRamCost(f);
});
it("getCityChaos()", async function () { it("getCityChaos()", async function () {
const f = ["bladeburner", "getCityChaos"]; const f = ["bladeburner", "getCityChaos"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f);

@ -4,6 +4,11 @@ import { calculateRamUsage } from "../../src/Script/RamCalculations";
const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost; const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost;
const HacknetNamespaceCost = RamCostConstants.ScriptHacknetNodesRamCost; const HacknetNamespaceCost = RamCostConstants.ScriptHacknetNodesRamCost;
jest.mock("../../src/Netscript/killWorkerScript", () => ({
__esModule: true,
killWorkerScript: jest.fn(),
}));
describe("Netscript Static RAM Calculation/Generation Tests", function () { describe("Netscript Static RAM Calculation/Generation Tests", function () {
// Tests numeric equality, allowing for floating point imprecision // Tests numeric equality, allowing for floating point imprecision
function testEquality(val, expected) { function testEquality(val, expected) {
@ -81,13 +86,13 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("hackAnalyzePercent()", async function () { it("hackAnalyze()", async function () {
const f = ["hackAnalyzePercent"]; const f = ["hackAnalyze"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("hackChance()", async function () { it("hackAnalyzeChance()", async function () {
const f = ["hackChance"]; const f = ["hackAnalyzeChance"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
@ -343,32 +348,32 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
it("write()", async function () { it("write()", async function () {
const f = ["write"]; const f = ["write"];
await expectNonZeroRamCost(f); await expectZeroRamCost(f);
}); });
it("tryWrite()", async function () { it("tryWritePort()", async function () {
const f = ["tryWrite"]; const f = ["tryWritePort"];
await expectNonZeroRamCost(f); await expectZeroRamCost(f);
}); });
it("read()", async function () { it("read()", async function () {
const f = ["read"]; const f = ["read"];
await expectNonZeroRamCost(f); await expectZeroRamCost(f);
}); });
it("peek()", async function () { it("peek()", async function () {
const f = ["peek"]; const f = ["peek"];
await expectNonZeroRamCost(f); await expectZeroRamCost(f);
}); });
it("clear()", async function () { it("clear()", async function () {
const f = ["clear"]; const f = ["clear"];
await expectNonZeroRamCost(f); await expectZeroRamCost(f);
}); });
it("getPortHandle()", async function () { it("getPortHandle()", async function () {
const f = ["getPortHandle"]; const f = ["getPortHandle"];
await expectNonZeroRamCost(f); await expectZeroRamCost(f);
}); });
it("rm()", async function () { it("rm()", async function () {
@ -508,98 +513,98 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
}); });
describe("TIX API", function () { describe("TIX API", function () {
it("getStockSymbols()", async function () { it("stock.getSymbols()", async function () {
const f = ["getStockSymbols"]; const f = ["stock", "getSymbols"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockPrice()", async function () { it("stock.getPrice()", async function () {
const f = ["getStockPrice"]; const f = ["stock", "getPrice"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockAskPrice()", async function () { it("stock.getAskPrice()", async function () {
const f = ["getStockAskPrice"]; const f = ["stock", "getAskPrice"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockBidPrice()", async function () { it("stock.getBidPrice()", async function () {
const f = ["getStockBidPrice"]; const f = ["stock", "getBidPrice"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockPosition()", async function () { it("stock.getPosition()", async function () {
const f = ["getStockPosition"]; const f = ["stock", "getPosition"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockMaxShares()", async function () { it("stock.getMaxShares()", async function () {
const f = ["getStockMaxShares"]; const f = ["stock", "getMaxShares"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockPurchaseCost()", async function () { it("stock.getPurchaseCost()", async function () {
const f = ["getStockPurchaseCost"]; const f = ["stock", "getPurchaseCost"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockSaleGain()", async function () { it("stock.getSaleGain()", async function () {
const f = ["getStockSaleGain"]; const f = ["stock", "getSaleGain"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("buyStock()", async function () { it("stock.buy()", async function () {
const f = ["buyStock"]; const f = ["stock", "buy"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("sellStock()", async function () { it("stock.sell()", async function () {
const f = ["sellStock"]; const f = ["stock", "sell"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("shortStock()", async function () { it("stock.short()", async function () {
const f = ["shortStock"]; const f = ["stock", "short"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("sellShort()", async function () { it("stock.sellShort()", async function () {
const f = ["sellShort"]; const f = ["stock", "sell"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("placeOrder()", async function () { it("stock.placeOrder()", async function () {
const f = ["placeOrder"]; const f = ["stock", "placeOrder"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("cancelOrder()", async function () { it("stock.cancelOrder()", async function () {
const f = ["cancelOrder"]; const f = ["stock", "cancelOrder"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getOrders()", async function () { it("stock.getOrders()", async function () {
const f = ["getOrders"]; const f = ["stock", "getOrders"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockVolatility()", async function () { it("stock.getVolatility()", async function () {
const f = ["getStockVolatility"]; const f = ["stock", "getVolatility"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getStockForecast()", async function () { it("stock.getForecast()", async function () {
const f = ["getStockForecast"]; const f = ["stock", "getForecast"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("purchase4SMarketData()", async function () { it("stock.purchase4SMarketData()", async function () {
const f = ["purchase4SMarketData"]; const f = ["stock", "purchase4SMarketData"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("purchase4SMarketDataTixApi()", async function () { it("stock.purchase4SMarketDataTixApi()", async function () {
const f = ["purchase4SMarketDataTixApi"]; const f = ["stock", "purchase4SMarketDataTixApi"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
}); });
@ -912,11 +917,6 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);
}); });
it("getCityEstimatedCommunities()", async function () {
const f = ["bladeburner", "getCityEstimatedCommunities"];
await expectNonZeroRamCost(f);
});
it("getCityChaos()", async function () { it("getCityChaos()", async function () {
const f = ["bladeburner", "getCityChaos"]; const f = ["bladeburner", "getCityChaos"];
await expectNonZeroRamCost(f); await expectNonZeroRamCost(f);