diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index c59ff5eba..000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: CI - -on: - push: - branches: [dev] - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: "14" - cache: "npm" - - - name: Install Dependencies - run: npm ci - - - name: Test - run: npm run test - - - name: Build - run: npm run build - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 7bd900b5c..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: CI - -on: [push, pull_request] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - test: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: "14" - cache: "npm" - - - name: Install Dependencies - run: npm ci - - - name: Test - run: npm run test diff --git a/.gitignore b/.gitignore index 35a419b0f..63c90cd7a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ Netburner.txt /test/*.bundle.* /test/*.css .cypress +dist-tsc # editor files .vscode diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5abf64ead..003c91871 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -123,3 +123,46 @@ rules: _danielyxie/bitburner_ and the base is _dev_. - Do not check in any generated files under `doc\`. The documentation is built automatically by ReadTheDocs. + +## Tests + +There are a few unit tests written using [jest](https://jestjs.io/), and some browser automation tests using [Cypress](https://www.cypress.io/). + +### Unit Tests + +Run unit tests with: + +```sh +$ npm run test +$ npm run test:watch # to re-run tests on changes +``` + +Tests go in the `/test` directory. + +### Browser Tests + +There are full browser automation tests which cover some basic "does it work" functionality. + +Run these with: + +```sh +$ npm run build +$ npm run cy:test +``` + +To start up the tests in watch mode (re-run on changes), which will also start up a dev server: + +```sh +$ npm run cy:dev +``` + +## TypeScript Setup + +This project uses [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) +to make sure that jest and Cypress tests only exist within Jest/Cypress code. + +To type-check the whole project: + +```sh +$ npm run typescript +``` diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json new file mode 100644 index 000000000..608a1a0c9 --- /dev/null +++ b/cypress/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["**/*"], + "compilerOptions": { + "types": ["cypress", "@testing-library/cypress"] + } +} diff --git a/jest.config.js b/jest.config.js index 4fb0d1462..94233b728 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,6 +4,6 @@ module.exports = { transform: { "^.+\\.(js|jsx|ts|tsx)$": "babel-jest", }, - // testMatch: ["**/?(*.)+(test).[jt]s?(x)"], + testMatch: ["**/?(*.)+(test).[jt]s?(x)"], testEnvironment: "jsdom", }; diff --git a/package-lock.json b/package-lock.json index 698385c86..cb3013eff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "bitburner", "version": "0.52.9", "hasInstallScript": true, "license": "SEE LICENSE IN license.txt", @@ -63,7 +64,7 @@ "@types/lodash": "^4.14.168", "@typescript-eslint/eslint-plugin": "^4.22.0", "@typescript-eslint/parser": "^4.22.0", - "babel-jest": "^27.0.6", + "babel-jest": "^27.1.0", "babel-loader": "^8.0.5", "beautify-lint": "^1.0.3", "benchmark": "^2.1.1", @@ -39258,9 +39259,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/mathjax-react/-/mathjax-react-1.0.6.tgz", "integrity": "sha512-GlkPAhaY0FKc95TMdo33mxNZHb+3xRgfgc3YcnQ0cZxvnM1UaF0o8mRI5y5xIwi3JnioeYuukZJWCbIZkACIVw==", - "requires": { - "mathjax-full": "^3.0.4" - } + "requires": {} }, "mathml-tag-names": { "version": "2.1.0", diff --git a/package.json b/package.json index bccd17b30..b381be1de 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@types/lodash": "^4.14.168", "@typescript-eslint/eslint-plugin": "^4.22.0", "@typescript-eslint/parser": "^4.22.0", - "babel-jest": "^27.0.6", + "babel-jest": "^27.1.0", "babel-loader": "^8.0.5", "beautify-lint": "^1.0.3", "benchmark": "^2.1.1", @@ -137,6 +137,7 @@ "lint": "npm run lint:jsts & npm run lint:style", "lint:jsts": "eslint --fix . --ext js,jsx,ts,tsx", "lint:style": "stylelint --fix ./css/*", + "typescript": "tsc --build", "preinstall": "node ./scripts/engines-check.js", "test": "jest", "test:watch": "jest --watch", diff --git a/test/StockMarket.test.ts b/test/StockMarket.test.ts index 7f8341ce1..245218dee 100644 --- a/test/StockMarket.test.ts +++ b/test/StockMarket.test.ts @@ -35,11 +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("../src/ui/React/createPopup.tsx", () => ({ -// createPopup: jest.fn(), -// })); +jest.mock("../src/ui/React/createPopup.tsx", () => ({ + createPopup: jest.fn(), +})); describe("Stock Market Tests", function () { const commission = CONSTANTS.StockMarketCommission; @@ -63,7 +62,7 @@ describe("Stock Market Tests", function () { stock = new Stock(ctorParams); } - expect(construct).not.throw(); + expect(construct).not.toThrow(); }); describe("Stock Class", function () { @@ -72,26 +71,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 +124,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).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 () { - 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 +163,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 +174,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 +188,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 +197,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).toContain(stock.otlkMagForecast); }); }); @@ -206,31 +205,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 +237,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).toBeLessThanOrEqual(1); + expect(perc).toBeGreaterThanOrEqual(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).toBeLessThanOrEqual(1); + expect(perc).toBeGreaterThanOrEqual(0); const expected = stock.price * (1 - perc); - expect(stock.getBidPrice()).equal(expected); + expect(stock.getBidPrice()).toEqual(expected); }); }); @@ -285,50 +284,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 +338,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 +364,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 +389,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 +402,35 @@ describe("Stock Market Tests", function () { } // We'll just check that there are some stocks - expect(stocks.length).gte(1); + expect(stocks.length).toBeGreaterThanOrEqual(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({}); }); }); @@ -443,9 +442,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 +473,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 +496,7 @@ describe("Stock Market Tests", function () { continue; } - expect(SymbolToStockMap[stock.symbol]).equal(stock); + expect(SymbolToStockMap[stock.symbol]).toEqual(stock); } }); }); @@ -506,55 +505,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 +564,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 +601,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 +635,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 +645,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 +655,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 +665,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 +677,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 +687,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 +697,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 +709,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 +723,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,54 +827,54 @@ 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 () { 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 Player.setMoney(cost!); - expect(buyStock(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShares).equal(shares); - expect(stock.playerAvgPx).greaterThan(0); - expect(Player.money.toNumber()).equal(0); + expect(buyStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(shares); + expect(stock.playerAvgPx).toBeGreaterThan(0); + expect(Player.money.toNumber()).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 +884,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.toNumber()).equal(gain); + expect(sellStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(0); + expect(stock.playerAvgPx).toEqual(0); + expect(Player.money.toNumber()).toEqual(gain); }); it("should cap the number of sharse sold to however many the player owns", function () { @@ -899,10 +898,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.toNumber()).equal(gain); + expect(sellStock(stock, attemptedShares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(0); + expect(stock.playerAvgPx).toEqual(0); + expect(Player.money.toNumber()).toEqual(gain); }); it("should properly update stock properties for partial transactions", function () { @@ -913,63 +912,63 @@ 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.toNumber()).equal(gain); + expect(sellStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShares).toEqual(shares); + expect(stock.playerAvgPx).toEqual(origPrice); + expect(Player.money.toNumber()).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 () { 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 Player.setMoney(cost!); - expect(shortStock(stock, shares, null, suppressDialogOpt)).equal(true); - expect(stock.playerShortShares).equal(shares); - expect(stock.playerAvgShortPx).greaterThan(0); - expect(Player.money.toNumber()).equal(0); + expect(shortStock(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(shares); + expect(stock.playerAvgShortPx).toBeGreaterThan(0); + expect(Player.money.toNumber()).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 +978,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.toNumber()).equal(gain); + expect(sellShort(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(0); + expect(stock.playerAvgShortPx).toEqual(0); + expect(Player.money.toNumber()).toEqual(gain); }); it("should cap the number of sharse sold to however many the player owns", function () { @@ -993,10 +992,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.toNumber()).equal(gain); + expect(sellShort(stock, attemptedShares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(0); + expect(stock.playerAvgShortPx).toEqual(0); + expect(Player.money.toNumber()).toEqual(gain); }); it("should properly update stock properties for partial transactions", function () { @@ -1007,10 +1006,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.toNumber()).equal(gain); + expect(sellShort(stock, shares, null, suppressDialogOpt)).toEqual(true); + expect(stock.playerShortShares).toEqual(shares); + expect(stock.playerAvgShortPx).toEqual(origPrice); + expect(Player.money.toNumber()).toEqual(gain); }); }); }); @@ -1033,18 +1032,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 +1055,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 +1082,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 +1101,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 +1119,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 +1128,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; @@ -1149,13 +1148,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 () { @@ -1165,7 +1164,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 () { @@ -1175,7 +1174,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 () { @@ -1185,7 +1184,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 () { @@ -1195,7 +1194,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 () { @@ -1205,7 +1204,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 () { @@ -1215,7 +1214,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 () { @@ -1225,7 +1224,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 () { @@ -1235,13 +1234,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); }); }); }); @@ -1264,8 +1263,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; }); @@ -1274,13 +1273,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); }); }); @@ -1288,13 +1287,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); }); }); @@ -1305,7 +1304,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 () { @@ -1314,7 +1313,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 80ccdbdcd..57bdad6d0 100644 --- a/test/StringHelperFunctions.test.ts +++ b/test/StringHelperFunctions.test.ts @@ -2,19 +2,19 @@ import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions 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( - "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, true)).toEqual( "2 days 5 minutes 34.123 seconds", ); + expect( + convertTimeMsToTimeElapsedString(2 * 60 * 60 * 24 * 1000 + 5 * 60 * 1000 + 34 * 1000 + 123.888, true), + ).toEqual("2 days 5 minutes 34.123 seconds"); }); }); diff --git a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts index b75bdda21..9d70b9b6e 100644 --- a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts +++ b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts @@ -44,12 +44,12 @@ describe("determineAllPossibilitiesForTabCompletion", function () { it("completes the connect command", () => { const options = determineAllPossibilitiesForTabCompletion(Player, "connect ", 0); - expect(options).equal(["8.8.8.8", "near"]); + expect(options).toEqual(["8.8.8.8", "near"]); }); it("completes the buy command", () => { const options = determineAllPossibilitiesForTabCompletion(Player, "buy ", 0); - expect(options).equal([ + expect(options).toEqual([ "BruteSSH.exe", "FTPCrack.exe", "relaySMTP.exe", @@ -67,23 +67,23 @@ describe("determineAllPossibilitiesForTabCompletion", function () { 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/"]); + 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"]); + expect(options2).toEqual([Player.getHomeComputer().ip, "home", "8.8.8.8", "near", "4.4.4.4", "far"]); }); it("completes the kill, tail, mem, and check commands", () => { 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/"]); + expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).toEqual(["/www/script.js", "www/"]); } }); it("completes the nano commands", () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); - expect(determineAllPossibilitiesForTabCompletion(Player, "nano ", 0)).equal([ + expect(determineAllPossibilitiesForTabCompletion(Player, "nano ", 0)).toEqual([ "/www/script.js", "note.txt", ".fconf", @@ -97,7 +97,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () { Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); Player.getHomeComputer().messages.push(new Message("asl.msg")); Player.getHomeComputer().messages.push("af.lit"); - expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).equal([ + expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).toEqual([ "/www/script.js", "NUKE.exe", "af.lit", @@ -110,7 +110,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () { it("completes the run command", () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); - expect(determineAllPossibilitiesForTabCompletion(Player, "run ", 0)).equal([ + expect(determineAllPossibilitiesForTabCompletion(Player, "run ", 0)).toEqual([ "/www/script.js", "NUKE.exe", "linklist.cct", @@ -122,7 +122,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () { Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark"); Player.getHomeComputer().messages.push(new Message("asl.msg")); Player.getHomeComputer().messages.push("af.lit"); - expect(determineAllPossibilitiesForTabCompletion(Player, "cat ", 0)).equal([ + expect(determineAllPossibilitiesForTabCompletion(Player, "cat ", 0)).toEqual([ "asl.msg", "af.lit", "/www/note.txt", @@ -134,7 +134,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () { 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([ + expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).toEqual([ "/www/script.js", "note.txt", "www/", @@ -144,19 +144,19 @@ describe("determineAllPossibilitiesForTabCompletion", function () { it("completes the cd command", () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); - expect(determineAllPossibilitiesForTabCompletion(Player, "cd ", 0)).equal(["www/"]); + expect(determineAllPossibilitiesForTabCompletion(Player, "cd ", 0)).toEqual(["www/"]); }); it("completes the ls and cd commands", () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); for (const command of ["ls", "cd"]) { - expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).equal(["www/"]); + expect(determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0)).toEqual(["www/"]); } }); it("completes commands starting with ./", () => { Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); - expect(determineAllPossibilitiesForTabCompletion(Player, "run ./", 0)).equal([ + expect(determineAllPossibilitiesForTabCompletion(Player, "run ./", 0)).toEqual([ ".//www/script.js", "NUKE.exe", "./www/", diff --git a/test/tsconfig.spec.json b/test/tsconfig.spec.json new file mode 100644 index 000000000..01e09f3b9 --- /dev/null +++ b/test/tsconfig.spec.json @@ -0,0 +1,4 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["**/*"] +} diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 000000000..fc4a395be --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "outDir": "./dist-tsc/", + "esModuleInterop": true, + "isolatedModules": true, + "jsx": "react", + "lib": ["es2016", "dom", "es2017.object", "es2019"], + "module": "commonjs", + "target": "es6", + "strict": true + } +} diff --git a/tsconfig.json b/tsconfig.json index b488241a0..213ba669b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,14 @@ { - "compilerOptions": { - "baseUrl": ".", - "esModuleInterop": true, - "isolatedModules": true, - "jsx": "react", - "lib": ["es2016", "dom", "es2017.object", "es2019"], - "module": "commonjs", - "target": "es6", - "sourceMap": true, - "strict": true, - "types": ["cypress", "@testing-library/cypress"] - }, - "exclude": ["node_modules"] + "files": [], + "references": [ + { + "path": "./tsconfig.src.json" + }, + { + "path": "./test/tsconfig.spec.json" + }, + { + "path": "./cypress/tsconfig.json" + } + ] } diff --git a/tsconfig.src.json b/tsconfig.src.json new file mode 100644 index 000000000..b5f69ac4c --- /dev/null +++ b/tsconfig.src.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.base.json", + "exclude": ["node_modules", "cypress", "test"] +}