diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ddd778..dcf8ee4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,13 +19,16 @@ jobs: - name: Install Bun uses: oven-sh/setup-bun@v1 with: - bun-version: latest # Or specify a version like "1.1.0" + bun-version: 1.3.9 - name: Install dependencies run: bun install + - name: Generate protobuf types + run: bun run proto-gen + - name: Run Biome lint run: bunx @biomejs/biome lint . - name: Run tests - run: bun test \ No newline at end of file + run: bun test \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 256a730..b8bf5e6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,7 +22,7 @@ jobs: - name: Install Bun uses: oven-sh/setup-bun@v1 with: - bun-version: latest + bun-version: 1.3.9 - name: Setup Node.js for npm publishing uses: actions/setup-node@v4 @@ -37,6 +37,9 @@ jobs: - name: Install dependencies run: bun install + - name: Generate protobuf types + run: bun run proto-gen + - name: Run tests run: bun test diff --git a/test-setup.ts b/test-setup.ts index 2436e4f..7eb148f 100644 --- a/test-setup.ts +++ b/test-setup.ts @@ -10,12 +10,10 @@ beforeAll(() => { const originalConsole = { ...console }; console.log = () => {}; console.warn = () => {}; - console.error = () => {}; // Restore console after tests afterAll(() => { console.log = originalConsole.log; console.warn = originalConsole.warn; - console.error = originalConsole.error; }); }); diff --git a/test/cex-broker.test.ts b/test/cex-broker.test.ts index da0667e..3e874e1 100644 --- a/test/cex-broker.test.ts +++ b/test/cex-broker.test.ts @@ -42,9 +42,9 @@ describe("CEXBroker", () => { delete process.env.CEX_BROKER_BINANCE_API_SECRET_1; }); - afterEach(() => { + afterEach(async () => { if (broker) { - broker.stop(); + await broker.stop(); } }); @@ -209,9 +209,9 @@ describe("CEXBroker", () => { expect(startedBroker).toBe(broker); }); - test("should stop server successfully", () => { + test("should stop server successfully", async () => { broker = new CEXBroker({}, testPolicy); - broker.stop(); + await broker.stop(); expect(broker).toBeDefined(); }); diff --git a/test/integration.test.ts b/test/integration.test.ts index 6982793..71f3049 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -1,25 +1,21 @@ +import { readFileSync } from "node:fs"; import { describe, expect, test } from "bun:test"; describe("Integration Tests", () => { describe("Policy Integration", () => { test("should load and validate policy correctly", () => { - // Test that the policy file can be loaded - const fs = require("bun:fs"); - const path = require("bun:path"); - const policyPath = path.join(__dirname, "../policy/policy.json"); + const policyPath = new URL("../policy/policy.json", import.meta.url); expect(() => { - const policyData = fs.readFileSync(policyPath, "utf8"); + const policyData = readFileSync(policyPath, "utf8"); const policy = JSON.parse(policyData); return policy; }).not.toThrow(); }); test("should have correct policy structure", () => { - const fs = require("bun:fs"); - const path = require("bun:path"); - const policyPath = path.join(__dirname, "../policy/policy.json"); - const policyData = fs.readFileSync(policyPath, "utf8"); + const policyPath = new URL("../policy/policy.json", import.meta.url); + const policyData = readFileSync(policyPath, "utf8"); const policy = JSON.parse(policyData); // Check withdraw policy diff --git a/test/otel.test.ts b/test/otel.test.ts index dfcc92b..4800c47 100644 --- a/test/otel.test.ts +++ b/test/otel.test.ts @@ -27,65 +27,72 @@ describe("OtelMetrics", () => { }); describe("Initialization", () => { - test("should be enabled when hostname is provided", () => { + test("should be enabled when hostname is provided", async () => { const config: OtelConfig = { host: "localhost", port: 8123, }; const metrics = new OtelMetrics(config); expect(metrics.isOtelEnabled()).toBe(true); + await metrics.close(); }); - test("should use default values when optional config is missing", () => { + test("should use default values when optional config is missing", async () => { const config: OtelConfig = { host: "localhost", }; const metrics = new OtelMetrics(config); expect(metrics.isOtelEnabled()).toBe(true); + await metrics.close(); }); - test("should handle initialization errors gracefully", () => { + test("should handle initialization errors gracefully", async () => { const config: OtelConfig = { host: "invalid://host", port: 8123, }; const metrics = new OtelMetrics(config); expect(metrics).toBeDefined(); + await metrics.close(); }); }); describe("createOtelMetricsFromEnv", () => { - test("should create metrics from CEX_BROKER_OTEL_* env vars", () => { + test("should create metrics from CEX_BROKER_OTEL_* env vars", async () => { process.env.CEX_BROKER_OTEL_HOST = "localhost"; process.env.CEX_BROKER_OTEL_PORT = "8123"; process.env.CEX_BROKER_OTEL_PROTOCOL = "https"; const metrics = createOtelMetricsFromEnv(); expect(metrics.isOtelEnabled()).toBe(true); + await metrics.close(); }); - test("should create metrics from legacy CEX_BROKER_CLICKHOUSE_* env vars", () => { + test("should create metrics from legacy CEX_BROKER_CLICKHOUSE_* env vars", async () => { process.env.CEX_BROKER_CLICKHOUSE_HOST = "localhost"; process.env.CEX_BROKER_CLICKHOUSE_PORT = "8123"; process.env.CEX_BROKER_CLICKHOUSE_PROTOCOL = "https"; const metrics = createOtelMetricsFromEnv(); expect(metrics.isOtelEnabled()).toBe(true); + await metrics.close(); }); - test("should use default values for optional env vars", () => { + test("should use default values for optional env vars", async () => { process.env.CEX_BROKER_OTEL_HOST = "localhost"; const metrics = createOtelMetricsFromEnv(); expect(metrics.isOtelEnabled()).toBe(true); + await metrics.close(); }); - test("should prefer OTEL_EXPORTER_OTLP_ENDPOINT when set", () => { + test("should prefer OTEL_EXPORTER_OTLP_ENDPOINT when set", async () => { process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "http://collector:4318"; process.env.CEX_BROKER_OTEL_HOST = "legacy-host"; const metrics = createOtelMetricsFromEnv(); expect(metrics.isOtelEnabled()).toBe(true); + await metrics.close(); }); });