From 8e67f5a70765c76b408892b396fd1fe211a80aba Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Wed, 11 Mar 2026 09:04:31 +0700 Subject: [PATCH] fix(tests): iteration 1 --- .../relay/src/dist-handshake-parity.test.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/relay/src/dist-handshake-parity.test.ts b/packages/relay/src/dist-handshake-parity.test.ts index af25cc77a..f76e40ee6 100644 --- a/packages/relay/src/dist-handshake-parity.test.ts +++ b/packages/relay/src/dist-handshake-parity.test.ts @@ -1,14 +1,27 @@ -import { readFileSync } from "node:fs"; +import { existsSync, readFileSync } from "node:fs"; +import { execFileSync } from "node:child_process"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const THIS_DIR = path.dirname(fileURLToPath(import.meta.url)); const DIST_ENCRYPTED_CHANNEL_PATH = path.resolve(THIS_DIR, "../dist/encrypted-channel.js"); +const RELAY_PACKAGE_ROOT = path.resolve(THIS_DIR, ".."); + +function readBuiltEncryptedChannel(): string { + if (!existsSync(DIST_ENCRYPTED_CHANNEL_PATH)) { + execFileSync("npm", ["run", "build"], { + cwd: RELAY_PACKAGE_ROOT, + stdio: "inherit", + }); + } + + return readFileSync(DIST_ENCRYPTED_CHANNEL_PATH, "utf8"); +} describe("relay dist handshake parity", () => { it("keeps Node dist handshake message types in sync with src", () => { - const distCode = readFileSync(DIST_ENCRYPTED_CHANNEL_PATH, "utf8"); + const distCode = readBuiltEncryptedChannel(); expect(distCode).toContain('type: "e2ee_hello"'); expect(distCode).toContain('type: "e2ee_ready"'); @@ -18,4 +31,3 @@ describe("relay dist handshake parity", () => { expect(distCode).not.toMatch(/\btype:\s*"ready"\b/); }); }); -