Skip to content

Commit d24a21c

Browse files
committed
test(socials): skip the PWA composer test when express is absent
apps/pwa is not a pnpm workspace package, so the root `pnpm install` never installs its dependencies and CI's root `node --test` cannot resolve express. The composer test imported the route module statically, so that resolution failure crashed the file instead of skipping it. Probe for express with createRequire and defer the route import, matching the guard the other 38 PWA tests already use.
1 parent ae99fd3 commit d24a21c

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

apps/pwa/test/socials.test.mjs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
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.
16
import assert from "node:assert/strict";
7+
import { createRequire } from "node:module";
28
import test from "node:test";
39

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+
}
517

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();
827
assert.match(html, /window\.nostr\.js@0\.5\.0\/dist\/window\.nostr\.min\.js/);
928
assert.match(html, /window\.nostr\.getPublicKey\(\)/);
1029
assert.match(html, /window\.nostr\.signEvent\(/);
1130
});
1231

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();
1534
assert.match(html, /kind: 1/);
1635
assert.match(html, /\["EVENT", event\]/);
1736
for (const relay of NOSTR_RELAYS) assert.ok(html.includes(relay), `${relay} is not rendered`);
1837
});
1938

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();
2241
assert.match(html, /location\.hash\.slice\(1\)/);
2342
assert.doesNotMatch(html, /location\.search/);
2443
});

0 commit comments

Comments
 (0)