|
| 1 | +// Unit tests for the browser-side Nostr composer. |
| 2 | +// |
| 3 | +// Same shape as the other PWA tests: the route module pulls in express at load |
| 4 | +// time, so probe for it first and skip cleanly when the PWA dependencies aren't |
| 5 | +// installed — that keeps the root `pnpm test` green in a fresh clone. |
1 | 6 | import assert from "node:assert/strict"; |
| 7 | +import { createRequire } from "node:module"; |
2 | 8 | import test from "node:test"; |
3 | 9 |
|
4 | | -import { NOSTR_RELAYS, nostrComposerPage } from "../src/routes/socials.mjs"; |
| 10 | +const require = createRequire(import.meta.url); |
| 11 | +let hasDeps = true; |
| 12 | +try { |
| 13 | + require("express"); |
| 14 | +} catch { |
| 15 | + hasDeps = false; |
| 16 | +} |
5 | 17 |
|
6 | | -test("Nostr composer loads the pinned NIP-07/NIP-46 bridge", () => { |
7 | | - const html = nostrComposerPage(); |
| 18 | +const skip = hasDeps ? false : "PWA dependencies are not installed"; |
| 19 | + |
| 20 | +async function composer() { |
| 21 | + const { NOSTR_RELAYS, nostrComposerPage } = await import("../src/routes/socials.mjs"); |
| 22 | + return { NOSTR_RELAYS, html: nostrComposerPage() }; |
| 23 | +} |
| 24 | + |
| 25 | +test("Nostr composer loads the pinned NIP-07/NIP-46 bridge", { skip }, async () => { |
| 26 | + const { html } = await composer(); |
8 | 27 | assert.match(html, /window\.nostr\.js@0\.5\.0\/dist\/window\.nostr\.min\.js/); |
9 | 28 | assert.match(html, /window\.nostr\.getPublicKey\(\)/); |
10 | 29 | assert.match(html, /window\.nostr\.signEvent\(/); |
11 | 30 | }); |
12 | 31 |
|
13 | | -test("Nostr composer creates kind-1 events and publishes to every named relay", () => { |
14 | | - const html = nostrComposerPage(); |
| 32 | +test("Nostr composer creates kind-1 events and publishes to every named relay", { skip }, async () => { |
| 33 | + const { NOSTR_RELAYS, html } = await composer(); |
15 | 34 | assert.match(html, /kind: 1/); |
16 | 35 | assert.match(html, /\["EVENT", event\]/); |
17 | 36 | for (const relay of NOSTR_RELAYS) assert.ok(html.includes(relay), `${relay} is not rendered`); |
18 | 37 | }); |
19 | 38 |
|
20 | | -test("Nostr composer reads the draft from the fragment", () => { |
21 | | - const html = nostrComposerPage(); |
| 39 | +test("Nostr composer reads the draft from the fragment", { skip }, async () => { |
| 40 | + const { html } = await composer(); |
22 | 41 | assert.match(html, /location\.hash\.slice\(1\)/); |
23 | 42 | assert.doesNotMatch(html, /location\.search/); |
24 | 43 | }); |
0 commit comments