diff options
Diffstat (limited to 'test/cdp/discovery-test.ts')
| -rw-r--r-- | test/cdp/discovery-test.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/test/cdp/discovery-test.ts b/test/cdp/discovery-test.ts index 7fc18fb..61b42b7 100644 --- a/test/cdp/discovery-test.ts +++ b/test/cdp/discovery-test.ts @@ -1,6 +1,6 @@ import { test, describe } from "node:test"; import assert from "node:assert/strict"; -import { endpointFromEnv } from "../../src/cdp/discovery"; +import { endpointFromEnv, parseVersionResponse } from "../../src/cdp/discovery"; describe("BU_CDP_WS endpoint override", () => { test("an unset variable leaves discovery to run normally", () => { @@ -27,3 +27,20 @@ describe("BU_CDP_WS endpoint override", () => { assert.equal(endpointFromEnv({ BU_CDP_WS: " " }), undefined); }); }); + +describe("/json/version parsing", () => { + test("extracts webSocketDebuggerUrl from a well-formed response", () => { + const raw = JSON.stringify({ Browser: "Chrome/154.0", webSocketDebuggerUrl: "ws://127.0.0.1:9222/devtools/browser/abc" }); + assert.equal(parseVersionResponse(raw), "ws://127.0.0.1:9222/devtools/browser/abc"); + }); + + test("a response without the url yields null", () => { + assert.equal(parseVersionResponse(JSON.stringify({ Browser: "Chrome/154.0" })), null); + }); + + test("a non-string url, a non-object body, and invalid JSON all yield null", () => { + assert.equal(parseVersionResponse(JSON.stringify({ webSocketDebuggerUrl: 42 })), null); + assert.equal(parseVersionResponse(JSON.stringify([1, 2])), null); + assert.equal(parseVersionResponse("not json"), null); + }); +}); |
