Skip to content

Commit

Permalink
chore: replace jest with vitest (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed Aug 29, 2024
1 parent 5f4b7be commit ed15d2e
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 113 deletions.
9 changes: 3 additions & 6 deletions packages/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"test": "jest",
"test": "vitest",
"build": "tsup --dts",
"lint": "eslint . --quiet",
"lint:fix": "eslint . --fix",
Expand All @@ -15,16 +15,13 @@
"author": "bludnic",
"license": "Apache-2.0",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@opentrader/eslint": "workspace:*",
"@opentrader/tsconfig": "workspace:*",
"@types/big.js": "^6.2.2",
"@types/jest": "^29.5.12",
"eslint": "8.57.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"tsup": "^8.2.4",
"typescript": "5.5.4"
"typescript": "5.5.4",
"vitest": "^2.0.5"
},
"dependencies": {
"@opentrader/types": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { barSizeToDuration } from "./barSizeToDuration.js";

describe("barSizeToDuration function", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { describe, expect, it } from "vitest";
import { CANDLESTICKS } from "../mocks/candlesticks.js";
import { findHighestCandlestickBy } from "./findHighestCandlestickBy.js";

describe("findHighestCandlestickBy", () => {
it("highest by close", () => {
expect(findHighestCandlestickBy("close", CANDLESTICKS)).toEqual(
CANDLESTICKS[0],
);
expect(findHighestCandlestickBy("close", CANDLESTICKS)).toEqual(CANDLESTICKS[0]);
});

it("highest by open", () => {
expect(findHighestCandlestickBy("open", CANDLESTICKS)).toEqual(
CANDLESTICKS[2],
);
expect(findHighestCandlestickBy("open", CANDLESTICKS)).toEqual(CANDLESTICKS[2]);
});

it("highest by low", () => {
expect(findHighestCandlestickBy("low", CANDLESTICKS)).toEqual(
CANDLESTICKS[2],
);
expect(findHighestCandlestickBy("low", CANDLESTICKS)).toEqual(CANDLESTICKS[2]);
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { describe, expect, it } from "vitest";
import { CANDLESTICKS } from "../mocks/candlesticks.js";
import { findLowestCandlestickBy } from "./findLowestCandlestickBy.js";

describe("findLowestCandlestickBy", () => {
it("lowest by close", () => {
expect(findLowestCandlestickBy("close", CANDLESTICKS)).toEqual(
CANDLESTICKS[2],
);
expect(findLowestCandlestickBy("close", CANDLESTICKS)).toEqual(CANDLESTICKS[2]);
});

it("lowest by open", () => {
expect(findLowestCandlestickBy("open", CANDLESTICKS)).toEqual(
CANDLESTICKS[1],
);
expect(findLowestCandlestickBy("open", CANDLESTICKS)).toEqual(CANDLESTICKS[1]);
});

it("lowest by low", () => {
expect(findLowestCandlestickBy("low", CANDLESTICKS)).toEqual(
CANDLESTICKS[0],
);
expect(findLowestCandlestickBy("low", CANDLESTICKS)).toEqual(CANDLESTICKS[0]);
});
});
48 changes: 0 additions & 48 deletions packages/tools/src/candlesticks/lastClosedCandleDate.spec.ts

This file was deleted.

26 changes: 26 additions & 0 deletions packages/tools/src/candlesticks/lastClosedCandleDate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import { lastClosedCandleDate } from "./lastClosedCandleDate.js";

describe("lastClosedCandleDate", () => {
it("should return the correct date for each bar size", () => {
expect(lastClosedCandleDate(new Date("2023-01-21T01:00:00.000Z").getTime(), "1m")).toBe("2023-01-21T00:59:00.000Z");
});

it("should return the correct date for 1m bar size with milliseconds", () => {
expect(lastClosedCandleDate(new Date("2023-01-21T01:00:00.123Z").getTime(), "1m")).toBe("2023-01-21T00:59:00.000Z");
});

it("should return the correct date for 5m bar size with milliseconds", () => {
expect(lastClosedCandleDate(new Date("2023-01-21T01:00:00.123Z").getTime(), "5m")).toBe("2023-01-21T00:55:00.000Z");
});

it("should return the correct date for 15m bar size with milliseconds", () => {
expect(lastClosedCandleDate(new Date("2023-01-21T01:00:00.123Z").getTime(), "15m")).toBe(
"2023-01-21T00:45:00.000Z",
);
});

it("should return the correct date for 1h bar size with milliseconds", () => {
expect(lastClosedCandleDate(new Date("2023-01-21T01:00:00.123Z").getTime(), "1h")).toBe("2023-01-21T00:00:00.000Z");
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { countDecimalPlaces } from "./countDecimalPlaces.js";

describe(countDecimalPlaces.name, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { getExponentAbs } from "./getExponentAbs.js";

describe("getExponentAbs", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { ETH_SYMBOL_FILTER } from "../mocks/symbols.js";
import { filterPrice } from "./filterPrice.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { ETH_SYMBOL_FILTER } from "../mocks/symbols.js";
import { filterQuantity } from "./filterQuantity.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { areGridLinesPricesSortedInAscOrder } from "./areGridLinesPricesSortedInAscOrder.js";

describe("areGridLinesPricesSortedInAscOrder", () => {
Expand All @@ -6,9 +7,7 @@ describe("areGridLinesPricesSortedInAscOrder", () => {
});

it("should return `true` when only one grid line is preset", () => {
expect(
areGridLinesPricesSortedInAscOrder([{ price: 10, quantity: 1 }]),
).toBe(true);
expect(areGridLinesPricesSortedInAscOrder([{ price: 10, quantity: 1 }])).toBe(true);
});

it("should return `false` when grid lines are not sorted", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
BASE_CURRENCY_INVESTMENT,
GRID_LEVELS,
QUOTE_CURRENCY_INVESTMENT,
} from "../mocks/grid-bot.js";
import { describe, expect, it } from "vitest";
import { BASE_CURRENCY_INVESTMENT, GRID_LEVELS, QUOTE_CURRENCY_INVESTMENT } from "../mocks/grid-bot.js";
import { calculateInvestment } from "./calculateInvestment.js";

describe("calculateInvestment", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { describe, expect, it } from "vitest";
import type { IGridBotLevel } from "@opentrader/types";
import {
CURRENT_ASSET_PRICE,
GRID_LINES,
GRID_LEVELS,
} from "../mocks/grid-bot.js";
import { CURRENT_ASSET_PRICE, GRID_LINES, GRID_LEVELS } from "../mocks/grid-bot.js";
import { calcGridLines } from "./calcGridLines.js";
import { computeGridLevelsFromCurrentAssetPrice } from "./computeGridLevelsFromCurrentAssetPrice.js";

describe("computeGridLevelsFromCurrentAssetPrice", () => {
it("should calculate initial grid levels", () => {
const gridLevels = computeGridLevelsFromCurrentAssetPrice(
GRID_LINES,
CURRENT_ASSET_PRICE,
);
const gridLevels = computeGridLevelsFromCurrentAssetPrice(GRID_LINES, CURRENT_ASSET_PRICE);
const expectedGridLevels: IGridBotLevel[] = GRID_LEVELS;

expect(gridLevels).toStrictEqual(expectedGridLevels);
Expand All @@ -22,10 +16,7 @@ describe("computeGridLevelsFromCurrentAssetPrice", () => {
const currentAssetPrice = 1.13;
const gridLines = calcGridLines(1.14, 1.11, 4, 5);

const gridLevels = computeGridLevelsFromCurrentAssetPrice(
gridLines,
currentAssetPrice,
);
const gridLevels = computeGridLevelsFromCurrentAssetPrice(gridLines, currentAssetPrice);

expect(gridLevels).toMatchObject([
{ sell: { price: 1.12 } },
Expand All @@ -38,10 +29,7 @@ describe("computeGridLevelsFromCurrentAssetPrice", () => {
const currentAssetPrice = 2610;
const gridLines = calcGridLines(2800, 2500, 16, 0.1);

const gridLevels = computeGridLevelsFromCurrentAssetPrice(
gridLines,
currentAssetPrice,
);
const gridLevels = computeGridLevelsFromCurrentAssetPrice(gridLines, currentAssetPrice);

expect(gridLevels).toHaveLength(15);
expect(gridLevels).toMatchObject([
Expand All @@ -68,10 +56,7 @@ describe("computeGridLevelsFromCurrentAssetPrice", () => {
const currentAssetPrice = 9.8;
const gridLines = calcGridLines(12, 7.5, 10, 10);

const gridLevels = computeGridLevelsFromCurrentAssetPrice(
gridLines,
currentAssetPrice,
);
const gridLevels = computeGridLevelsFromCurrentAssetPrice(gridLines, currentAssetPrice);

expect(gridLevels).toHaveLength(9);
expect(gridLevels).toMatchObject([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import type { IGridLine } from "@opentrader/types";
import { isWaitingGridLine } from "./isWaitingGridLine.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { isWaitingPriceLine } from "./isWaitingPriceLine.js";

const priceLines = [1, 3, 2, 4, 5];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { ExchangeCode } from "@opentrader/types";
import type { DecomposeSymbolIdResult } from "./decomposeSymbolId.js";
import { decomposeSymbolId } from "./decomposeSymbolId.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { ExchangeCode } from "@opentrader/types";
import { isValidExchangeCode } from "./isValidExchangeCode.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { isValidSymbol } from "./isValidSymbol.js";

describe("isValidSymbol", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from "vitest";
import { isValidSymbolId } from "./isValidSymbolId.js";

describe("isValidSymbolId", () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/tools/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
environment: "node",
coverage: {
reporter: ["text", "json", "html"],
},
include: ["src/**/*.test.ts"],
},
});
15 changes: 3 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed15d2e

Please sign in to comment.