npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

scuttle-playbook

v0.1.1

Published

Easily test states in complex SSB apps

Downloads

3

Readme

scuttle-playbook

ALICE: Knock knock.

BOB: Who's there?

ALICE: Scuttlebutt.

BOB: Scuttlewhat??

Playbooks help you write tests for complex Secure Scuttlebutt apps. If you have app that builds up a complex state (such as a flumeview) from a series of messages that have been published by a number of parties, Playbooks can help with that.

A Playbook is a light structure that lets you define a "script" with one or more "actors" (users with their own key). Each line of the script specifies either a message to publish, or a test to run. The playbook ensures that each step only runs after the last has completed. It also handles creating and tearing down temporary scuttlebot servers as well as allocating feeds for the actors.

Message steps

A message step looks like step.message(actor, data) or step.message(actor, label, data)

// no label
step.message(actor, {
  type: 'test',
  moreStuff: 'whatever you want!'
})

// with label
step.message(actor, 'label' {
  type: 'test',
  moreStuff: 'whatever you want!'
})

Test steps

A test step is just a function. To handle asynchronous tests, your function can accept done, which you can call when the test is over, like this:

step.test(done => {
  sbot.whoami((err, me) => {
    t.ok(me)
    done()
  })
})

If your test is purely synchronous, you can omit the done parameter and the playbook will continue after your function completes:

step.test(() => {
  t.equal(1 + 1, 2)
  t.equal(e**(i * pi) + 1, 0)
})

Let's see how you can compose these steps together to create a playbook script.

Usage

Here's a simple example for how you might test the recognition of friendship based on mutual following. It has two actors, alice and bob, and the script has six steps:

  1. publish message: alice follows bob
  2. test: that bob shows up in alice's follow graph
  3. publish message: bob follows alice
  4. test: that alice shows up in bob's follow graph and that they are friends
  5. publish message: alice unfollows bob
  6. test: that they are no longer friends

Skipping over the details of doing the actual testing, it might look something like this:

const Playbook = require('scuttle-playbook')
                 .use(whatever)
                 .use(you)
                 .use(want)

// define the script
const script = sbot => (alice, bob) => [
  step.message(alice, {
    type: 'contact',
    contact: bob.id,
    following: true
  }),
  step.test(done => {
    sbot.testThatAliceFollowsBob((err, data) => done())
  }),
  step.message(bob, {
    type: 'contact',
    contact: alice.id,
    following: true
  }),
  step.test(done => {
    sbot.testThatBobAndAliceAreNowFriends((err, data) => done())
  }),
  step.message(alice, {
    type: 'contact',
    contact: bob.id,
    following: false
  }),
  step.test(done => {
    sbot.testThatAliceAndBobAreNoLongerFriends((err, data) => done())
  }),
]

const finale = () => console.log('all done')

// run it
Playbook(script, finale)

A little explanation

Note that the script takes a function with a signature like

(sbot) => (actors) => [script]

The Playbook creates an sbot instance for you and passes it in. After that, it will create actors for you based on how many parameters you specify in the second set of parameters. For instance, if your function looks like this:

sbot => (alvin, simon, theodore, larry, curly, moe) => [...]

then you will have six actors available in your script.

Examples using actual testing frameworks

See examples/ for examples of real tests using the tape test harness. Note that scuttle-playbook is designed to let you use whatever test runner you want.

Under the hood

Each time you run a script with Playbook(), a scuttlebot instance is created and destroyed. The instance is created with the {temp: true} option, which means your data will not be affected, and test data won't linger after a test is run.

Anything you pass to Playbook.use() is passed directly on to scuttlebot, so the instance that gets created will contain whatever plugins you used.

TODO

  • Document refs
  • Demonstrate script composition

Install

With npm installed, run

$ npm install scuttle-playbook