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

tapdance

v5.1.1

Published

Test harness that emits the Test Anything Protocol (TAP).

Downloads

123

Readme

Tapdance

Build Status npm Version License

Test harness that emits the Test Anything Protocol (TAP). It runs in Node.js and web browsers, and is written in literate Parenscript (Common Lisp).

$ npm install tapdance

Usage

When the test exits, Tapdance will return a 0 exit code if nothing went wrong, and a non-zero exit code otherwise. There is no need to manually call when a test ends.

tapdance(fn)

Run a function which may return a Promise. Calls to runTest get collected synchronously and run in sequential order in the next tick, which is useful when splitting up asynchronous tests in different files. The fn accepts two arguments, assert and comment.

assert(value, [message])

Check if a value is truthy or not.

comment([message])

Output a comment line.

runTest.assert

This can be overridden to use a different assert function.

Building

You will need a Common Lisp implementation like SBCL, and wget. If installing the developer dependencies didn't work the first time, you may need to cd node_modules/sigil-cli && make.

License

This software is licensed under the MIT License.

Code

Here's the full source code.

"use strict"
(defvar *assert* (require "assert"))

Check if it's running in Node.js, this determines whether or not to call Node.js specific APIs.

(defvar *is-node*
 (and (not (eq (typeof process) 'undefined))
      (eq (typeof (@ process exit)) 'function)
      (eq (typeof (@ process next-tick)) 'function)))

Initialize the local state of the program which is read & written later.

(defvar *start-time* ((@ *date now)))
(defvar *stack* (array))
(defvar *count* 0)
(defvar *passing* 0)

A bit a ceremony is needed to kick off the TAP output. This kicks off the running of tests.

(println "TAP version 13")
(if *is-node*
    (progn ((@ process on) 'exit exit)
           ((@ process next-tick) flush))
  (set-timeout flush 0))

Define the main public function, it accepts a test function that takes two arguments, assert and comment.

(setf (@ module exports) run-test)
(setf (@ run-test assert) *assert*)
(defun run-test (fn)
  (defun assert (exp message)
    (incf *count*)
    (try
      (progn ((@ run-test assert) exp)
             (incf *passing*)
             (println (+ "ok " *count* " " message)))
      (:catch (error)
        (println (+ "not ok " *count* " " message))
        (show-error error))))
  (defun comment (message) (println (+ "# " message)))
  ((@ *stack* push) (lambda () (fn assert comment))))

This is an implementation detail which runs all of the testing functions in the order that they are declared.

(defun flush ()
  ((@ ((@ *stack* reduce)
       (lambda (chain fn)
         ((@ ((@ chain then) fn) catch)
          (lambda (error)
            (progn
              (incf *count*)
              (println (+ "not ok " *count* " " (@ error message)))
              (show-error error)))))
       ((@ *promise resolve))) then)
   (lambda () (if *is-node* ((@ process exit)) (exit)))))

Upon exiting, print the results as well as some useful information such as how many tests failed and how long it took.

(defun exit ()
  (if *is-node*
      (setf (@ process exit-code)
            (if (and *count* (eq *count* *passing*)) 0 1)))
  (if (not *count*)
      (progn (incf *count*) (println "not ok 1 no tests found")))
  (println (+ "1.." *count*))
  (println)
  (if (eq *count* *passing*)
      (println "# all tests passed")
    (let ((failing (- *count* *passing*)))
      (println
       (+ "# " failing " test" (if (> failing 1) "s" "") " failed"))))
  (println
   (+ "# test finished in " (- ((@ *date now)) *start-time*) " ms"))
  (println))

Internal function to pretty print errors that happen while running tests.

(defun show-error (error)
  (println "  ---")
  (println (+ "  name: " (@ error name)))
  (if ((@ (regex "\\n") test) (@ error message))
      (progn
        (println "  message:")
        ((@ ((@ error message split) #\linefeed) map)
         (lambda (line)
           (println (+ "    - " line)))))
    (progn
      (println (+ "  message: " (@ error message)))
      (if (@ error stack)
          (progn
            (println "  stack:")
            ((@ ((@ error stack split) #\linefeed) for-each)
             (lambda (line)
               (setf line ((@ line trim)))
               (if (not (eq ((@ line index-of) (@ error name)) 0))
                   (println (+ "    - " line)))))))))
  (println "  ..."))

Internal function to print lines while escaping new lines in the input.

(defun println (str)
  ((@ console log)
   (if str ((@ str replace) #\linefeed "") "")))