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

run-test

v0.60.0

Published

Define tests with dependencies

Downloads

105

Readme

Run-test lets you define tests in the same file where you define their dependencies:

var runTest = require("run-test")(require)

runTest(
  "a button tells us who's good",
  ["web-site", "browser-bridge", "web-element", "browser-task"],
  function(expect, done, WebSite, BrowserBridge, element, browserTask) {
    var site = new WebSite()
    var bridge = new BrowserBridge()

    var sayWhosGood = bridge.defineFunction(
      function sayWhosGood() {
        document.write("Prince")
      }
    )

    var button = element("button", "Who's good?", {onclick: sayWhosGood.evalable()})

    site.addRoute("get", "/", bridge.sendPage(button))

    site.live()

    var browser = browserTask(
      site.url(), function() {
      browser.pressButton(checkWho)
    })

    function checkWho() {
      browser.assertText("body", /Prince/, browser.done, done)
    }
  }
)

One test at a time

runTest.only("currying")

runTest("currying", function(expect, done) {
  expect("curry").to.contain("cur")
  done()
})

runTest("salading", function(expect, done) {
  throw new Error("This test will never run")
  expect("salad").to.contain("sal")
  done()
})

You have to do this at the top of the file, because runTest is eager: it will just start running tests as soon as you define them.

Partly passing

Note that a test has partially passed to make it easier to figure out where complicated tests when wrong:

runTest(
  "adding",
  function(expect, done) {
    var a = 2 + 4
    expect(a).to.equal(6)
    done.ish("add two numbers")

    var b = a + 5
    expect(b).to.equal(11)
    done.ish("adding to a variable")

    done()
  })

Why

This makes it possible to hot reload modules when they change and re-run just the individual tests that depend on them.

I haven't written that test runner yet, but I wanted to set this standard so that the tests don't have to be rewritten when we have a global autonomous test runner up.

And in general, we try always to write code that describes its prerequisites in software.

Random thoughts on testing

Wondering whether you should write a test? Ask yourself, if this stopped working, and none of our collaborators noticed, would it matter? If so, write the test.