From d1696148c4becee9162720a75519cf49674ad25a Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Sun, 19 Dec 2021 04:42:16 -0500 Subject: [PATCH 1/5] Fix tests syntax for jest Most tests could not run with jest because of syntax difference between the old test runner. --- src/Terminal/DirectoryHelpers.ts | 4 +- test/Netscript/DynamicRamCalculation.test.js | 4 + test/StockMarket.test.ts | 556 +++++++++--------- test/StringHelperFunctions.test.ts | 12 +- ...neAllPossibilitiesForTabCompletion.test.ts | 77 ++- 5 files changed, 340 insertions(+), 313 deletions(-) diff --git a/src/Terminal/DirectoryHelpers.ts b/src/Terminal/DirectoryHelpers.ts index 00599feac..c6d020639 100644 --- a/src/Terminal/DirectoryHelpers.ts +++ b/src/Terminal/DirectoryHelpers.ts @@ -35,7 +35,7 @@ export function removeTrailingSlash(s: string): string { * Checks whether a string is a valid filename. Only used for the filename itself, * not the entire filepath */ -function isValidFilename(filename: string): boolean { +export function isValidFilename(filename: string): boolean { // Allows alphanumerics, hyphens, underscores, and percentage signs // Must have a file extension const regex = /^[.a-zA-Z0-9_-]+[.][a-zA-Z0-9]+(?:-\d+(?:\.\d*)?%-INC)?$/; @@ -48,7 +48,7 @@ function isValidFilename(filename: string): boolean { * Checks whether a string is a valid directory name. Only used for the directory itself, * not an entire path */ -function isValidDirectoryName(name: string): boolean { + export function isValidDirectoryName(name: string): boolean { // Allows alphanumerics, hyphens, underscores, and percentage signs. // Name can begin with a single period, but otherwise cannot have any const regex = /^.?[a-zA-Z0-9_-]+$/; diff --git a/test/Netscript/DynamicRamCalculation.test.js b/test/Netscript/DynamicRamCalculation.test.js index db8bb8f35..9632e0895 100644 --- a/test/Netscript/DynamicRamCalculation.test.js +++ b/test/Netscript/DynamicRamCalculation.test.js @@ -5,6 +5,10 @@ import { RunningScript } from "../../src/Script/RunningScript"; import { Script } from "../../src/Script/Script"; import { SourceFileFlags } from "../../src/SourceFile/SourceFileFlags"; +jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', { + virtual: true, +}); + const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost; describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { diff --git a/test/StockMarket.test.ts b/test/StockMarket.test.ts index e72a0d6dc..49bceb122 100644 --- a/test/StockMarket.test.ts +++ b/test/StockMarket.test.ts @@ -35,7 +35,10 @@ import { } from "../src/StockMarket/StockMarketHelpers"; import { OrderTypes } from "../src/StockMarket/data/OrderTypes"; import { PositionTypes } from "../src/StockMarket/data/PositionTypes"; -// import { jest } from "jest"; + +jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', { + virtual: true, +}); // jest.mock("../src/ui/React/createPopup.tsx", () => ({ // createPopup: jest.fn(), @@ -63,7 +66,7 @@ describe("Stock Market Tests", function () { stock = new Stock(ctorParams); } - expect(construct).not.throw(); + expect(construct).not.toThrow(); }); describe("Stock Class", function () { @@ -72,26 +75,26 @@ describe("Stock Market Tests", function () { function construct(): void { new Stock(); // eslint-disable-line no-new } - expect(construct).not.throw(); + expect(construct).not.toThrow(); const defaultStock = new Stock(); - expect(defaultStock).not.equal(null); - expect(defaultStock.name).equal(""); + expect(defaultStock).not.toEqual(null); + expect(defaultStock.name).toEqual(""); }); it("should properly initialize props from parameters", function () { - expect(stock.name).equal(ctorParams.name); - expect(stock.symbol).equal(ctorParams.symbol); - expect(stock.price).equal(ctorParams.initPrice); - expect(stock.lastPrice).equal(ctorParams.initPrice); - expect(stock.b).equal(ctorParams.b); - expect(stock.mv).equal(ctorParams.mv); - expect(stock.shareTxForMovement).equal(ctorParams.shareTxForMovement); - expect(stock.shareTxUntilMovement).equal(ctorParams.shareTxForMovement); - expect(stock.maxShares).lessThan(stock.totalShares); - expect(stock.spreadPerc).equal(ctorParams.spreadPerc); - expect(stock.otlkMag).equal(ctorParams.otlkMag); - expect(stock.otlkMagForecast).equal(ctorParams.b ? 50 + ctorParams.otlkMag : 50 - ctorParams.otlkMag); + expect(stock.name).toEqual(ctorParams.name); + expect(stock.symbol).toEqual(ctorParams.symbol); + expect(stock.price).toEqual(ctorParams.initPrice); + expect(stock.lastPrice).toEqual(ctorParams.initPrice); + expect(stock.b).toEqual(ctorParams.b); + expect(stock.mv).toEqual(ctorParams.mv); + expect(stock.shareTxForMovement).toEqual(ctorParams.shareTxForMovement); + expect(stock.shareTxUntilMovement).toEqual(ctorParams.shareTxForMovement); + expect(stock.maxShares).toBeLessThan(stock.totalShares); + expect(stock.spreadPerc).toEqual(ctorParams.spreadPerc); + expect(stock.otlkMag).toEqual(ctorParams.otlkMag); + expect(stock.otlkMagForecast).toEqual(ctorParams.b ? 50 + ctorParams.otlkMag : 50 - ctorParams.otlkMag); }); it("should properly initialize props from range-values", function () { @@ -125,38 +128,38 @@ describe("Stock Market Tests", function () { new Stock(params); // eslint-disable-line no-new } - expect(construct).not.throw(); + expect(construct).not.toThrow(); const stock = new Stock(params); - expect(stock).not.equal(null); - expect(stock.price).gte(params.initPrice.min); - expect(stock.price).lte(params.initPrice.max); - expect(stock.mv).gte(params.mv.min / params.mv.divisor); - expect(stock.mv).lte(params.mv.max / params.mv.divisor); - expect(stock.spreadPerc).gte(params.spreadPerc.min / params.spreadPerc.divisor); - expect(stock.spreadPerc).lte(params.spreadPerc.max / params.spreadPerc.divisor); - expect(stock.shareTxForMovement).gte(params.shareTxForMovement.min); - expect(stock.shareTxForMovement).lte(params.shareTxForMovement.max); + expect(stock).not.toEqual(null); + expect(stock.price).toBeGreaterThan(params.initPrice.min); + expect(stock.price).toBeLessThan(params.initPrice.max); + expect(stock.mv).toBeGreaterThan(params.mv.min / params.mv.divisor); + expect(stock.mv).toBeLessThan(params.mv.max / params.mv.divisor); + expect(stock.spreadPerc).toBeGreaterThan(params.spreadPerc.min / params.spreadPerc.divisor); + expect(stock.spreadPerc).toBeLessThan(params.spreadPerc.max / params.spreadPerc.divisor); + expect(stock.shareTxForMovement).toBeGreaterThan(params.shareTxForMovement.min); + expect(stock.shareTxForMovement).toBeLessThan(params.shareTxForMovement.max); }); it("should round the 'totalShare' prop to the nearest 100k", function () { - expect(stock.totalShares % 100e3).equal(0); + expect(stock.totalShares % 100e3).toEqual(0); }); }); describe("#changeForecastForecast()", function () { it("should get the stock's second-order forecast property", function () { stock.changeForecastForecast(99); - expect(stock.otlkMagForecast).equal(99); + expect(stock.otlkMagForecast).toEqual(99); stock.changeForecastForecast(1); - expect(stock.otlkMagForecast).equal(1); + expect(stock.otlkMagForecast).toEqual(1); }); it("should prevent values outside of 0-100", function () { stock.changeForecastForecast(101); - expect(stock.otlkMagForecast).equal(100); + expect(stock.otlkMagForecast).toEqual(100); stock.changeForecastForecast(-1); - expect(stock.otlkMagForecast).equal(0); + expect(stock.otlkMagForecast).toEqual(0); }); }); @@ -164,8 +167,8 @@ describe("Stock Market Tests", function () { it("should set both the last price and current price properties", function () { const newPrice = 20e3; stock.changePrice(newPrice); - expect(stock.lastPrice).equal(ctorParams.initPrice); - expect(stock.price).equal(newPrice); + expect(stock.lastPrice).toEqual(ctorParams.initPrice); + expect(stock.price).toEqual(newPrice); }); }); @@ -175,13 +178,13 @@ describe("Stock Market Tests", function () { return 1; }; stock.cycleForecast(5); - expect(stock.otlkMag).equal(ctorParams.otlkMag + 5); + expect(stock.otlkMag).toEqual(ctorParams.otlkMag + 5); stock.getForecastIncreaseChance = () => { return 0; }; stock.cycleForecast(10); - expect(stock.otlkMag).equal(ctorParams.otlkMag - 5); + expect(stock.otlkMag).toEqual(ctorParams.otlkMag - 5); }); it("should NOT(!) the stock's 'b' property if it causes 'otlkMag' to go below 0", function () { @@ -189,8 +192,8 @@ describe("Stock Market Tests", function () { return 0; }; stock.cycleForecast(25); - expect(stock.otlkMag).equal(5); - expect(stock.b).equal(false); + expect(stock.otlkMag).toEqual(5); + expect(stock.b).toEqual(false); }); }); @@ -198,7 +201,7 @@ describe("Stock Market Tests", function () { it("should increase the stock's second-order forecast by a given amount", function () { const expected = [65, 75]; stock.cycleForecastForecast(5); - expect(expected).contain(stock.otlkMagForecast); + expect(expected).toEqual(expect.arrayContaining([stock.otlkMagForecast])); }); }); @@ -206,31 +209,31 @@ describe("Stock Market Tests", function () { it("should flip the 'otlkMagForecast' property around 50", function () { stock.otlkMagForecast = 50; stock.flipForecastForecast(); - expect(stock.otlkMagForecast).equal(50); + expect(stock.otlkMagForecast).toEqual(50); stock.otlkMagForecast = 60; stock.flipForecastForecast(); - expect(stock.otlkMagForecast).equal(40); + expect(stock.otlkMagForecast).toEqual(40); stock.otlkMagForecast = 90; stock.flipForecastForecast(); - expect(stock.otlkMagForecast).equal(10); + expect(stock.otlkMagForecast).toEqual(10); stock.otlkMagForecast = 100; stock.flipForecastForecast(); - expect(stock.otlkMagForecast).equal(0); + expect(stock.otlkMagForecast).toEqual(0); stock.otlkMagForecast = 40; stock.flipForecastForecast(); - expect(stock.otlkMagForecast).equal(60); + expect(stock.otlkMagForecast).toEqual(60); stock.otlkMagForecast = 0; stock.flipForecastForecast(); - expect(stock.otlkMagForecast).equal(100); + expect(stock.otlkMagForecast).toEqual(100); stock.otlkMagForecast = 25; stock.flipForecastForecast(); - expect(stock.otlkMagForecast).equal(75); + expect(stock.otlkMagForecast).toEqual(75); }); }); @@ -238,44 +241,44 @@ describe("Stock Market Tests", function () { it("should return the absolute forecast on a 1-100 scale", function () { stock.b = true; stock.otlkMag = 10; - expect(stock.getAbsoluteForecast()).equal(60); + expect(stock.getAbsoluteForecast()).toEqual(60); stock.b = false; - expect(stock.getAbsoluteForecast()).equal(40); + expect(stock.getAbsoluteForecast()).toEqual(40); stock.otlkMag = 30; - expect(stock.getAbsoluteForecast()).equal(20); + expect(stock.getAbsoluteForecast()).toEqual(20); stock.b = true; - expect(stock.getAbsoluteForecast()).equal(80); + expect(stock.getAbsoluteForecast()).toEqual(80); stock.otlkMag = 0; - expect(stock.getAbsoluteForecast()).equal(50); + expect(stock.getAbsoluteForecast()).toEqual(50); stock.b = false; - expect(stock.getAbsoluteForecast()).equal(50); + expect(stock.getAbsoluteForecast()).toEqual(50); }); }); describe("#getAskPrice()", function () { it("should return the price increased by spread percentage", function () { const perc = stock.spreadPerc / 100; - expect(perc).lte(1); - expect(perc).gte(0); + expect(perc).toBeLessThan(1); + expect(perc).toBeGreaterThan(0); const expected = stock.price * (1 + perc); - expect(stock.getAskPrice()).equal(expected); + expect(stock.getAskPrice()).toEqual(expected); }); }); describe("#getBidPrice()", function () { it("should return the price decreased by spread percentage", function () { const perc = stock.spreadPerc / 100; - expect(perc).lte(1); - expect(perc).gte(0); + expect(perc).toBeLessThan(1); + expect(perc).toBeGreaterThan(0); const expected = stock.price * (1 - perc); - expect(stock.getBidPrice()).equal(expected); + expect(stock.getBidPrice()).toEqual(expected); }); }); @@ -285,50 +288,50 @@ describe("Stock Market Tests", function () { stock.otlkMagForecast = 90; stock.otlkMag = 20; // Absolute forecast of 70 - expect(stock.getForecastIncreaseChance()).equal(0.7); + expect(stock.getForecastIncreaseChance()).toEqual(0.7); stock.otlkMag = 25; // Absolute forecast of 75 - expect(stock.getForecastIncreaseChance()).equal(0.65); + expect(stock.getForecastIncreaseChance()).toEqual(0.65); stock.otlkMagForecast = 100; stock.otlkMag = 0; // Absolute forecast of 50 - expect(stock.getForecastIncreaseChance()).equal(0.95); + expect(stock.getForecastIncreaseChance()).toEqual(0.95); stock.otlkMagForecast = 60; stock.otlkMag = 25; // Absolute forecast of 75 - expect(stock.getForecastIncreaseChance()).equal(0.35); + expect(stock.getForecastIncreaseChance()).toEqual(0.35); stock.otlkMagForecast = 10; - expect(stock.getForecastIncreaseChance()).equal(0.05); + expect(stock.getForecastIncreaseChance()).toEqual(0.05); stock.b = false; stock.otlkMagForecast = 90; stock.otlkMag = 20; // Absolute forecast of 30 - expect(stock.getForecastIncreaseChance()).equal(0.95); + expect(stock.getForecastIncreaseChance()).toEqual(0.95); stock.otlkMagForecast = 50; stock.otlkMag = 25; // Absolute forecast of 25 - expect(stock.getForecastIncreaseChance()).equal(0.75); + expect(stock.getForecastIncreaseChance()).toEqual(0.75); stock.otlkMagForecast = 100; stock.otlkMag = 0; // Absolute forecast of 50 - expect(stock.getForecastIncreaseChance()).equal(0.95); + expect(stock.getForecastIncreaseChance()).toEqual(0.95); stock.otlkMagForecast = 5; stock.otlkMag = 25; // Absolute forecast of 25 - expect(stock.getForecastIncreaseChance()).equal(0.3); + expect(stock.getForecastIncreaseChance()).toEqual(0.3); stock.otlkMagForecast = 10; - expect(stock.getForecastIncreaseChance()).equal(0.35); + expect(stock.getForecastIncreaseChance()).toEqual(0.35); stock.otlkMagForecast = 50; stock.otlkMag = 0; - expect(stock.getForecastIncreaseChance()).equal(0.5); + expect(stock.getForecastIncreaseChance()).toEqual(0.5); stock.otlkMagForecast = 25; stock.otlkMag = 5; // Asolute forecast of 45 - expect(stock.getForecastIncreaseChance()).equal(0.3); + expect(stock.getForecastIncreaseChance()).toEqual(0.3); }); }); @@ -339,25 +342,25 @@ describe("Stock Market Tests", function () { it("should change the forecast's value towards 50", function () { stock.influenceForecast(2); - expect(stock.otlkMag).equal(8); + expect(stock.otlkMag).toEqual(8); }); it("should not care about whether the stock is in bull or bear mode", function () { stock.b = true; stock.influenceForecast(1); - expect(stock.otlkMag).equal(9); + expect(stock.otlkMag).toEqual(9); stock.b = false; stock.influenceForecast(2); - expect(stock.otlkMag).equal(7); + expect(stock.otlkMag).toEqual(7); }); it("should not influence the forecast beyond the limit", function () { stock.influenceForecast(10); - expect(stock.otlkMag).equal(StockForecastInfluenceLimit); + expect(stock.otlkMag).toEqual(StockForecastInfluenceLimit); stock.influenceForecast(10); - expect(stock.otlkMag).equal(StockForecastInfluenceLimit); + expect(stock.otlkMag).toEqual(StockForecastInfluenceLimit); }); }); @@ -365,21 +368,21 @@ describe("Stock Market Tests", function () { it("should change the second-order forecast's value towards 50", function () { stock.otlkMagForecast = 75; stock.influenceForecastForecast(15); - expect(stock.otlkMagForecast).equal(60); + expect(stock.otlkMagForecast).toEqual(60); stock.otlkMagForecast = 25; stock.influenceForecastForecast(15); - expect(stock.otlkMagForecast).equal(40); + expect(stock.otlkMagForecast).toEqual(40); }); it("should not change the second-order forecast past 50", function () { stock.otlkMagForecast = 40; stock.influenceForecastForecast(20); - expect(stock.otlkMagForecast).equal(50); + expect(stock.otlkMagForecast).toEqual(50); stock.otlkMagForecast = 60; stock.influenceForecastForecast(20); - expect(stock.otlkMagForecast).equal(50); + expect(stock.otlkMagForecast).toEqual(50); }); }); }); @@ -390,8 +393,8 @@ describe("Stock Market Tests", function () { const stocks: string[] = []; beforeEach(function () { - expect(initStockMarket).not.throw(); - expect(initSymbolToStockMap).not.throw(); + expect(initStockMarket).not.toThrow(); + expect(initSymbolToStockMap).not.toThrow(); }); it("should have Stock objects", function () { @@ -403,35 +406,40 @@ describe("Stock Market Tests", function () { } // We'll just check that there are some stocks - expect(stocks.length).gte(1); + expect(stocks.length).toBeGreaterThan(1); }); it("should have an order book in the 'Orders' property", function () { - expect(StockMarket).have.property("Orders"); + expect(StockMarket).toHaveProperty("Orders"); const orderbook = StockMarket["Orders"]; for (const symbol of stocks) { const ordersForStock = orderbook[symbol]; - expect(ordersForStock).equal([]); - expect(ordersForStock.length).equal(0); + expect(ordersForStock).toEqual([]); + expect(ordersForStock.length).toEqual(0); } }); it("should have properties for managing game cycles", function () { - expect(StockMarket).have.property("storedCycles"); - expect(StockMarket["storedCycles"]).equal(0); - expect(StockMarket).have.property("lastUpdate"); - expect(StockMarket["lastUpdate"]).equal(0); - expect(StockMarket).have.property("ticksUntilCycle"); - expect(typeof StockMarket["ticksUntilCycle"]).instanceOf("number"); + expect(StockMarket).toHaveProperty("storedCycles"); + expect(StockMarket["storedCycles"]).toEqual(0); + expect(StockMarket).toHaveProperty("lastUpdate"); + expect(StockMarket["lastUpdate"]).toEqual(0); + expect(StockMarket).toHaveProperty("ticksUntilCycle"); + expect(typeof StockMarket["ticksUntilCycle"]).toBe('number'); }); }); describe("Deletion", function () { it("should set StockMarket to be an empty object", function () { - expect(StockMarket).not.equal({}); + expect(StockMarket).not.toEqual({}); deleteStockMarket(); - expect(StockMarket).equal({}); + expect(StockMarket).toEqual({ + lastUpdate: 0, + Orders: {}, + storedCycles: 0, + ticksUntilCycle: 0, + }); }); }); @@ -443,9 +451,9 @@ describe("Stock Market Tests", function () { }); it("should store cycles until it actually processes", function () { - expect(StockMarket["storedCycles"]).equal(0); + expect(StockMarket["storedCycles"]).toEqual(0); processStockPrices(10); - expect(StockMarket["storedCycles"]).equal(10); + expect(StockMarket["storedCycles"]).toEqual(10); }); it("should trigger a price update when it has enough cycles", function () { @@ -474,7 +482,7 @@ describe("Stock Market Tests", function () { continue; } const initValue = initialValues[stock.symbol]; - expect(initValue.price).not.equal(stock.price); + expect(initValue.price).not.toEqual(stock.price); if (initValue.otlkMag === stock.otlkMag && initValue.b === stock.b) { throw new Error("expected either price or otlkMag to be different"); } @@ -497,7 +505,7 @@ describe("Stock Market Tests", function () { continue; } - expect(SymbolToStockMap[stock.symbol]).equal(stock); + expect(SymbolToStockMap[stock.symbol]).toEqual(stock); } }); }); @@ -506,55 +514,55 @@ describe("Stock Market Tests", function () { describe("getBuyTransactionCost()", function () { it("should fail on invalid 'stock' argument", function () { const res = getBuyTransactionCost({} as Stock, 10, PositionTypes.Long); - expect(res).equal(null); + expect(res).toEqual(null); }); it("should fail on invalid 'shares' arg", function () { let res = getBuyTransactionCost(stock, NaN, PositionTypes.Long); - expect(res).equal(null); + expect(res).toEqual(null); res = getBuyTransactionCost(stock, -1, PositionTypes.Long); - expect(res).equal(null); + expect(res).toEqual(null); }); it("should properly evaluate LONG transactions", function () { const shares = ctorParams.shareTxForMovement / 2; const res = getBuyTransactionCost(stock, shares, PositionTypes.Long); - expect(res).equal(shares * stock.getAskPrice() + commission); + expect(res).toEqual(shares * stock.getAskPrice() + commission); }); it("should properly evaluate SHORT transactions", function () { const shares = ctorParams.shareTxForMovement / 2; const res = getBuyTransactionCost(stock, shares, PositionTypes.Short); - expect(res).equal(shares * stock.getBidPrice() + commission); + expect(res).toEqual(shares * stock.getBidPrice() + commission); }); it("should cap the 'shares' argument at the stock's maximum number of shares", function () { const maxRes = getBuyTransactionCost(stock, stock.maxShares, PositionTypes.Long); const exceedRes = getBuyTransactionCost(stock, stock.maxShares * 10, PositionTypes.Long); - expect(maxRes).equal(exceedRes); + expect(maxRes).toEqual(exceedRes); }); }); describe("getSellTransactionGain()", function () { it("should fail on invalid 'stock' argument", function () { const res = getSellTransactionGain({} as Stock, 10, PositionTypes.Long); - expect(res).equal(null); + expect(res).toEqual(null); }); it("should fail on invalid 'shares' arg", function () { let res = getSellTransactionGain(stock, NaN, PositionTypes.Long); - expect(res).equal(null); + expect(res).toEqual(null); res = getSellTransactionGain(stock, -1, PositionTypes.Long); - expect(res).equal(null); + expect(res).toEqual(null); }); it("should properly evaluate LONG transactionst", function () { const shares = ctorParams.shareTxForMovement / 2; const res = getSellTransactionGain(stock, shares, PositionTypes.Long); const expected = shares * stock.getBidPrice() - commission; - expect(res).equal(expected); + expect(res).toEqual(expected); }); it("should properly evaluate SHORT transactions", function () { @@ -565,13 +573,13 @@ describe("Stock Market Tests", function () { const res = getSellTransactionGain(stock, shares, PositionTypes.Short); const expected = shares * stock.playerAvgShortPx + shares * (stock.playerAvgShortPx - stock.getAskPrice()) - commission; - expect(res).equal(expected); + expect(res).toEqual(expected); }); it("should cap the 'shares' argument at the stock's maximum number of shares", function () { const maxRes = getSellTransactionGain(stock, stock.maxShares, PositionTypes.Long); const exceedRes = getSellTransactionGain(stock, stock.maxShares * 10, PositionTypes.Long); - expect(maxRes).equal(exceedRes); + expect(maxRes).toEqual(exceedRes); }); }); }); @@ -602,33 +610,33 @@ describe("Stock Market Tests", function () { const oldTracker = stock.shareTxUntilMovement; processTransactionForecastMovement({} as Stock, mvmtShares); - expect(stock.shareTxUntilMovement).equal(oldTracker); + expect(stock.shareTxUntilMovement).toEqual(oldTracker); }); it("should do nothing on invalid 'shares' arg", function () { const oldTracker = stock.shareTxUntilMovement; processTransactionForecastMovement(stock, NaN); - expect(stock.shareTxUntilMovement).equal(oldTracker); + expect(stock.shareTxUntilMovement).toEqual(oldTracker); processTransactionForecastMovement(stock, -1); - expect(stock.shareTxUntilMovement).equal(oldTracker); + expect(stock.shareTxUntilMovement).toEqual(oldTracker); }); it("should properly evaluate a LONG transaction that doesn't trigger a forecast movement", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, noMvmtShares); - expect(stock.otlkMag).equal(oldForecast); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(oldForecast); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate a SHORT transaction that doesn't trigger a forecast movement", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, noMvmtShares); - expect(stock.otlkMag).equal(oldForecast); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(oldForecast); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate LONG transactions that triggers forecast movements", function () { @@ -636,9 +644,9 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, mvmtShares); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate SHORT transactions that triggers forecast movements", function () { @@ -646,9 +654,9 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, mvmtShares); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate LONG transactions of exactly 'shareTxForMovement' shares", function () { @@ -656,9 +664,9 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate LONG transactions that total to 'shareTxForMovement' shares", function () { @@ -666,11 +674,11 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, Math.round(stock.shareTxForMovement / 2)); - expect(stock.shareTxUntilMovement).lessThan(stock.shareTxForMovement); + expect(stock.shareTxUntilMovement).toBeLessThan(stock.shareTxForMovement); processTransactionForecastMovement(stock, stock.shareTxUntilMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate LONG transactions that are a multiple of 'shareTxForMovement' shares", function () { @@ -678,9 +686,9 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, 3 * stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate SHORT transactions of exactly 'shareTxForMovement' shares", function () { @@ -688,9 +696,9 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate SHORT transactions that total to 'shareTxForMovement' shares", function () { @@ -698,11 +706,11 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, Math.round(stock.shareTxForMovement / 2)); - expect(stock.shareTxUntilMovement).lessThan(stock.shareTxForMovement); + expect(stock.shareTxUntilMovement).toBeLessThan(stock.shareTxForMovement); processTransactionForecastMovement(stock, stock.shareTxUntilMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate SHORT transactions that are a multiple of 'shareTxForMovement' shares", function () { @@ -710,9 +718,9 @@ describe("Stock Market Tests", function () { const oldForecastForecast = stock.otlkMagForecast; processTransactionForecastMovement(stock, 3 * stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.otlkMagForecast).equal(getNthForecastForecast(oldForecastForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.otlkMagForecast).toEqual(getNthForecastForecast(oldForecastForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); }); @@ -724,101 +732,101 @@ describe("Stock Market Tests", function () { const oldTracker = stock.shareTxUntilMovement; processTransactionForecastMovement({} as Stock, mvmtShares); - expect(stock.shareTxUntilMovement).equal(oldTracker); + expect(stock.shareTxUntilMovement).toEqual(oldTracker); }); it("should do nothing on invalid 'shares' arg", function () { const oldTracker = stock.shareTxUntilMovement; processTransactionForecastMovement(stock, NaN); - expect(stock.shareTxUntilMovement).equal(oldTracker); + expect(stock.shareTxUntilMovement).toEqual(oldTracker); processTransactionForecastMovement(stock, -1); - expect(stock.shareTxUntilMovement).equal(oldTracker); + expect(stock.shareTxUntilMovement).toEqual(oldTracker); }); it("should properly evaluate a LONG transaction that doesn't trigger a price movement", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, noMvmtShares); - expect(stock.otlkMag).equal(oldForecast); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(oldForecast); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate a SHORT transaction that doesn't trigger a price movement", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, noMvmtShares); - expect(stock.otlkMag).equal(oldForecast); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(oldForecast); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate LONG transactions that trigger price movements", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, mvmtShares); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate SHORT transactions that trigger price movements", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, mvmtShares); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement - noMvmtShares); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement - noMvmtShares); }); it("should properly evaluate LONG transactions of exactly 'shareTxForMovement' shares", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate LONG transactions that total to 'shareTxForMovement' shares", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, Math.round(stock.shareTxForMovement / 2)); - expect(stock.shareTxUntilMovement).lessThan(stock.shareTxForMovement); + expect(stock.shareTxUntilMovement).toBeLessThan(stock.shareTxForMovement); processTransactionForecastMovement(stock, stock.shareTxUntilMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate LONG transactions that are a multiple of 'shareTxForMovement' shares", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, 3 * stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate SHORT transactions of exactly 'shareTxForMovement' shares", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate SHORT transactions that total to 'shareTxForMovement' shares", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, Math.round(stock.shareTxForMovement / 2)); - expect(stock.shareTxUntilMovement).lessThan(stock.shareTxForMovement); + expect(stock.shareTxUntilMovement).toBeLessThan(stock.shareTxForMovement); processTransactionForecastMovement(stock, stock.shareTxUntilMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 2)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 2)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); it("should properly evaluate SHORT transactions that are a multiple of 'shareTxForMovement' shares", function () { const oldForecast = stock.otlkMag; processTransactionForecastMovement(stock, 3 * stock.shareTxForMovement); - expect(stock.otlkMag).equal(getNthForecast(oldForecast, 4)); - expect(stock.shareTxUntilMovement).equal(stock.shareTxForMovement); + expect(stock.otlkMag).toEqual(getNthForecast(oldForecast, 4)); + expect(stock.shareTxUntilMovement).toEqual(stock.shareTxForMovement); }); }); }); @@ -828,20 +836,20 @@ describe("Stock Market Tests", function () { describe("buyStock()", function () { it("should fail for invalid arguments", function () { - expect(buyStock({} as Stock, 1, null, suppressDialogOpt)).equal(false); - expect(buyStock(stock, 0, null, suppressDialogOpt)).equal(false); - expect(buyStock(stock, -1, null, suppressDialogOpt)).equal(false); - expect(buyStock(stock, NaN, null, suppressDialogOpt)).equal(false); + expect(buyStock({} as Stock, 1, null, suppressDialogOpt)).toEqual(false); + expect(buyStock(stock, 0, null, suppressDialogOpt)).toEqual(false); + expect(buyStock(stock, -1, null, suppressDialogOpt)).toEqual(false); + expect(buyStock(stock, NaN, null, suppressDialogOpt)).toEqual(false); }); it("should fail if player doesn't have enough money", function () { Player.setMoney(0); - expect(buyStock(stock, 1, null, suppressDialogOpt)).equal(false); + expect(buyStock(stock, 1, null, suppressDialogOpt)).toEqual(false); }); it("should not allow for transactions that exceed the maximum shares", function () { const maxShares = stock.maxShares; - expect(buyStock(stock, maxShares + 1, null, suppressDialogOpt)).equal(false); + expect(buyStock(stock, maxShares + 1, null, suppressDialogOpt)).toEqual(false); }); it("should return true and properly update stock properties for successful transactions", function () { @@ -853,29 +861,29 @@ describe("Stock Market Tests", function () { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion Player.setMoney(cost!); - expect(buyStock(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShares).equal(shares); - expect(stock.playerAvgPx).greaterThan(0); - expect(Player.money).equal(0); + expect(buyStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(shares); + expect(stock.playerAvgPx).toBeGreaterThan(0); + expect(Player.money).toEqual(0); }); }); describe("sellStock()", function () { it("should fail for invalid arguments", function () { - expect(sellStock({} as Stock, 1, null, suppressDialogOpt)).equal(false); - expect(sellStock(stock, 0, null, suppressDialogOpt)).equal(false); - expect(sellStock(stock, -1, null, suppressDialogOpt)).equal(false); - expect(sellStock(stock, NaN, null, suppressDialogOpt)).equal(false); + expect(sellStock({} as Stock, 1, null, suppressDialogOpt)).toEqual(false); + expect(sellStock(stock, 0, null, suppressDialogOpt)).toEqual(false); + expect(sellStock(stock, -1, null, suppressDialogOpt)).toEqual(false); + expect(sellStock(stock, NaN, null, suppressDialogOpt)).toEqual(false); }); it("should fail if player doesn't have any shares", function () { Player.setMoney(0); - expect(sellStock(stock, 1, null, suppressDialogOpt)).equal(false); + expect(sellStock(stock, 1, null, suppressDialogOpt)).toEqual(false); }); it("should not allow for transactions that exceed the maximum shares", function () { const maxShares = stock.maxShares; - expect(sellStock(stock, maxShares + 1, null, suppressDialogOpt)).equal(false); + expect(sellStock(stock, maxShares + 1, null, suppressDialogOpt)).toEqual(false); }); it("should return true and properly update stock properties for successful transactions", function () { @@ -885,10 +893,10 @@ describe("Stock Market Tests", function () { const gain = getSellTransactionGain(stock, shares, PositionTypes.Long); Player.setMoney(0); - expect(sellStock(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShares).equal(0); - expect(stock.playerAvgPx).equal(0); - expect(Player.money).equal(gain); + expect(sellStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(0); + expect(stock.playerAvgPx).toEqual(0); + expect(Player.money).toEqual(gain); }); it("should cap the number of sharse sold to however many the player owns", function () { @@ -899,10 +907,10 @@ describe("Stock Market Tests", function () { const gain = getSellTransactionGain(stock, actualShares, PositionTypes.Long); Player.setMoney(0); - expect(sellStock(stock, attemptedShares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShares).equal(0); - expect(stock.playerAvgPx).equal(0); - expect(Player.money).equal(gain); + expect(sellStock(stock, attemptedShares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(0); + expect(stock.playerAvgPx).toEqual(0); + expect(Player.money).toEqual(gain); }); it("should properly update stock properties for partial transactions", function () { @@ -913,29 +921,29 @@ describe("Stock Market Tests", function () { const gain = getSellTransactionGain(stock, shares, PositionTypes.Long); Player.setMoney(0); - expect(sellStock(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShares).equal(shares); - expect(stock.playerAvgPx).equal(origPrice); - expect(Player.money).equal(gain); + expect(sellStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(shares); + expect(stock.playerAvgPx).toEqual(origPrice); + expect(Player.money).toEqual(gain); }); }); describe("shortStock()", function () { it("should fail for invalid arguments", function () { - expect(shortStock({} as Stock, 1, null, suppressDialogOpt)).equal(false); - expect(shortStock(stock, 0, null, suppressDialogOpt)).equal(false); - expect(shortStock(stock, -1, null, suppressDialogOpt)).equal(false); - expect(shortStock(stock, NaN, null, suppressDialogOpt)).equal(false); + expect(shortStock({} as Stock, 1, null, suppressDialogOpt)).toEqual(false); + expect(shortStock(stock, 0, null, suppressDialogOpt)).toEqual(false); + expect(shortStock(stock, -1, null, suppressDialogOpt)).toEqual(false); + expect(shortStock(stock, NaN, null, suppressDialogOpt)).toEqual(false); }); it("should fail if player doesn't have enough money", function () { Player.setMoney(0); - expect(shortStock(stock, 1, null, suppressDialogOpt)).equal(false); + expect(shortStock(stock, 1, null, suppressDialogOpt)).toEqual(false); }); it("should not allow for transactions that exceed the maximum shares", function () { const maxShares = stock.maxShares; - expect(shortStock(stock, maxShares + 1, null, suppressDialogOpt)).equal(false); + expect(shortStock(stock, maxShares + 1, null, suppressDialogOpt)).toEqual(false); }); it("should return true and properly update stock properties for successful transactions", function () { @@ -947,29 +955,29 @@ describe("Stock Market Tests", function () { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion Player.setMoney(cost!); - expect(shortStock(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShortShares).equal(shares); - expect(stock.playerAvgShortPx).greaterThan(0); - expect(Player.money).equal(0); + expect(shortStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(shares); + expect(stock.playerAvgShortPx).toBeGreaterThan(0); + expect(Player.money).toEqual(0); }); }); describe("sellShort()", function () { it("should fail for invalid arguments", function () { - expect(sellShort({} as Stock, 1, null, suppressDialogOpt)).equal(false); - expect(sellShort(stock, 0, null, suppressDialogOpt)).equal(false); - expect(sellShort(stock, -1, null, suppressDialogOpt)).equal(false); - expect(sellShort(stock, NaN, null, suppressDialogOpt)).equal(false); + expect(sellShort({} as Stock, 1, null, suppressDialogOpt)).toEqual(false); + expect(sellShort(stock, 0, null, suppressDialogOpt)).toEqual(false); + expect(sellShort(stock, -1, null, suppressDialogOpt)).toEqual(false); + expect(sellShort(stock, NaN, null, suppressDialogOpt)).toEqual(false); }); it("should fail if player doesn't have any shares", function () { Player.setMoney(0); - expect(sellShort(stock, 1, null, suppressDialogOpt)).equal(false); + expect(sellShort(stock, 1, null, suppressDialogOpt)).toEqual(false); }); it("should not allow for transactions that exceed the maximum shares", function () { const maxShares = stock.maxShares; - expect(sellShort(stock, maxShares + 1, null, suppressDialogOpt)).equal(false); + expect(sellShort(stock, maxShares + 1, null, suppressDialogOpt)).toEqual(false); }); it("should return true and properly update stock properties for successful transactions", function () { @@ -979,10 +987,10 @@ describe("Stock Market Tests", function () { const gain = getSellTransactionGain(stock, shares, PositionTypes.Short); Player.setMoney(0); - expect(sellShort(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShortShares).equal(0); - expect(stock.playerAvgShortPx).equal(0); - expect(Player.money).equal(gain); + expect(sellShort(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(0); + expect(stock.playerAvgShortPx).toEqual(0); + expect(Player.money).toEqual(gain); }); it("should cap the number of sharse sold to however many the player owns", function () { @@ -993,10 +1001,10 @@ describe("Stock Market Tests", function () { const gain = getSellTransactionGain(stock, actualShares, PositionTypes.Short); Player.setMoney(0); - expect(sellShort(stock, attemptedShares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShortShares).equal(0); - expect(stock.playerAvgShortPx).equal(0); - expect(Player.money).equal(gain); + expect(sellShort(stock, attemptedShares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(0); + expect(stock.playerAvgShortPx).toEqual(0); + expect(Player.money).toEqual(gain); }); it("should properly update stock properties for partial transactions", function () { @@ -1007,10 +1015,10 @@ describe("Stock Market Tests", function () { const gain = getSellTransactionGain(stock, shares, PositionTypes.Short); Player.setMoney(0); - expect(sellShort(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShortShares).equal(shares); - expect(stock.playerAvgShortPx).equal(origPrice); - expect(Player.money).equal(gain); + expect(sellShort(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(shares); + expect(stock.playerAvgShortPx).toEqual(origPrice); + expect(Player.money).toEqual(gain); }); }); }); @@ -1033,18 +1041,18 @@ describe("Stock Market Tests", function () { return new Order("FOO", NaN, 0, OrderTypes.LimitBuy, PositionTypes.Short); } - expect(invalid1).throw(); - expect(invalid2).throw(); - expect(invalid3).throw(); - expect(invalid4).throw(); - expect(invalid5).throw(); + expect(invalid1).toThrow(); + expect(invalid2).toThrow(); + expect(invalid3).toThrow(); + expect(invalid4).toThrow(); + expect(invalid5).toThrow(); }); }); describe("Order Placing & Processing", function () { beforeEach(function () { - expect(initStockMarket).not.throw(); - expect(initSymbolToStockMap).not.throw(); + expect(initStockMarket).not.toThrow(); + expect(initSymbolToStockMap).not.toThrow(); // Create an order book for our mock stock StockMarket["Orders"][stock.symbol] = []; @@ -1056,25 +1064,25 @@ describe("Stock Market Tests", function () { const invalid2 = placeOrder(stock, "foo" as any as number, 2, OrderTypes.LimitBuy, PositionTypes.Long); const invalid3 = placeOrder(stock, 1, "foo" as any as number, OrderTypes.LimitBuy, PositionTypes.Long); - expect(invalid1).equal(false); - expect(invalid2).equal(false); - expect(invalid3).equal(false); + expect(invalid1).toEqual(false); + expect(invalid2).toEqual(false); + expect(invalid3).toEqual(false); - expect(StockMarket["Orders"][stock.symbol]).equal([]); + expect(StockMarket["Orders"][stock.symbol]).toEqual([]); }); it("should return true and update the order book for valid arguments", function () { const res = placeOrder(stock, 1e3, 9e3, OrderTypes.LimitBuy, PositionTypes.Long); - expect(res).equal(true); + expect(res).toEqual(true); - expect(StockMarket["Orders"][stock.symbol]).length(1); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(1); const order = StockMarket["Orders"][stock.symbol][0]; - expect(order).instanceOf(Order); - expect(order.stockSymbol).equal(ctorParams.symbol); - expect(order.shares).equal(1e3); - expect(order.price).equal(9e3); - expect(order.type).equal(OrderTypes.LimitBuy); - expect(order.pos).equal(PositionTypes.Long); + expect(order).toBeInstanceOf(Order); + expect(order.stockSymbol).toEqual(ctorParams.symbol); + expect(order.shares).toEqual(1e3); + expect(order.price).toEqual(9e3); + expect(order.type).toEqual(OrderTypes.LimitBuy); + expect(order.pos).toEqual(PositionTypes.Long); }); }); @@ -1083,15 +1091,15 @@ describe("Stock Market Tests", function () { StockMarket["Orders"][stock.symbol] = []; const res = placeOrder(stock, 1e3, 9e3, OrderTypes.LimitBuy, PositionTypes.Long); - expect(res).equal(true); - expect(StockMarket["Orders"][stock.symbol]).length(1); + expect(res).toEqual(true); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(1); }); it("returns true & removes an Order from the order book", function () { const order = StockMarket["Orders"][stock.symbol][0]; const res = cancelOrder({ order }); - expect(res).equal(true); - expect(StockMarket["Orders"][stock.symbol]).length(0); + expect(res).toEqual(true); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(0); }); it("should also work when passing in order parameters separately", function () { @@ -1102,16 +1110,16 @@ describe("Stock Market Tests", function () { type: OrderTypes.LimitBuy, pos: PositionTypes.Long, }); - expect(res).equal(true); - expect(StockMarket["Orders"][stock.symbol]).length(0); + expect(res).toEqual(true); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(0); }); it("should return false and do nothing when the specified order doesn't exist", function () { // Same parameters, but its a different object const order = new Order(stock.symbol, 1e3, 9e3, OrderTypes.LimitBuy, PositionTypes.Long); const res = cancelOrder({ order }); - expect(res).equal(false); - expect(StockMarket["Orders"][stock.symbol]).length(1); + expect(res).toEqual(false); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(1); const res2 = cancelOrder({ stock, @@ -1120,8 +1128,8 @@ describe("Stock Market Tests", function () { type: OrderTypes.LimitBuy, pos: PositionTypes.Long, }); - expect(res2).equal(false); - expect(StockMarket["Orders"][stock.symbol]).length(1); + expect(res2).toEqual(false); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(1); }); }); @@ -1129,8 +1137,8 @@ describe("Stock Market Tests", function () { let processOrdersRefs: IProcessOrderRefs; beforeEach(function () { - expect(initStockMarket).not.throw(); - expect(initSymbolToStockMap).not.throw(); + expect(initStockMarket).not.toThrow(); + expect(initSymbolToStockMap).not.toThrow(); StockMarket[stock.name] = stock; SymbolToStockMap[stock.symbol] = stock; @@ -1148,13 +1156,13 @@ describe("Stock Market Tests", function () { function checkThatOrderExists(placeOrderRes?: boolean): void { if (typeof placeOrderRes === "boolean") { - expect(placeOrderRes).equal(true); + expect(placeOrderRes).toEqual(true); } - expect(StockMarket["Orders"][stock.symbol]).length(1); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(1); } function checkThatOrderExecuted(): void { - expect(StockMarket["Orders"][stock.symbol]).length(0); + expect(StockMarket["Orders"][stock.symbol]).toHaveLength(0); } it("should execute LONG Limit Buy orders when price <= order price", function () { @@ -1164,7 +1172,7 @@ describe("Stock Market Tests", function () { stock.changePrice(9e3); processOrders(stock, OrderTypes.LimitBuy, PositionTypes.Long, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShares).equal(2e3); + expect(stock.playerShares).toEqual(2e3); }); it("should execute SHORT Limit Buy Orders when price >= order price", function () { @@ -1174,7 +1182,7 @@ describe("Stock Market Tests", function () { stock.changePrice(11e3); processOrders(stock, OrderTypes.LimitBuy, PositionTypes.Short, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShortShares).equal(2e3); + expect(stock.playerShortShares).toEqual(2e3); }); it("should execute LONG Limit Sell Orders when price >= order price", function () { @@ -1184,7 +1192,7 @@ describe("Stock Market Tests", function () { stock.changePrice(11e3); processOrders(stock, OrderTypes.LimitSell, PositionTypes.Long, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShares).equal(0); + expect(stock.playerShares).toEqual(0); }); it("should execute SHORT Limit Sell Orders when price <= order price", function () { @@ -1194,7 +1202,7 @@ describe("Stock Market Tests", function () { stock.changePrice(9e3); processOrders(stock, OrderTypes.LimitSell, PositionTypes.Short, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShortShares).equal(0); + expect(stock.playerShortShares).toEqual(0); }); it("should execute LONG Stop Buy Orders when price >= order price", function () { @@ -1204,7 +1212,7 @@ describe("Stock Market Tests", function () { stock.changePrice(11e3); processOrders(stock, OrderTypes.StopBuy, PositionTypes.Long, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShares).equal(2e3); + expect(stock.playerShares).toEqual(2e3); }); it("should execute SHORT Stop Buy Orders when price <= order price", function () { @@ -1214,7 +1222,7 @@ describe("Stock Market Tests", function () { stock.changePrice(9e3); processOrders(stock, OrderTypes.StopBuy, PositionTypes.Short, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShortShares).equal(2e3); + expect(stock.playerShortShares).toEqual(2e3); }); it("should execute LONG Stop Sell Orders when price <= order price", function () { @@ -1224,7 +1232,7 @@ describe("Stock Market Tests", function () { stock.changePrice(9e3); processOrders(stock, OrderTypes.StopSell, PositionTypes.Long, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShares).equal(0); + expect(stock.playerShares).toEqual(0); }); it("should execute SHORT Stop Sell Orders when price >= order price", function () { @@ -1234,13 +1242,13 @@ describe("Stock Market Tests", function () { stock.changePrice(11e3); processOrders(stock, OrderTypes.StopSell, PositionTypes.Short, processOrdersRefs); checkThatOrderExecuted(); - expect(stock.playerShortShares).equal(0); + expect(stock.playerShortShares).toEqual(0); }); it("should execute immediately if their conditions are satisfied", function () { placeOrder(stock, 1e3, 11e3, OrderTypes.LimitBuy, PositionTypes.Long); checkThatOrderExecuted(); - expect(stock.playerShares).equal(2e3); + expect(stock.playerShares).toEqual(2e3); }); }); }); @@ -1263,8 +1271,8 @@ describe("Stock Market Tests", function () { }); beforeEach(function () { - expect(initStockMarket).not.throw(); - expect(initSymbolToStockMap).not.throw(); + expect(initStockMarket).not.toThrow(); + expect(initSymbolToStockMap).not.toThrow(); StockMarket[stock.name] = stock; }); @@ -1273,13 +1281,13 @@ describe("Stock Market Tests", function () { it("should decrease a stock's second-order forecast when all of its money is hacked", function () { const oldSecondOrderForecast = stock.otlkMagForecast; influenceStockThroughServerHack(server, server.moneyMax); - expect(stock.otlkMagForecast).equal(oldSecondOrderForecast - forecastForecastChangeFromHack); + expect(stock.otlkMagForecast).toEqual(oldSecondOrderForecast - forecastForecastChangeFromHack); }); it("should not decrease the stock's second-order forecast when no money is stolen", function () { const oldSecondOrderForecast = stock.otlkMagForecast; influenceStockThroughServerHack(server, 0); - expect(stock.otlkMagForecast).equal(oldSecondOrderForecast); + expect(stock.otlkMagForecast).toEqual(oldSecondOrderForecast); }); }); @@ -1287,13 +1295,13 @@ describe("Stock Market Tests", function () { it("should increase a stock's second-order forecast when all of its money is grown", function () { const oldSecondOrderForecast = stock.otlkMagForecast; influenceStockThroughServerGrow(server, server.moneyMax); - expect(stock.otlkMagForecast).equal(oldSecondOrderForecast + forecastForecastChangeFromHack); + expect(stock.otlkMagForecast).toEqual(oldSecondOrderForecast + forecastForecastChangeFromHack); }); it("should not increase the stock's second-order forecast when no money is grown", function () { const oldSecondOrderForecast = stock.otlkMagForecast; influenceStockThroughServerGrow(server, 0); - expect(stock.otlkMagForecast).equal(oldSecondOrderForecast); + expect(stock.otlkMagForecast).toEqual(oldSecondOrderForecast); }); }); @@ -1304,7 +1312,7 @@ describe("Stock Market Tests", function () { // Use 1e3 for numCycles to force a change // (This may break later if numbers are rebalanced); influenceStockThroughCompanyWork(company, 1, 500); - expect(stock.otlkMagForecast).equal(oldSecondOrderForecast + forecastForecastChangeFromCompanyWork); + expect(stock.otlkMagForecast).toEqual(oldSecondOrderForecast + forecastForecastChangeFromCompanyWork); }); it("should be affected by performanceMult", function () { @@ -1313,7 +1321,7 @@ describe("Stock Market Tests", function () { // Use 1e3 for numCycles to force a change // (This may break later if numbers are rebalanced); influenceStockThroughCompanyWork(company, 4, 1e3); - expect(stock.otlkMagForecast).equal(oldSecondOrderForecast + 4 * forecastForecastChangeFromCompanyWork); + expect(stock.otlkMagForecast).toEqual(oldSecondOrderForecast + 4 * forecastForecastChangeFromCompanyWork); }); }); }); diff --git a/test/StringHelperFunctions.test.ts b/test/StringHelperFunctions.test.ts index 96400bc75..3e6267163 100644 --- a/test/StringHelperFunctions.test.ts +++ b/test/StringHelperFunctions.test.ts @@ -2,18 +2,18 @@ import { convertTimeMsToTimeElapsedString } from "../src/utils/StringHelperFunct describe("StringHelperFunctions Tests", function () { it("transforms strings", () => { - expect(convertTimeMsToTimeElapsedString(1000)).equal("1 seconds"); - expect(convertTimeMsToTimeElapsedString(5 * 60 * 1000 + 34 * 1000)).equal("5 minutes 34 seconds"); - expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000)).equal( + expect(convertTimeMsToTimeElapsedString(1000)).toEqual("1 seconds"); + expect(convertTimeMsToTimeElapsedString(5 * 60 * 1000 + 34 * 1000)).toEqual("5 minutes 34 seconds"); + expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000)).toEqual( "2 days 5 minutes 34 seconds", ); - expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000, true)).equal( + expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000, true)).toEqual( "2 days 5 minutes 34.000 seconds", ); - expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123, true)).equal( + 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)).equal( + expect(convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123.888, true)).toEqual( "2 days 5 minutes 34.123 seconds", ); }); diff --git a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts index 070a66722..5fdc8bc12 100644 --- a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts +++ b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-await-in-loop */ import { Player } from "../../src/Player"; import { determineAllPossibilitiesForTabCompletion } from "../../src/Terminal/determineAllPossibilitiesForTabCompletion"; import { Server } from "../../src/Server/Server"; @@ -5,6 +6,10 @@ import { AddToAllServers, prestigeAllServers } from "../../src/Server/AllServers import { LocationName } from "../../src/Locations/data/LocationNames"; import { CodingContract } from "../../src/CodingContracts"; +jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', { + virtual: true, +}); + describe("determineAllPossibilitiesForTabCompletion", function () { let closeServer: Server; let farServer: Server; @@ -41,14 +46,14 @@ describe("determineAllPossibilitiesForTabCompletion", function () { AddToAllServers(farServer); }); - it("completes the connect command", () => { - const options = determineAllPossibilitiesForTabCompletion(Player, "connect ", 0); - expect(options).equal(["8.8.8.8", "near"]); + it("completes the connect command", async () => { + const options = await determineAllPossibilitiesForTabCompletion(Player, "connect ", 0); + expect(options).toEqual(["near"]); }); - it("completes the buy command", () => { - const options = determineAllPossibilitiesForTabCompletion(Player, "buy ", 0); - expect(options).equal([ + it("completes the buy command", async () => { + const options = await determineAllPossibilitiesForTabCompletion(Player, "buy ", 0); + expect(options.sort()).toEqual([ "BruteSSH.exe", "FTPCrack.exe", "relaySMTP.exe", @@ -58,45 +63,48 @@ describe("determineAllPossibilitiesForTabCompletion", function () { "DeepscanV2.exe", "AutoLink.exe", "ServerProfiler.exe", - ]); + "Formulas.exe", + ].sort()); }); - it("completes the scp command", () => { + it("completes the scp command", async () => { Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); Player.getHomeComputer().messages.push("af.lit"); Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); - const options1 = determineAllPossibilitiesForTabCompletion(Player, "scp ", 0); - expect(options1).equal(["/www/script.js", "af.lit", "note.txt", "www/"]); + const options1 = await determineAllPossibilitiesForTabCompletion(Player, "scp ", 0); + expect(options1).toEqual(["/www/script.js", "af.lit", "note.txt", "www/"]); - const options2 = determineAllPossibilitiesForTabCompletion(Player, "scp note.txt ", 1); - expect(options2).equal([Player.getHomeComputer().ip, "home", "8.8.8.8", "near", "4.4.4.4", "far"]); + const options2 = await determineAllPossibilitiesForTabCompletion(Player, "scp note.txt ", 1); + expect(options2).toEqual(["home", "near", "far"]); }); - it("completes the kill, tail, mem, and check commands", () => { + it("completes the kill, tail, mem, and check commands", async () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); for (const command of ["kill", "tail", "mem", "check"]) { - expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal(["/www/script.js", "www/"]); + const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0); + expect(options).toEqual(["/www/script.js", "www/"]); } }); - it("completes the nano commands", () => { + it("completes the nano commands", async () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); - expect(determineAllPossibilitiesForTabCompletion(Player, "nano ", 0)).equal([ + const options = await determineAllPossibilitiesForTabCompletion(Player, "nano ", 0); + expect(options).toEqual([ "/www/script.js", "note.txt", - ".fconf", "www/", ]); }); - it("completes the rm command", () => { + it("completes the rm command", async () => { Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); Player.getHomeComputer().messages.push("asl.msg"); Player.getHomeComputer().messages.push("af.lit"); - expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).equal([ + const options = await determineAllPossibilitiesForTabCompletion(Player, "rm ", 0); + expect(options).toEqual([ "/www/script.js", "NUKE.exe", "af.lit", @@ -106,10 +114,11 @@ describe("determineAllPossibilitiesForTabCompletion", function () { ]); }); - it("completes the run command", () => { + it("completes the run command", async () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); - expect(determineAllPossibilitiesForTabCompletion(Player, "run ", 0)).equal([ + const options = await determineAllPossibilitiesForTabCompletion(Player, "run ", 0); + expect(options).toEqual([ "/www/script.js", "NUKE.exe", "linklist.cct", @@ -117,11 +126,12 @@ describe("determineAllPossibilitiesForTabCompletion", function () { ]); }); - it("completes the cat command", () => { + it("completes the cat command", async () => { Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark"); Player.getHomeComputer().messages.push("asl.msg"); Player.getHomeComputer().messages.push("af.lit"); - expect(determineAllPossibilitiesForTabCompletion(Player, "cat ", 0)).equal([ + const options = await determineAllPossibilitiesForTabCompletion(Player, "cat ", 0); + expect(options).toEqual([ "asl.msg", "af.lit", "/www/note.txt", @@ -129,11 +139,13 @@ describe("determineAllPossibilitiesForTabCompletion", function () { ]); }); - it("completes the download and mv commands", () => { + it("completes the download and mv commands", async () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); for (const command of ["download", "mv"]) { - expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal([ + + const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0); + expect(options).toEqual([ "/www/script.js", "note.txt", "www/", @@ -141,21 +153,24 @@ describe("determineAllPossibilitiesForTabCompletion", function () { } }); - it("completes the cd command", () => { + it("completes the cd command", async () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); - expect(determineAllPossibilitiesForTabCompletion(Player, "cd ", 0)).equal(["www/"]); + const options = await determineAllPossibilitiesForTabCompletion(Player, "cd ", 0); + expect(options).toEqual(["www/"]); }); - it("completes the ls and cd commands", () => { + it("completes the ls and cd commands", async () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); for (const command of ["ls", "cd"]) { - expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal(["www/"]); + const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0); + expect(options).toEqual(["www/"]); } }); - it("completes commands starting with ./", () => { + it("completes commands starting with ./", async () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); - expect(determineAllPossibilitiesForTabCompletion(Player, "run ./", 0)).equal([ + const options = await determineAllPossibilitiesForTabCompletion(Player, "run ./", 0); + expect(options).toEqual([ ".//www/script.js", "NUKE.exe", "./www/", From 92e8b42d182e58472c55bc4248e1a8d71affc21c Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Sun, 19 Dec 2021 12:10:06 -0500 Subject: [PATCH 2/5] Fix renamed functions from 1.0 release in tests --- jest.config.js | 4 +- test/Netscript/DynamicRamCalculation.test.js | 105 +++++++++--------- test/Netscript/StaticRamCalculation.test.js | 110 +++++++++---------- 3 files changed, 111 insertions(+), 108 deletions(-) diff --git a/jest.config.js b/jest.config.js index 4fb0d1462..2be488205 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,6 +4,8 @@ module.exports = { transform: { "^.+\\.(js|jsx|ts|tsx)$": "babel-jest", }, - // testMatch: ["**/?(*.)+(test).[jt]s?(x)"], + testPathIgnorePatterns: [ + '.cypress', 'node_modules', 'dist', + ], testEnvironment: "jsdom", }; diff --git a/test/Netscript/DynamicRamCalculation.test.js b/test/Netscript/DynamicRamCalculation.test.js index 9632e0895..59f82db3d 100644 --- a/test/Netscript/DynamicRamCalculation.test.js +++ b/test/Netscript/DynamicRamCalculation.test.js @@ -9,6 +9,11 @@ jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', { virtual: true, }); +jest.mock("../../src/Netscript/killWorkerScript", () => ({ + __esModule: true, + killWorkerScript: jest.fn(), +})); + const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost; describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { @@ -158,7 +163,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { runPotentiallyAsyncFunction(curr); } catch (e) {} } else { - throw new Error(`Invalid function specified: [${fndesc}]`); + throw new Error(`Invalid function specified: [${fnDesc}]`); } testEquality(workerScript.dynamicRamUsage, ScriptBaseCost); @@ -192,13 +197,13 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { await testNonzeroDynamicRamCost(f); }); - it("hackAnalyzePercent()", async function () { - const f = ["hackAnalyzePercent"]; + it("hackAnalyze()", async function () { + const f = ["hackAnalyze"]; await testNonzeroDynamicRamCost(f); }); - it("hackChance()", async function () { - const f = ["hackChance"]; + it("hackAnalyzeChance()", async function () { + const f = ["hackAnalyzeChance"]; await testNonzeroDynamicRamCost(f); }); @@ -289,6 +294,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { it("exec()", async function () { const f = ["exec"]; + jest.spyOn(console, 'log').mockImplementation(() => {}); // eslint-disable-line await testNonzeroDynamicRamCost(f); }); @@ -454,32 +460,32 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { it("write()", async function () { const f = ["write"]; - await testNonzeroDynamicRamCost(f); + await testZeroDynamicRamCost(f); }); - it("tryWrite()", async function () { - const f = ["tryWrite"]; - await testNonzeroDynamicRamCost(f); + it("tryWritePort()", async function () { + const f = ["tryWritePort"]; + await testZeroDynamicRamCost(f); }); it("read()", async function () { const f = ["read"]; - await testNonzeroDynamicRamCost(f); + await testZeroDynamicRamCost(f); }); it("peek()", async function () { const f = ["peek"]; - await testNonzeroDynamicRamCost(f); + await testZeroDynamicRamCost(f); }); it("clear()", async function () { const f = ["clear"]; - await testNonzeroDynamicRamCost(f); + await testZeroDynamicRamCost(f); }); it("getPortHandle()", async function () { const f = ["getPortHandle"]; - await testNonzeroDynamicRamCost(f); + await testZeroDynamicRamCost(f); }); it("rm()", async function () { @@ -581,88 +587,88 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { }); describe("TIX API", function () { - it("getStockSymbols()", async function () { - const f = ["getStockSymbols"]; + it("stock.getSymbols()", async function () { + const f = ["stock", "getSymbols"]; await testNonzeroDynamicRamCost(f); }); - it("getStockPrice()", async function () { - const f = ["getStockPrice"]; + it("stock.getPrice()", async function () { + const f = ["stock", "getPrice"]; await testNonzeroDynamicRamCost(f); }); - it("getStockAskPrice()", async function () { - const f = ["getStockAskPrice"]; + it("stock.getBidPrice()", async function () { + const f = ["stock", "getBidPrice"]; await testNonzeroDynamicRamCost(f); }); - it("getStockBidPrice()", async function () { - const f = ["getStockBidPrice"]; + it("stock.getBidPrice()", async function () { + const f = ["stock", "getBidPrice"]; await testNonzeroDynamicRamCost(f); }); - it("getStockPosition()", async function () { - const f = ["getStockPosition"]; + it("stock.getPosition()", async function () { + const f = ["stock", "getPosition"]; await testNonzeroDynamicRamCost(f); }); - it("getStockMaxShares()", async function () { - const f = ["getStockMaxShares"]; + it("stock.getMaxShares()", async function () { + const f = ["stock", "getMaxShares"]; await testNonzeroDynamicRamCost(f); }); - it("buyStock()", async function () { - const f = ["buyStock"]; + it("stock.buy()", async function () { + const f = ["stock", "buy"]; await testNonzeroDynamicRamCost(f); }); - it("sellStock()", async function () { - const f = ["sellStock"]; + it("stock.sell()", async function () { + const f = ["stock", "sell"]; await testNonzeroDynamicRamCost(f); }); - it("shortStock()", async function () { - const f = ["shortStock"]; + it("stock.short()", async function () { + const f = ["stock", "short"]; await testNonzeroDynamicRamCost(f); }); - it("sellShort()", async function () { - const f = ["sellShort"]; + it("stock.sellShort()", async function () { + const f = ["stock", "sellShort"]; await testNonzeroDynamicRamCost(f); }); - it("placeOrder()", async function () { - const f = ["placeOrder"]; + it("stock.placeOrder()", async function () { + const f = ["stock", "placeOrder"]; await testNonzeroDynamicRamCost(f); }); - it("cancelOrder()", async function () { - const f = ["cancelOrder"]; + it("stock.cancelOrder()", async function () { + const f = ["stock", "cancelOrder"]; await testNonzeroDynamicRamCost(f); }); - it("getOrders()", async function () { - const f = ["getOrders"]; + it("stock.getOrders()", async function () { + const f = ["stock", "getOrders"]; await testNonzeroDynamicRamCost(f); }); - it("getStockVolatility()", async function () { - const f = ["getStockVolatility"]; + it("stock.getVolatility()", async function () { + const f = ["stock", "getVolatility"]; await testNonzeroDynamicRamCost(f); }); - it("getStockForecast()", async function () { - const f = ["getStockForecast"]; + it("stock.getForecast()", async function () { + const f = ["stock", "getForecast"]; await testNonzeroDynamicRamCost(f); }); - it("purchase4SMarketData()", async function () { - const f = ["purchase4SMarketData"]; + it("stock.purchase4SMarketData()", async function () { + const f = ["stock", "purchase4SMarketData"]; await testNonzeroDynamicRamCost(f); }); - it("purchase4SMarketDataTixApi()", async function () { - const f = ["purchase4SMarketDataTixApi"]; + it("stock.purchase4SMarketDataTixApi()", async function () { + const f = ["stock", "purchase4SMarketDataTixApi"]; await testNonzeroDynamicRamCost(f); }); }); @@ -975,11 +981,6 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { await testNonzeroDynamicRamCost(f); }); - it("getCityEstimatedCommunities()", async function () { - const f = ["bladeburner", "getCityEstimatedCommunities"]; - await testNonzeroDynamicRamCost(f); - }); - it("getCityChaos()", async function () { const f = ["bladeburner", "getCityChaos"]; await testNonzeroDynamicRamCost(f); diff --git a/test/Netscript/StaticRamCalculation.test.js b/test/Netscript/StaticRamCalculation.test.js index 8cac53ce4..14ec03176 100644 --- a/test/Netscript/StaticRamCalculation.test.js +++ b/test/Netscript/StaticRamCalculation.test.js @@ -4,6 +4,11 @@ import { calculateRamUsage } from "../../src/Script/RamCalculations"; const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost; const HacknetNamespaceCost = RamCostConstants.ScriptHacknetNodesRamCost; +jest.mock("../../src/Netscript/killWorkerScript", () => ({ + __esModule: true, + killWorkerScript: jest.fn(), +})); + describe("Netscript Static RAM Calculation/Generation Tests", function () { // Tests numeric equality, allowing for floating point imprecision function testEquality(val, expected) { @@ -81,13 +86,13 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () { await expectNonZeroRamCost(f); }); - it("hackAnalyzePercent()", async function () { - const f = ["hackAnalyzePercent"]; + it("hackAnalyze()", async function () { + const f = ["hackAnalyze"]; await expectNonZeroRamCost(f); }); - it("hackChance()", async function () { - const f = ["hackChance"]; + it("hackAnalyzeChance()", async function () { + const f = ["hackAnalyzeChance"]; await expectNonZeroRamCost(f); }); @@ -343,32 +348,32 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () { it("write()", async function () { const f = ["write"]; - await expectNonZeroRamCost(f); + await expectZeroRamCost(f); }); - it("tryWrite()", async function () { - const f = ["tryWrite"]; - await expectNonZeroRamCost(f); + it("tryWritePort()", async function () { + const f = ["tryWritePort"]; + await expectZeroRamCost(f); }); it("read()", async function () { const f = ["read"]; - await expectNonZeroRamCost(f); + await expectZeroRamCost(f); }); it("peek()", async function () { const f = ["peek"]; - await expectNonZeroRamCost(f); + await expectZeroRamCost(f); }); it("clear()", async function () { const f = ["clear"]; - await expectNonZeroRamCost(f); + await expectZeroRamCost(f); }); it("getPortHandle()", async function () { const f = ["getPortHandle"]; - await expectNonZeroRamCost(f); + await expectZeroRamCost(f); }); it("rm()", async function () { @@ -508,98 +513,98 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () { }); describe("TIX API", function () { - it("getStockSymbols()", async function () { - const f = ["getStockSymbols"]; + it("stock.getSymbols()", async function () { + const f = ["stock", "getSymbols"]; await expectNonZeroRamCost(f); }); - it("getStockPrice()", async function () { - const f = ["getStockPrice"]; + it("stock.getPrice()", async function () { + const f = ["stock", "getPrice"]; await expectNonZeroRamCost(f); }); - it("getStockAskPrice()", async function () { - const f = ["getStockAskPrice"]; + it("stock.getAskPrice()", async function () { + const f = ["stock", "getAskPrice"]; await expectNonZeroRamCost(f); }); - it("getStockBidPrice()", async function () { - const f = ["getStockBidPrice"]; + it("stock.getBidPrice()", async function () { + const f = ["stock", "getBidPrice"]; await expectNonZeroRamCost(f); }); - it("getStockPosition()", async function () { - const f = ["getStockPosition"]; + it("stock.getPosition()", async function () { + const f = ["stock", "getPosition"]; await expectNonZeroRamCost(f); }); - it("getStockMaxShares()", async function () { - const f = ["getStockMaxShares"]; + it("stock.getMaxShares()", async function () { + const f = ["stock", "getMaxShares"]; await expectNonZeroRamCost(f); }); - it("getStockPurchaseCost()", async function () { - const f = ["getStockPurchaseCost"]; + it("stock.getPurchaseCost()", async function () { + const f = ["stock", "getPurchaseCost"]; await expectNonZeroRamCost(f); }); - it("getStockSaleGain()", async function () { - const f = ["getStockSaleGain"]; + it("stock.getSaleGain()", async function () { + const f = ["stock", "getSaleGain"]; await expectNonZeroRamCost(f); }); - it("buyStock()", async function () { - const f = ["buyStock"]; + it("stock.buy()", async function () { + const f = ["stock", "buy"]; await expectNonZeroRamCost(f); }); - it("sellStock()", async function () { - const f = ["sellStock"]; + it("stock.sell()", async function () { + const f = ["stock", "sell"]; await expectNonZeroRamCost(f); }); - it("shortStock()", async function () { - const f = ["shortStock"]; + it("stock.short()", async function () { + const f = ["stock", "short"]; await expectNonZeroRamCost(f); }); - it("sellShort()", async function () { - const f = ["sellShort"]; + it("stock.sellShort()", async function () { + const f = ["stock", "sell"]; await expectNonZeroRamCost(f); }); - it("placeOrder()", async function () { - const f = ["placeOrder"]; + it("stock.placeOrder()", async function () { + const f = ["stock", "placeOrder"]; await expectNonZeroRamCost(f); }); - it("cancelOrder()", async function () { - const f = ["cancelOrder"]; + it("stock.cancelOrder()", async function () { + const f = ["stock", "cancelOrder"]; await expectNonZeroRamCost(f); }); - it("getOrders()", async function () { - const f = ["getOrders"]; + it("stock.getOrders()", async function () { + const f = ["stock", "getOrders"]; await expectNonZeroRamCost(f); }); - it("getStockVolatility()", async function () { - const f = ["getStockVolatility"]; + it("stock.getVolatility()", async function () { + const f = ["stock", "getVolatility"]; await expectNonZeroRamCost(f); }); - it("getStockForecast()", async function () { - const f = ["getStockForecast"]; + it("stock.getForecast()", async function () { + const f = ["stock", "getForecast"]; await expectNonZeroRamCost(f); }); - it("purchase4SMarketData()", async function () { - const f = ["purchase4SMarketData"]; + it("stock.purchase4SMarketData()", async function () { + const f = ["stock", "purchase4SMarketData"]; await expectNonZeroRamCost(f); }); - it("purchase4SMarketDataTixApi()", async function () { - const f = ["purchase4SMarketDataTixApi"]; + it("stock.purchase4SMarketDataTixApi()", async function () { + const f = ["stock", "purchase4SMarketDataTixApi"]; await expectNonZeroRamCost(f); }); }); @@ -912,11 +917,6 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () { await expectNonZeroRamCost(f); }); - it("getCityEstimatedCommunities()", async function () { - const f = ["bladeburner", "getCityEstimatedCommunities"]; - await expectNonZeroRamCost(f); - }); - it("getCityChaos()", async function () { const f = ["bladeburner", "getCityChaos"]; await expectNonZeroRamCost(f); From 3b99da8474e3cf5838d021c9b89c01bad41878b8 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Sun, 19 Dec 2021 13:04:34 -0500 Subject: [PATCH 3/5] Lint current problems & fix ignore paths --- .eslintignore | 22 ++++++++++++++++--- electron/main.js | 4 +++- src/Electron.tsx | 1 + src/NetscriptFunctions/toNative.ts | 1 + .../Player/PlayerObjectGeneralMethods.tsx | 2 +- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 4 ++-- src/Server/BaseServer.ts | 1 + src/Terminal/DirectoryHelpers.ts | 4 ++-- src/Terminal/commands/download.ts | 2 +- 9 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.eslintignore b/.eslintignore index 63c1d3054..0ef022e71 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,23 @@ node_modules/ -doc/build/ dist/ -tests/*.bundle.* +input/ + +assets/ +css/ +.cypress/ +cypress/ +doc/ +markdown/ +netscript_tests/ +scripts/ + +electron/lib +electron/greenworks.js src/ThirdParty/* src/JSInterpreter.js -main.bundle.js \ No newline at end of file + +test/*.bundle.* +editor.main.js +main.bundle.js +webpack.config.js +webpack.config-test.js diff --git a/electron/main.js b/electron/main.js index 2887fba23..b26321d97 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,4 +1,5 @@ -const { app, BrowserWindow, Menu, shell } = require("electron"); +/* eslint-disable @typescript-eslint/no-var-requires */ + const { app, BrowserWindow, Menu, shell } = require("electron"); const greenworks = require("./greenworks"); if (greenworks.init()) { @@ -127,6 +128,7 @@ function setStopProcessHandler(app, window, enabled) { const stopProcessHandler = () => { if (process.platform !== "darwin") { app.quit(); + // eslint-disable-next-line no-process-exit process.exit(0); } }; diff --git a/src/Electron.tsx b/src/Electron.tsx index f9714ee54..e08caab07 100644 --- a/src/Electron.tsx +++ b/src/Electron.tsx @@ -32,6 +32,7 @@ function bitNodeFinishedState(): boolean { return Player.bladeburner !== null && Player.bladeburner.blackops.hasOwnProperty("Operation Daedalus"); } +// eslint-disable-next-line @typescript-eslint/no-unused-vars function sfAchievement(): Achievement[] { const achs: Achievement[] = []; for (let i = 0; i <= 11; i++) { diff --git a/src/NetscriptFunctions/toNative.ts b/src/NetscriptFunctions/toNative.ts index 1f43fb03c..da365af67 100644 --- a/src/NetscriptFunctions/toNative.ts +++ b/src/NetscriptFunctions/toNative.ts @@ -4,6 +4,7 @@ const defaultInterpreter = new Interpreter("", () => undefined); // the acorn interpreter has a bug where it doesn't convert arrays correctly. // so we have to more or less copy it here. +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function toNative(pseudoObj: any): any { if (pseudoObj == null) return null; if ( diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx index 5d343dfe5..604fe7a16 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx @@ -26,7 +26,7 @@ import { Locations } from "../../Locations/Locations"; import { CityName } from "../../Locations/data/CityNames"; import { LocationName } from "../../Locations/data/LocationNames"; import { Sleeve } from "../../PersonObjects/Sleeve/Sleeve"; -import { calculateSkill as calculateSkillF, calculateSkillProgress as calculateSkillProgressF, getEmptySkillProgress, ISkillProgress } from "../formulas/skill"; +import { calculateSkill as calculateSkillF, calculateSkillProgress as calculateSkillProgressF, ISkillProgress } from "../formulas/skill"; import { calculateIntelligenceBonus } from "../formulas/intelligence"; import { getHackingWorkRepGain, diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 99d7f525a..1fc73aaa1 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -104,8 +104,8 @@ let currentScript = {} as openScript; // Script currently being viewed export function Root(props: IProps): React.ReactElement { const editorRef = useRef(null); const monacoRef = useRef(null); - const [filename, setFilename] = useState(props.filename); - const [code, setCode] = useState(props.code); + const [filename] = useState(props.filename); + const [code] = useState(props.code); const [decorations, setDecorations] = useState([]); const [ram, setRAM] = useState("RAM: ???"); const [updatingRam, setUpdatingRam] = useState(false); diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index c9e71f719..4c28581f4 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -246,6 +246,7 @@ export class BaseServer { this.maxRam = ram; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars updateRamUsed(ram: number, player: IPlayer): void { this.ramUsed = ram; } diff --git a/src/Terminal/DirectoryHelpers.ts b/src/Terminal/DirectoryHelpers.ts index c6d020639..be592ae9b 100644 --- a/src/Terminal/DirectoryHelpers.ts +++ b/src/Terminal/DirectoryHelpers.ts @@ -178,14 +178,14 @@ export function getAllParentDirectories(path: string): string { * @param cwd The current working directory * @returns A file path which may be absolute or relative */ -export function getDestinationFilepath(destination: string, source: string, cwd: string) { +export function getDestinationFilepath(destination: string, source: string, cwd: string): string { const dstDir = evaluateDirectoryPath(destination, cwd); // If evaluating the directory for this destination fails, we have a filename or full path. if (dstDir === null) { return destination; } else { // Append the filename to the directory provided. - let t_path = removeTrailingSlash(dstDir); + const t_path = removeTrailingSlash(dstDir); const fileName = getFileName(source); return t_path + "/" + fileName; } diff --git a/src/Terminal/commands/download.ts b/src/Terminal/commands/download.ts index 83729eef8..fa392d444 100644 --- a/src/Terminal/commands/download.ts +++ b/src/Terminal/commands/download.ts @@ -24,7 +24,7 @@ export function download( const matchEnding = fn.length == 1 || fn === "*.*" ? null : fn.slice(1); // Treat *.* the same as * const zip = new JSZip(); // Helper function to zip any file contents whose name matches the pattern - const zipFiles = (fileNames: string[], fileContents: string[]) => { + const zipFiles = (fileNames: string[], fileContents: string[]): void => { for (let i = 0; i < fileContents.length; ++i) { let name = fileNames[i]; if (name.startsWith("/")) name = name.slice(1); From 2bbb7675757e3eaab12a96d2bc846d53e8130b71 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Sun, 19 Dec 2021 15:42:40 -0500 Subject: [PATCH 4/5] Fix remaining unit test issues --- .eslintignore | 4 ++++ test/Netscript/DynamicRamCalculation.test.js | 13 +++++------ test/Netscript/StaticRamCalculation.test.js | 8 +++---- test/StockMarket.test.ts | 23 +++++++++++-------- test/StringHelperFunctions.test.ts | 2 ++ test/Terminal/Directory.test.js | 2 ++ ...neAllPossibilitiesForTabCompletion.test.ts | 3 +++ 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.eslintignore b/.eslintignore index 0ef022e71..198118748 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,6 +2,10 @@ node_modules/ dist/ input/ +.dist +.tmp +.package + assets/ css/ .cypress/ diff --git a/test/Netscript/DynamicRamCalculation.test.js b/test/Netscript/DynamicRamCalculation.test.js index 59f82db3d..67b16b74b 100644 --- a/test/Netscript/DynamicRamCalculation.test.js +++ b/test/Netscript/DynamicRamCalculation.test.js @@ -1,3 +1,6 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { jest, describe, expect, test } from '@jest/globals' + import { NetscriptFunctions } from "../../src/NetscriptFunctions"; import { getRamCost, RamCostConstants } from "../../src/Netscript/RamCostGenerator"; import { Environment } from "../../src/Netscript/Environment"; @@ -9,11 +12,6 @@ jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', { virtual: true, }); -jest.mock("../../src/Netscript/killWorkerScript", () => ({ - __esModule: true, - killWorkerScript: jest.fn(), -})); - const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost; describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { @@ -115,12 +113,13 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { * @param {string[]} fnDesc - describes the name of the function being tested, * including the namespace(s). e.g. ["gang", "getMemberNames"] */ - async function testZeroDynamicRamCost(fnDesc) { + async function testZeroDynamicRamCost(fnDesc, skipRun = false) { if (!Array.isArray(fnDesc)) { throw new Error("Non-array passed to testZeroDynamicRamCost()"); } const expected = getRamCost(...fnDesc); expect(expected).toEqual(0); + if (skipRun) return; const code = `${fnDesc.join(".")}();`; @@ -315,7 +314,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { it("exit()", async function () { const f = ["exit"]; - await testZeroDynamicRamCost(f); + await testZeroDynamicRamCost(f, true); }); it("scp()", async function () { diff --git a/test/Netscript/StaticRamCalculation.test.js b/test/Netscript/StaticRamCalculation.test.js index 14ec03176..0a976e318 100644 --- a/test/Netscript/StaticRamCalculation.test.js +++ b/test/Netscript/StaticRamCalculation.test.js @@ -1,14 +1,12 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { jest, describe, expect, test } from '@jest/globals' + import { getRamCost, RamCostConstants } from "../../src/Netscript/RamCostGenerator"; import { calculateRamUsage } from "../../src/Script/RamCalculations"; const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost; const HacknetNamespaceCost = RamCostConstants.ScriptHacknetNodesRamCost; -jest.mock("../../src/Netscript/killWorkerScript", () => ({ - __esModule: true, - killWorkerScript: jest.fn(), -})); - describe("Netscript Static RAM Calculation/Generation Tests", function () { // Tests numeric equality, allowing for floating point imprecision function testEquality(val, expected) { diff --git a/test/StockMarket.test.ts b/test/StockMarket.test.ts index 49bceb122..92c2d720f 100644 --- a/test/StockMarket.test.ts +++ b/test/StockMarket.test.ts @@ -1,3 +1,6 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { jest, describe, expect, test } from '@jest/globals' + import { CONSTANTS } from "../src/Constants"; import { Player } from "../src/Player"; import { IMap } from "../src/types"; @@ -132,14 +135,14 @@ describe("Stock Market Tests", function () { const stock = new Stock(params); expect(stock).not.toEqual(null); - expect(stock.price).toBeGreaterThan(params.initPrice.min); - expect(stock.price).toBeLessThan(params.initPrice.max); - expect(stock.mv).toBeGreaterThan(params.mv.min / params.mv.divisor); - expect(stock.mv).toBeLessThan(params.mv.max / params.mv.divisor); - expect(stock.spreadPerc).toBeGreaterThan(params.spreadPerc.min / params.spreadPerc.divisor); - expect(stock.spreadPerc).toBeLessThan(params.spreadPerc.max / params.spreadPerc.divisor); - expect(stock.shareTxForMovement).toBeGreaterThan(params.shareTxForMovement.min); - expect(stock.shareTxForMovement).toBeLessThan(params.shareTxForMovement.max); + expect(stock.price).toBeGreaterThanOrEqual(params.initPrice.min); + expect(stock.price).toBeLessThanOrEqual(params.initPrice.max); + expect(stock.mv).toBeGreaterThanOrEqual(params.mv.min / params.mv.divisor); + expect(stock.mv).toBeLessThanOrEqual(params.mv.max / params.mv.divisor); + expect(stock.spreadPerc).toBeGreaterThanOrEqual(params.spreadPerc.min / params.spreadPerc.divisor); + expect(stock.spreadPerc).toBeLessThanOrEqual(params.spreadPerc.max / params.spreadPerc.divisor); + expect(stock.shareTxForMovement).toBeGreaterThanOrEqual(params.shareTxForMovement.min); + expect(stock.shareTxForMovement).toBeLessThanOrEqual(params.shareTxForMovement.max); }); it("should round the 'totalShare' prop to the nearest 100k", function () { @@ -855,7 +858,7 @@ describe("Stock Market Tests", function () { it("should return true and properly update stock properties for successful transactions", function () { const shares = 1e3; const cost = getBuyTransactionCost(stock, shares, PositionTypes.Long); - expect(cost).not.null; + expect(cost).not.toBeNull(); // Checked above // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -949,7 +952,7 @@ describe("Stock Market Tests", function () { it("should return true and properly update stock properties for successful transactions", function () { const shares = 1e3; const cost = getBuyTransactionCost(stock, shares, PositionTypes.Short); - expect(cost).not.null; + expect(cost).not.toBeNull(); // Checked above // eslint-disable-next-line @typescript-eslint/no-non-null-assertion diff --git a/test/StringHelperFunctions.test.ts b/test/StringHelperFunctions.test.ts index 3e6267163..637963c6a 100644 --- a/test/StringHelperFunctions.test.ts +++ b/test/StringHelperFunctions.test.ts @@ -1,3 +1,5 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { jest, describe, expect, test } from '@jest/globals' import { convertTimeMsToTimeElapsedString } from "../src/utils/StringHelperFunctions"; describe("StringHelperFunctions Tests", function () { diff --git a/test/Terminal/Directory.test.js b/test/Terminal/Directory.test.js index df5333dfc..a054be567 100644 --- a/test/Terminal/Directory.test.js +++ b/test/Terminal/Directory.test.js @@ -1,3 +1,5 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { jest, describe, expect, test } from '@jest/globals' import * as dirHelpers from "../../src/Terminal/DirectoryHelpers"; describe("Terminal Directory Tests", function () { diff --git a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts index 5fdc8bc12..ab2a370ee 100644 --- a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts +++ b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts @@ -1,4 +1,7 @@ /* eslint-disable no-await-in-loop */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { jest, describe, expect, test } from '@jest/globals' + import { Player } from "../../src/Player"; import { determineAllPossibilitiesForTabCompletion } from "../../src/Terminal/determineAllPossibilitiesForTabCompletion"; import { Server } from "../../src/Server/Server"; From 8b355c365ea0a48f9904e369efb2f4c01eb301f8 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Sun, 19 Dec 2021 15:43:13 -0500 Subject: [PATCH 5/5] Add github workflow to run tests, linter & build --- .github/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 53 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..01643cd66 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +# This is a basic workflow to help you get started with Actions +name: CI + +on: + # Triggers the workflow on push or pull request events but only for the dev branch + push: + branches: [ dev ] + pull_request: + branches: [ dev ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.13.1] + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - run: echo "The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - uses: actions/checkout@v2 + - run: echo "The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "The workflow is now ready to test your code on the runner." + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Install npm dependencies + run: npm ci + - name: Run unit tests + run: npm run test + - name: Run linter + run: npm run lint:report + - name: Build the web app + run: npm run build + + # Cannot build the electron app by default using ubuntu + # Wrapper command 'wine64' not found on the system. Consult your Linux distribution's package manager to determine how to install Wine. + # - name: Build the electron app + # run: ./package.sh + + # Unable to properly run the cypress tests for now, they are throwing errors. + # - name: Run the integration tests + # run: npm run cy:test diff --git a/package.json b/package.json index ee42097e9..ab76e5851 100644 --- a/package.json +++ b/package.json @@ -104,11 +104,13 @@ "build": "webpack --mode production", "build:dev": "webpack --mode development", "lint": "eslint --fix . --ext js,jsx,ts,tsx", + "lint:report": "eslint --ext js,jsx,ts,tsx .", "preinstall": "node ./scripts/engines-check.js", "test": "jest", "test:watch": "jest --watch", "watch": "webpack --watch --mode production", "watch:dev": "webpack --watch --mode development", + "package-electron": "electron-packager .package bitburner --all --out .build --overwrite --icon .package/icon.png", "electron": "cp -r electron/* .package && cp index.html .package && cp main.bundle.js .package && cp dist/vendor.bundle.js .package/dist/ && cp -r dist/ext .package/dist/ && electron-packager .package bitburner --all --out .build --overwrite --icon .package/icon.png", "allbuild": "npm run build && npm run electron && git add --all && git commit --amend --no-edit && git push -f -u origin dev" }