OverviewFilesCommitsIssuesDocsReleasesPeers

favela-surface / test / boundary.test.js

29 lines · javascript ref:
// The surface holds a socket and nothing else. A renderer that grows a Corestore has become a
// second peer implementation — the same fork risk library.md §1 names for the codec.

import test from 'brittle'
import fs from '#node:fs'
import { join } from '#node:path'

const ROOT = new URL('..', import.meta.url).pathname
const FORBIDDEN = /(atproto-|ap-bridge|corestore|hypercore|autobee|autobase|hyperswarm|hyper-overlay)/

const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((e) =>
  e.name === 'node_modules' || e.name === '.git' ? []
    : e.isDirectory() ? walk(join(dir, e.name))
      : e.name.endsWith('.js') ? [join(dir, e.name)] : [])

test('no source file reaches for storage, a swarm, or a projection', (t) => {
  for (const f of [...walk(join(ROOT, 'lib')), join(ROOT, 'index.js')]) {
    if (!fs.existsSync(f)) continue
    t.absent(FORBIDDEN.test(fs.readFileSync(f, 'utf8')), f.slice(ROOT.length) + ' is a renderer only')
  }
})

test('and neither does a dependency', (t) => {
  const pkg = JSON.parse(fs.readFileSync(join(ROOT, 'package.json'), 'utf8'))
  const deps = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies })
  t.ok(deps.length > 0)
  for (const d of deps) t.absent(FORBIDDEN.test(d), d + ' is not storage or transport')
})