aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/jade
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-01-30 18:14:26 -0800
committerAdam Soltys <[email protected]>2018-01-30 18:14:36 -0800
commit709d1f04d073d9b46e42819bd0224da6a4157814 (patch)
tree4799253ecc1f93882e98cbd2f62f56454329c7d8 /node_modules/jade
parentde4d44a58f6bb49d5762632d2cad96e1dc96c56f (diff)
downloadcoinos-server-709d1f04d073d9b46e42819bd0224da6a4157814.tar.gz
coinos-server-709d1f04d073d9b46e42819bd0224da6a4157814.zip
rpc and zmq demo
Diffstat (limited to 'node_modules/jade')
0 files changed, 0 insertions, 0 deletions
ighlight .c1 { color: #888 } /* Comment.Single */ .highlight .cs { color: #C00; font-weight: bold; background-color: #FFF0F0 } /* Comment.Special */ .highlight .gd { color: #000; background-color: #FDD } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #A00 } /* Generic.Error */ .highlight .gh { color: #333 } /* Generic.Heading */ .highlight .gi { color: #000; background-color: #DFD } /* Generic.Inserted */ .highlight .go { color: #888 } /* Generic.Output */ .highlight .gp { color: #555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666 } /* Generic.Subheading */ .highlight .gt { color: #A00 } /* Generic.Traceback */ .highlight .kc { color: #080; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #080; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #080; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #080 } /* Keyword.Pseudo */ .highlight .kr { color: #080; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #00D; font-weight: bold } /* Literal.Number */ .highlight .s { color: #D20; background-color: #FFF0F0 } /* Literal.String */ .highlight .na { color: #369 } /* Name.Attribute */ .highlight .nb { color: #038 } /* Name.Builtin */ .highlight .nc { color: #B06; font-weight: bold } /* Name.Class */ .highlight .no { color: #036; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555 } /* Name.Decorator */ .highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// Real reply buttons/composer with controlled relay replies and no publishing.
// Run: bun tools/thread-reply-test.js
import assert from 'node:assert/strict';
import puppeteer from './puppeteer.js';
const app = await Bun.file('src/app.js').text();
const dom = app.slice(app.indexOf('function h(tag,'), app.indexOf('// ---------------------------------------------------------------- morphing'));
const entry = `
import { messagesFeature } from './src/features/messages.js';
import { createThreadStore } from './src/thread-cache.js';
import './src/rich-text.js'; // <coinos-text>, the reply field (app.js registers it)
${dom}
const author = 'a'.repeat(64), mine = 'b'.repeat(64), rootId = 'c'.repeat(64);
const root = { id: rootId, pubkey: author, kind: 1, content: 'Root post', tags: [], created_at: 1 };
const reply = { ...root, id: 'd'.repeat(64), content: 'The reply you tapped', tags: [['e', rootId, '', 'root']], created_at: 2 };
const other = { ...reply, id: 'e'.repeat(64), content: 'Another reply not returned by the relay', created_at: 3 };
const ui = { screen: 'wallet' }, waiting = [];
window.sent = [];
// the root (asked for by id, any kind) and its replies are held until the test lets them go
window.query = filter => filter.ids || (filter.kinds?.[0] === 1 && filter['#e']) ? new Promise(resolve => waiting.push({ filter, resolve })) : Promise.resolve([]);
const signer = { signEvent: async e => ({ ...e, id: 'f'.repeat(64), pubkey: mine }) };
let feature;
// (a wallet is open: without one the app is a visitor's, and Reply asks you to sign in)
const wallet = { xpub: 'test-wallet', loaded: true, nostrRelays: () => [], loadFeatureState: (k, d) => d, saveFeatureState() {} };
function render() {
  if (!feature) return;
  document.querySelector('#app').replaceChildren(feature.screenView() || feature.row(author, reply, 'Someone'));
}
feature = messagesFeature({ h, wallet, ui, render, toast() {}, brandHeader: () => window.test?.showNav
  ? h('div', { style: 'height:60px' }) : null,
  hook: k => k === 'nostrLoginIdentity' ? { pubkey: mine, signer } : null });
window.test = { ui, reply, other, root, render, waiting, showNav: false,
  held: () => waiting.some(q => q.filter.ids) && waiting.some(q => q.filter['#e']),
  stable: () => feature.testStable(),
  seedFace: () => createThreadStore().save({ root, replies: [reply] }, reply.id, {
    [author]: { name: 'Nostrich', picture: 'https://example.com/nostrich.webp', eventAt: 10, t: Date.now(),
      thumbFor: 'https://example.com/nostrich.webp', thumb: 'data:image/png;base64,iVBORw0KGgo=', thumbPx: 144 },
  }, { [reply.id]: { likes: 29, boosts: 7, sats: 210 } }),
  release: () => { for (const q of waiting.splice(0)) q.resolve(q.filter.ids ? [root] : []); },
  overlay: () => {
    ui.profilePk = author; ui.profOverThread = true; render();
    document.querySelector('#outside').replaceChildren(feature.actions(author, other, { canZap: false }));
  },
  missing: () => {
    const ev = { ...other, id: '1'.repeat(64), tags: [['e', '2'.repeat(64), '', 'root']] };
    document.querySelector('#outside').replaceChildren(feature.actions(author, ev, { canZap: false }));
  },
  empty: () => { for (const q of waiting.splice(0)) q.resolve([]); },
};
render();
`;
const bundle = await Bun.build({ entrypoints: ['thread-test-entry'], target: 'browser', plugins: [{ name: 'thread-test', setup(build) {
  build.onResolve({ filter: /^thread-test-entry$/ }, () => ({ path: 'entry', namespace: 'thread-test' }));
  build.onLoad({ filter: /.*/, namespace: 'thread-test' }, () => ({ contents: entry, loader: 'js', resolveDir: process.cwd() }));
  build.onLoad({ filter: /src\/features\/messages\.js$/ }, async ({ path }) => ({ loader: 'js', contents: (await Bun.file(path).text())
    .replace("id: 'messages',", "id: 'messages', row: noteRow, actions: noteActions, testStable: renderThreadStable,") }));
  build.onLoad({ filter: /src\/nostr\.js$/ }, async ({ path }) => ({ loader: 'js', contents: (await Bun.file(path).text())
    .replace('export async function queryOn(relays, filter, maxWait = 1500) {', 'export async function queryOn(relays, filter, maxWait = 1500) { return window.query(filter);')
    .replace('export async function publishOn(relays, evt) {', 'export async function publishOn(relays, evt) { window.sent.push(evt); return true;')
    .replace(/export function subscribeOn\(([^)]*)\) \{/, 'export function subscribeOn($1) { return () => {};') }));
} }] });
assert(bundle.success, bundle.logs.join('\n'));
const html = `<!doctype html><meta charset="utf-8"><style>${await Bun.file('src/style.css').text()}</style><div id="app"></div><div id="outside"></div><input id="elsewhere"><script type="module">${await bundle.outputs[0].text()}</script>`;
const server = Bun.serve({ port: 0, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) });
const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: true, args: ['--no-sandbox'] });
const page = await browser.newPage(), errors = [];
page.on('pageerror', e => errors.push(e.message));
await page.setRequestInterception(true);
page.on('request', r => r.url().startsWith(server.url.origin) ? r.continue() : r.abort());
const check = (name, value) => { assert(value, name); console.log('✓ ' + name); };
const inline = () => page.evaluate(() => {
  const input = document.querySelector('.thread-reply-input');
  const box = input?.closest('.thread-reply'); // the field sits directly in the box now, tools on a row beneath
  return !!input && box.previousElementSibling?.dataset.zapPost === test.ui.noteThread.focusId;
});
try {
  await page.goto(server.url.href);
  await page.waitForSelector('#app .note-act');
  await page.click('#app .note-act');
  check('Reply immediately shows its composer beneath the tapped post', await inline());
  check('the input receives focus before relay queries finish', await page.evaluate(() => document.activeElement.matches('.thread-reply-input')));
  await page.type('.thread-reply-input', 'A reply before the root loads');
  // (one atomic tap: a repaint landing between finding the button and clicking it replaces it)
  await page.waitForFunction(() => !document.querySelector('.thread-reply-send')?.disabled);
  await page.evaluate(() => document.querySelector('.thread-reply-send').click());
  await page.waitForFunction(() => sent.length === 1);
  check('publishing targets the selected reply and its original root', await page.evaluate(() => sent[0].tags.some(t => t[0] === 'e' && t[1] === test.reply.id && t[3] === 'reply') && sent[0].tags.some(t => t[0] === 'e' && t[1] === test.root.id && t[3] === 'root')));
  await page.waitForFunction(() => test.held());
  await page.evaluate(() => test.release());
  await page.waitForFunction(() => document.body.innerText.includes('Root post'));
  // the composer folds away once the reply is sent; the tapped reply itself stays
  check('a relay result omitting the tapped reply keeps it (composer folded after sending)', await page.evaluate(() =>
    !!document.querySelector('[data-zap-post="' + test.ui.noteThread.focusId + '"]') && !document.querySelector('.thread-reply-input')));
  await page.evaluate(() => test.overlay());
  check('fixture starts with a profile covering the existing thread', await page.evaluate(() => test.ui.profOverThread && !document.querySelector('.thread-reply-input')));
  await page.click('#outside .note-act');
  check('Reply leaves the covering profile and inserts an uncached reply into the thread', await inline() && await page.evaluate(() => !test.ui.profOverThread && document.activeElement.matches('.thread-reply-input')));
  await page.evaluate(() => test.missing());
  await page.click('#outside .note-act');
  await page.waitForFunction(() => test.held());
  await page.evaluate(() => test.empty());
  await page.waitForFunction(() => !document.querySelector('#app .spinner'));
  check('an unavailable root still leaves the selected post replyable', await inline());
  await page.evaluate(() => { test.ui.noteThread = null; test.ui.profilePk = null; test.render(); document.querySelector('#elsewhere').focus(); });
  await new Promise(r => setTimeout(r, 120));
  check('deferred focus does not steal focus after leaving the thread', await page.evaluate(() => document.activeElement.id === 'elsewhere'));
  await page.evaluate(() => test.seedFace());
  await page.reload();
  await page.waitForSelector('#app .note-act');
  await page.click('#app .note-act');
  check('cached thread author paints with name and local face on first frame', await page.evaluate(() => {
    const row = document.querySelector('.thread-page [data-zap-post]');
    return row?.textContent.includes('Nostrich') && row.querySelector('.note-avatar.ava-img')?.style.backgroundImage.includes('data:image/png;base64');
  }));
  check('cached likes, boosts and sats paint before relay replies', await page.evaluate(() => {
    const row = [...document.querySelectorAll('.thread-page [data-zap-post]')]
      .find((el) => el.dataset.zapPost === test.reply.id);
    const buttons = row?.querySelectorAll('.note-acts > button');
    return buttons?.[1].textContent === '7' && buttons?.[3].textContent === '29' && buttons?.[4].textContent === '210';
  }));
  await new Promise((r) => setTimeout(r, 450));
  check('an incomplete relay tally cannot erase the cached numbers', await page.evaluate(() => {
    const row = [...document.querySelectorAll('.thread-page [data-zap-post]')]
      .find((el) => el.dataset.zapPost === test.reply.id);
    const buttons = row?.querySelectorAll('.note-acts > button');
    return buttons?.[1].textContent === '7' && buttons?.[3].textContent === '29' && buttons?.[4].textContent === '210';
  }));
  await page.evaluate(() => {
    document.querySelector('#outside').style.height = '2000px';
    window.scrollTo(0, 0);
    test.showNav = true;
    test.stable();
  });
  await new Promise((r) => setTimeout(r, 80));
  check('adding header controls while at the top does not scroll to the first post',
    await page.evaluate(() => window.scrollY === 0));
  assert.deepEqual(errors, []);
  console.log('✓ no browser errors');
} finally { await browser.close(); server.stop(true); }