1import { describe, expect, test } from "bun:test";
2import { parseOutputUrl, parseOutputValue } from "../src/DevCli.ts";
3
4describe("parseOutputUrl", () => {
5 test("parses aligned and legacy stack output formats", () => {
6 expect(
7 parseOutputUrl(" api http://api.localhost:1234/\n", "api"),
8 ).toBe("http://api.localhost:1234/");
9 expect(parseOutputUrl('api: "https://example.com/path"\n', "api")).toBe(
10 "https://example.com/path",
11 );
12 expect(
13 parseOutputUrl(
14 '{\n api: "http://api.localhost:1234/",\n stage: "dev",\n}\n',
15 "api",
16 ),
17 ).toBe("http://api.localhost:1234/");
18 });
19
20 test("matches exact keys and waits for a complete output line", () => {
21 expect(
22 parseOutputUrl("otherApi http://wrong.example/\n", "api"),
23 ).toBeUndefined();
24 expect(
25 parseOutputUrl("api http://partial.example/", "api"),
26 ).toBeUndefined();
27 });
28});
29
30describe("parseOutputValue", () => {
31 test("parses aligned and legacy scalar output formats", () => {
32 expect(parseOutputValue(" account 000000000000\n", "account")).toBe(
33 "000000000000",
34 );
35 expect(parseOutputValue('text: "seed-object-body-v1"\n', "text")).toBe(
36 "seed-object-body-v1",
37 );
38 });
39
40 test("matches exact keys", () => {
41 expect(parseOutputValue("seedAccount 000000000000\n", "account")).toBe(
42 undefined,
43 );
44 });
45});