import { test } from "node:test"; import assert from "node:assert/strict"; import * as adb from "../src/adb.js"; test("normalizeTarget adds default port 5555", () => { assert.equal(adb.normalizeTarget("192.168.1.50"), "192.168.1.50:5555"); }); test("normalizeTarget keeps an explicit port", () => { assert.equal(adb.normalizeTarget("192.168.1.50:5556"), "192.168.1.50:5556"); }); test("normalizeTarget trims whitespace", () => { assert.equal(adb.normalizeTarget(" 192.168.1.50 "), "192.168.1.50:5555"); }); test("normalizeTarget rejects shell-hostile input", () => { assert.throws(() => adb.normalizeTarget("1.2.3.4; rm -rf /"), /doesn't look like/); }); test("normalizeTarget rejects empty input", () => { assert.throws(() => adb.normalizeTarget(""), /doesn't look like/); }); test("connect() rejects cleanly against a closed local port instead of hanging", async () => { // Nothing listens on 5599 locally, so `adb connect` should fail fast with // a normal error rather than the process throwing an unhandled exception. await assert.rejects(adb.connect("127.0.0.1:5599"), (err) => { assert.equal(err.name, "AdbError"); return true; }); }); test("pair() rejects a non-6-digit code before touching adb", async () => { await assert.rejects(adb.pair("127.0.0.1:5599", "12"), /6 digits/); });