Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mobile-showcase.test.ts

42 lines1.3 KB

1// @effect-diagnostics nodeBuiltinImport:off - expectations mirror the host path joins the script under test performs.
2import { assert, it } from "@effect/vitest";
3import { PNG } from "pngjs";
4​
5import {
6 encodeAndroidPairingUrls,
7 normalizeStorePng,
8 parsePairingCredentialOutput,
9 readPngMetadata,
10} from "./mobile-showcase.ts";
11​
12function rgbaPng(width: number, height: number): Buffer {
13 const png = new PNG({ width, height });
14 png.data.fill(255);
15 return PNG.sync.write(png);
17​
18it("converts simulator RGBA captures to upload-safe 24-bit RGB PNGs", () => {
19 const normalized = normalizeStorePng(rgbaPng(2, 3));
20 assert.deepStrictEqual(readPngMetadata(normalized), {
21 width: 2,
22 height: 3,
23 bitDepth: 8,
24 colorType: 2,
25 hasAlpha: false,
26 });
27});
28​
29it("reads multiline JSON from the pairing CLI", () => {
30 assert.equal(
31 parsePairingCredentialOutput('server log\n{\n "credential": "PAIR-ME"\n}\n'),
32 "PAIR-ME",
33 );
34});
35​
36it("encodes Android pairing URLs without shell-sensitive JSON quotes", () => {
37 const urls = ["http://10.0.2.2:65164/#token=ONE", "http://10.0.2.2:65198/#token=TWO"];
38 const encoded = encodeAndroidPairingUrls(urls);
39 assert.equal(encoded.startsWith("json-uri:"), true);
40 assert.deepStrictEqual(JSON.parse(decodeURIComponent(encoded.slice("json-uri:".length))), urls);
41 assert.equal(encoded.includes('"'), false);
42});