|
| 1 | +import { describe, it, expect, afterEach } from "vitest"; |
| 2 | +import { record } from "../src/index"; |
| 3 | +import { Algodv2 } from "algosdk"; |
| 4 | +import fs from "fs"; |
| 5 | +import path from "path"; |
| 6 | + |
| 7 | +const TEST_RECORDINGS_DIR = path.resolve(__dirname, "../recordings-test"); |
| 8 | +const LOCALNET_ALGOD_URL = "http://localhost"; |
| 9 | +const LOCALNET_ALGOD_PORT = 4001; |
| 10 | + |
| 11 | +describe("Recording Tests", () => { |
| 12 | + afterEach(async () => { |
| 13 | + // Clean up test recordings directory completely |
| 14 | + if (fs.existsSync(TEST_RECORDINGS_DIR)) { |
| 15 | + fs.rmSync(TEST_RECORDINGS_DIR, { recursive: true, force: true }); |
| 16 | + } |
| 17 | + }); |
| 18 | + |
| 19 | + it("should record in record-new mode", async () => { |
| 20 | + // Create test recordings directory |
| 21 | + fs.mkdirSync(TEST_RECORDINGS_DIR, { recursive: true }); |
| 22 | + |
| 23 | + // Create recording with record-new |
| 24 | + await record( |
| 25 | + "algod", |
| 26 | + async () => { |
| 27 | + const client = new Algodv2( |
| 28 | + "a".repeat(64), |
| 29 | + LOCALNET_ALGOD_URL, |
| 30 | + LOCALNET_ALGOD_PORT |
| 31 | + ); |
| 32 | + await client.status().do(); |
| 33 | + }, |
| 34 | + "record-new", |
| 35 | + TEST_RECORDINGS_DIR |
| 36 | + ); |
| 37 | + |
| 38 | + // Verify HAR file was created |
| 39 | + const harFiles = fs.readdirSync(TEST_RECORDINGS_DIR, { recursive: true }); |
| 40 | + const harFileName = harFiles.find((f) => |
| 41 | + f.toString().endsWith("recording.har") |
| 42 | + ); |
| 43 | + expect(harFileName).toBeDefined(); |
| 44 | + |
| 45 | + const harPath = path.join(TEST_RECORDINGS_DIR, harFileName!.toString()); |
| 46 | + expect(fs.existsSync(harPath)).toBe(true); |
| 47 | + |
| 48 | + // Verify HAR file has entries |
| 49 | + const content = fs.readFileSync(harPath, "utf-8"); |
| 50 | + const har = JSON.parse(content); |
| 51 | + expect(har.log.entries.length).toBeGreaterThan(0); |
| 52 | + }); |
| 53 | +}); |
0 commit comments