0.60.0 • Published 3 years ago

run-test v0.60.0

Weekly downloads
123
License
-
Repository
github
Last release
3 years ago

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.

0.60.0

3 years ago

0.59.0

4 years ago

0.58.0

5 years ago

0.57.0

5 years ago

0.56.0

5 years ago

0.55.0

5 years ago

0.54.0

5 years ago

0.53.0

5 years ago

0.52.0

5 years ago

0.51.0

6 years ago

0.50.0

6 years ago

0.49.0

6 years ago

0.48.0

7 years ago

0.47.0

7 years ago

0.46.0

7 years ago

0.45.0

7 years ago

0.44.0

7 years ago

0.43.0

7 years ago

0.42.0

7 years ago

0.41.0

7 years ago

0.40.0

7 years ago

0.39.0

7 years ago

0.38.0

7 years ago

0.37.0

7 years ago

0.36.0

7 years ago

0.35.0

7 years ago

0.34.0

7 years ago

0.33.0

7 years ago

0.32.0

7 years ago

0.31.0

7 years ago

1.0.0

8 years ago