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

tape-puppet

v0.3.0

Published

duplex stream that runs browserified tape tests with puppeteer

Downloads

78

Readme

tape-puppet

build status AppVeyor Build Status Security Responsible Disclosure


A test runner for browserify'd tape tests, runs puppeteer. Inspired by tape-run. Dead simple.

Features Chromium DevTools debugging and device emulation.

Meant to be used with browserify. If you want this to work with other bundlers open an issue.


Get it!

For npm scripts or programmatic usage:

npm install --save-dev tape-puppet@latest

Globally:

npm install --global tape-puppet@latest

Make sure to also have browserify available.


Usage

Write ordinary tape tests while using browser APIs in your test cases! Check out ./test.js for examples.

CLI

Run below from a terminal or set it as your package.json's test command:

browserify ./test.js | tape-puppet

Run tape-puppet -h for usage instructions:

tape-puppet v0.2.1

A duplex stream that runs browserified tape tests with puppeteer.
Just pipe a browserify stream into this and consume its TAP output.

Usage:

  browserify [opts] [files] | tape-puppet [opts]

Options:

  -h, --help		print usage instructions
  -v, --version		print version
      --headless	run chromium in headless mode; default: true
      --devtools	open devtools; forces !headless; default: false
      --autoclose	close chromium when program completes; default: true
      --debug		Add a breakpoint (debugger) before all code; default: false
      --emulate		emulate a mobile device; fx "iPhone X"
      --devices		list mobile devices that can be emulated
      --cover		Write coverage information to nyc_output.
      --width		chromium window width in px
      --height		chromium window height in px
      --timeout		timeout for chromium launch in ms; default: 30000
      --wait		timeout for tap-finished in ms; default: 1000

Examples:

  browserify ./test.js | tape-puppet
  browserify ./test.js | tape-puppet --devtools
  browserify ./test.js | tape-puppet --headless 0 --emulate "iPhone X"
  browserify ./test.js | tape-puppet > ./test.tap

Debugging

You can have a visible Chromium window pop up by setting option headless to false. Running such a Chromium head allows further debugging. You can automatically open Chromium DevTools by setting option devtools to true. Moreover, an open DevTools tab enables debugger statements in your tape tests, meaning you can literally do sth similar to this:

  1. Throw debugger statements into your tape test cases:
// example ./test.js
const tape = require('tape')

tape('a debug test', t => {
  var y, z = 'v'
  ;debugger;
  t.equal(y, z, 'y equals z')
  t.end()
})
  1. Run tape-puppet in non-headless mode and with DevTools:
browserify ./test.js | tape-puppet --devtools

A Chromium head plus its DevTools will open and script execution will pause at the specified breakpoints...happy debugging!

  1. Run tape-puppet in non-autoclose mode and with DevTools:
browserify ./test.js | tape-puppet --autoclose false

A Chromium browser will open and it will stay opened until you manually close it, this allows you to debug the HTML with the DOM inspector even after all the tests have passed successfully.

  1. Run tape-puppet with --debug

If you want to step throw all the code and figure out what's going on in node_modules before your tests or you want to add breakpoints in the chrome devtools manually without ;debugger; in the source code you can open the tests with --debug

browserify ./test.js | tape-puppet --autoclose false --debug

This will cause the devtools to be paused before we evaluate any of the javascript from browserify ./test.js and allows you to use the DevTools before any code from node_modules is run.

Code coverage

It's possible to use existing techniques for browser code coverage with tape-puppet.

For example

browserify ./test.js -t browserify-istanbul | tape-puppet --cover

The browserify-istanbul transformation will instrument your bundle with code coverage information.

The --cover flag for tape-puppet will output the code coverage from the puppeteer process into ./.nyc_output.

Now you can run nyc report

nyc report

To view the code coverage report of the puppeteer program.

Emulation

A set of mobile devices can be emulated by setting option emulate to a device name string. CLI example:

browserify ./test.js | tape-puppet --emulate "iPhone X"

List the names of all covered devices by setting option devices. CLI example:

tape-puppet --devices

node

new TapePuppetStream([opts])

Create a new TapePuppetStream instance, a transform stream. See above for available options. Note that options emulate and devices are available with the CLI only. Moreover, dictating window width and height programmatically requires setting opts.args to an array that includes a string like --window-size=${width},${height}.

The implementation is nothing more than a duplex stream. Pipe it, pump it, whatever...


License

MIT