Back to Napcraft
SOURCE / PINNED RELEASE

Made of little things.

Napcraft

Release
ee47ac6a25df…
Author-recorded commit
410dea87e109…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-52f9e22f5ce

Archive hash verified: 9e6e0cabb18d0d46…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

tests/browser-support.mjs
// Trusted host-side test utilities. Ephemeral test identities never enter the app.
import { readdir } from 'node:fs/promises';
import { execFileSync } from 'node:child_process';
import { pathToFileURL } from 'node:url';
import path from 'node:path';
const root = path.resolve(import.meta.dirname, '..');
const packages = await readdir(path.join(root, 'node_modules/.pnpm'));
async function dependency(prefix, file) {
  const name = packages.find((n) => n.startsWith(prefix));
  if (!name) throw new Error(`Missing pinned test dependency ${prefix}`);
  return import(
    pathToFileURL(
      path.join(root, 'node_modules/.pnpm', name, 'node_modules', file),
    ).href
  );
}
export const { chromium } = await dependency(
  'playwright@',
  'playwright/index.mjs',
);
const { generateSecretKey, getPublicKey, finalizeEvent } = await dependency(
  'nostr-tools@',
  'nostr-tools/lib/esm/pure.js',
);
export async function installTestIdentity(page, options = {}) {
  const secret = generateSecretKey(),
    pubkey = getPublicKey(secret);
  const signing = [];
  await page.exposeFunction('testPublicKey', () => pubkey);
  await page.exposeFunction('testSignEvent', async (event) => {
    const start=Date.now();
    if (options.signDelayMs) await new Promise(r=>setTimeout(r,options.signDelayMs));
    const signed=finalizeEvent(event,secret);
    signing.push({start,finished:Date.now(),kind:event.kind});
    return signed;
  });
  const inject = () => {
    window.nostr = {
      getPublicKey: () => window.testPublicKey(),
      signEvent: (e) => window.testSignEvent(e),
    };
  };
  await page.addInitScript(inject);
  await page.evaluate(inject);
  return { pubkey, signing };
}
export async function connectTestIdentity(page) {
  const {pubkey}=await installTestIdentity(page);
  await page.locator('#connect').click();
  await page.getByRole('button', { name: 'Disconnect', exact: true }).waitFor();
  return pubkey;
}
export function approveLocalPrompts(page) {
  let stopping = false;
  const loop = async () => {
    while (!stopping && !page.isClosed()) {
      try {
        const button = page.locator('#prompt[open] #confirm');
        if (await button.isVisible()) await button.click({ timeout: 500 });
      } catch {}
      await new Promise((r) => setTimeout(r, 100));
    }
  };
  void loop();
  return () => (stopping = true);
}
export const executable = process.env.NAPCRAFT_BROWSER ||
  JSON.parse(execFileSync('soyli',['browser','path','--json'],{encoding:'utf8'}))
    .executables.find(e => e.installed && e.name.startsWith('chromium'))?.path;
if (!executable) throw new Error('Run soyli browser install before hosted browser tests.');
export async function frameOf(page) {
  await page.locator('#stage iframe').waitFor();
  const handle = await page.locator('#stage iframe').elementHandle();
  const frame = await handle.contentFrame();
  await frame.locator('#app[data-ready=true]').waitFor();
  return frame;
}
export async function fitFrame(page, width, height) {
  await page.setViewportSize({ width, height });
  await page.addStyleTag({
    content: `body{margin:0!important}body>header,body>#status,body>#media{display:none!important}#stage{margin:0!important;padding:0!important;width:${width}px!important;height:${height}px!important}#stage iframe{display:block!important;width:${width}px!important;height:${height}px!important;min-height:0!important;border:0!important}`,
  });
  const frame = await frameOf(page);
  await frame.waitForFunction(
    ([w, h]) => innerWidth === w && innerHeight === h,
    [width, height],
    { timeout: 3000 },
  );
  const size = await frame.evaluate(() => [innerWidth, innerHeight]);
  if (size[0] !== width || size[1] !== height)
    throw new Error(`Actual frame ${size} != ${width},${height}`);
  return frame;
}