mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
Merge branch 'dev' into bugfix/fix-tests
This commit is contained in:
@@ -1 +1 @@
|
||||
module.exports = 'test-file-stub';
|
||||
module.exports = "test-file-stub";
|
||||
|
||||
@@ -4,7 +4,7 @@ beforeEach(() => {
|
||||
cy.visit("/", {
|
||||
onBeforeLoad(win: Cypress.AUTWindow) {
|
||||
win.indexedDB.deleteDatabase("bitburnerSave");
|
||||
}
|
||||
},
|
||||
});
|
||||
cy.clearLocalStorage();
|
||||
});
|
||||
|
||||
@@ -66,6 +66,39 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
||||
expect(multipleCallsCalculated).toEqual(ScriptBaseCost);
|
||||
}
|
||||
|
||||
// simplyfied version from RamCostGenerator.ts
|
||||
function SF4Cost(player, cost) {
|
||||
if (player.bitNodeN === 4) return cost;
|
||||
const sf4 = player.sourceFileLvl(4);
|
||||
if (sf4 <= 1) return cost * 16;
|
||||
if (sf4 === 2) return cost * 4;
|
||||
return cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that:
|
||||
* 1. A function has a specific RAM cost
|
||||
* 2. The calculator and the generator result in equal values
|
||||
* 3. Running multiple calls of the function does not result in additional RAM cost
|
||||
* @param {string[]} fnDesc - describes the name of the function being tested,
|
||||
* including the namespace(s). e.g. ["gang", "getMemberNames"]
|
||||
* @param {number} cost - expected cost
|
||||
*/
|
||||
async function expectSpecificRamCost(fnDesc, cost) {
|
||||
if (!Array.isArray(fnDesc)) {
|
||||
expect.fail("Non-array passed to expectZeroRamCost()");
|
||||
}
|
||||
const expected = getRamCost(Player, ...fnDesc);
|
||||
expect(expected).toEqual(SF4Cost(Player, cost));
|
||||
|
||||
const code = fnDesc.join(".") + "(); ";
|
||||
const calculated = (await calculateRamUsage(Player, code, [])).cost;
|
||||
testEquality(calculated, ScriptBaseCost + SF4Cost(Player, cost));
|
||||
|
||||
const multipleCallsCalculated = (await calculateRamUsage(Player, code, [])).cost;
|
||||
expect(multipleCallsCalculated).toEqual(ScriptBaseCost + SF4Cost(Player, cost));
|
||||
}
|
||||
|
||||
describe("Basic Functions", function () {
|
||||
it("hack()", async function () {
|
||||
const f = ["hack"];
|
||||
@@ -466,6 +499,11 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
||||
const f = ["getFavorToDonate"];
|
||||
await expectNonZeroRamCost(f);
|
||||
});
|
||||
|
||||
it("goToLocation()", async function () {
|
||||
const f = ["goToLocation"];
|
||||
await expectSpecificRamCost(f, RamCostConstants.ScriptSingularityFn3RamCost);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Advanced Functions", function () {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Script } from "../../../src/Script/Script";
|
||||
import { Player } from "../../../src/Player";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
virtual: true,
|
||||
});
|
||||
|
||||
const code = `/** @param {NS} ns */
|
||||
@@ -14,16 +14,15 @@ export async function main(ns) {
|
||||
}`;
|
||||
|
||||
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, []);
|
||||
|
||||
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)
|
||||
});
|
||||
expect(script.filename).toEqual(filename);
|
||||
expect(script.code).toEqual(code);
|
||||
expect(script.server).toEqual(server);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
|
||||
import { CONSTANTS } from "../../src/Constants";
|
||||
import { Player } from "../../src/Player";
|
||||
@@ -39,7 +39,7 @@ import {
|
||||
import { OrderTypes } from "../../src/StockMarket/data/OrderTypes";
|
||||
import { PositionTypes } from "../../src/StockMarket/data/PositionTypes";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', {
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
});
|
||||
|
||||
@@ -429,7 +429,7 @@ describe("Stock Market Tests", function () {
|
||||
expect(StockMarket).toHaveProperty("lastUpdate");
|
||||
expect(StockMarket["lastUpdate"]).toEqual(0);
|
||||
expect(StockMarket).toHaveProperty("ticksUntilCycle");
|
||||
expect(typeof StockMarket["ticksUntilCycle"]).toBe('number');
|
||||
expect(typeof StockMarket["ticksUntilCycle"]).toBe("number");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
import { convertTimeMsToTimeElapsedString } from "../../src/utils/StringHelperFunctions";
|
||||
|
||||
describe("StringHelperFunctions Tests", function () {
|
||||
@@ -15,8 +15,8 @@ describe("StringHelperFunctions Tests", function () {
|
||||
expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123, true)).toEqual(
|
||||
"2 days 5 minutes 34.123 seconds",
|
||||
);
|
||||
expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123.888, true)).toEqual(
|
||||
"2 days 5 minutes 34.123 seconds",
|
||||
);
|
||||
expect(
|
||||
convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123.888, true),
|
||||
).toEqual("2 days 5 minutes 34.123 seconds");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
import * as dirHelpers from "../../../src/Terminal/DirectoryHelpers";
|
||||
|
||||
describe("Terminal Directory Tests", function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CityName } from './../../../src/Locations/data/CityNames';
|
||||
import { CityName } from "./../../../src/Locations/data/CityNames";
|
||||
/* eslint-disable no-await-in-loop */
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from "@jest/globals";
|
||||
import { numeralWrapper } from "../../../src/ui/numeralFormat";
|
||||
|
||||
let decimalFormat = '0.[000000]';
|
||||
let decimalFormat = "0.[000000]";
|
||||
|
||||
describe('Numeral formatting for positive numbers', () => {
|
||||
test('should not format too small numbers', () => {
|
||||
|
||||
Reference in New Issue
Block a user