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

mobile-preview-comment.test.cjs

62 lines2.3 KB

1const assert = require("node:assert/strict");
2const test = require("node:test");
3​
4const { mergeState, readState, render } = require("./mobile-preview-comment.cjs");
5​
6const fingerprint = "c31608b37a8a2dca35ccee39cfd2ec7305042629";
7const run = "https://github.com/pingdotgg/t3code/actions/runs/1";
8​
9test("the comment round-trips its state", () => {
10 const state = { fingerprint, client: "", group: "8e413a0a" };
11 const body = render(state, run);
12 assert.deepEqual(readState(body), state);
13 assert.match(
14 body,
15 /Building on Blacksmith \(\[run\]\(https:\/\/github\.com\/pingdotgg\/t3code\/actions\/runs\/1\)\)/,
16 );
17 assert.match(
18 body,
19 /qr\.expo\.dev\/eas-update\?appScheme=t3-code&projectId=[0-9a-f-]+&groupId=8e413a0a/,
20 );
21 assert.equal(readState("🚀 Expo continuous deployment is ready!"), null);
22});
23​
24test("the build job adds the install link without losing the update", () => {
25 const first = mergeState(null, { fingerprint, client: "", group: "8e413a0a" });
26 const built = mergeState(first, { fingerprint, client: "https://expo.dev/a/b", group: "" });
27 assert.deepEqual(built, { fingerprint, client: "https://expo.dev/a/b", group: "8e413a0a" });
28 assert.match(render(built, run), /Dev client \| \[Install\]\(https:\/\/expo\.dev\/a\/b\)/);
29});
30​
31test("a new fingerprint drops the old client; the same one keeps it", () => {
32 const built = { fingerprint, client: "https://expo.dev/a/b", group: "old" };
33 assert.deepEqual(mergeState(built, { fingerprint, client: "", group: "new" }), {
34 fingerprint,
35 client: "https://expo.dev/a/b",
36 group: "new",
37 });
38 assert.deepEqual(mergeState(built, { fingerprint: "f".repeat(40), client: "", group: "new" }), {
39 fingerprint: "f".repeat(40),
40 client: "",
41 group: "new",
42 });
43});
44​
45test("a build that finishes after the PR moved to another fingerprint changes nothing", () => {
46 const current = { fingerprint: "f".repeat(40), client: "", group: "new" };
47 assert.deepEqual(
48 mergeState(current, { fingerprint, client: "https://expo.dev/a/b", group: "" }),
49 current,
50 );
51});
52​
53test("state from the comment is always three strings", () => {
54 assert.deepEqual(
55 readState('<!-- mobile-preview-android {"fingerprint":5,"client":null} -->\nx'),
56 {
57 fingerprint: "",
58 client: "",
59 group: "",
60 },
61 );
62});