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

spin-test

v1.0.0

Published

Spin on a test until it passes

Downloads

3

Readme

spin-test

Spin on a test until it passes.

Build Status

Inspired by http://sauceio.com/index.php/2011/04/how-to-lose-races-and-win-at-selenium/

SUPER handy for flakey selenium tests where the framework is racing ahead of the browser.

Installation

  npm install --save-dev spin-test

Usage

This module exports a function spin.

  var spin = require('spin-test');

The Basics

All three parameters to spin() are Functions.

  function action(cb) {
    cb(null, result);
  }

  function check(result) {
    // throw or not
  }

  function done(err) {
    // conclude the test
  }

  spin(action, check, done);

The action will be executed on the next tick by setImmediate and runs asynchronously. The callback results of the action (minus the first err param) are passed to the check. If the action calls-back with an err, it will be scheduled to run again after a short period (100ms by default).

The check Function runs synchronously. If the check doesn't throw, done will get called.

If the check does throw an exception, the action is scheduled to happen again after a short period (100ms by default). Once the spinner has been running for a maximum amount of time (4000ms by default) done will get called with an error.

Configuring Intervals

You can affect all newly created spinners by setting spin package globals:

  spin.TIMEOUT = 1000; // maximum run time of the spinner, in ms
  spin.WAIT = 10;      // time to wait between attempts, in ms

To restore these:

  spin.TIMEOUT = spin.DEFAULT_TIMEOUT;
  spin.WAIT = spin.DEFAULT_WAIT;

Or, you can modify the times for each test:

  var spinner = spin(action, check, done);
  spinner.timeout = 1000;
  spinner.wait = 10;

Impatience

Want the action to run immediately, not after setImmediate? We got you covered.

  spinner.start();

Error Accumulator

The .errors property will be an array of Errors that occurred while spinning.

  var spinner;

  function finish(err) {
    if (!err) {
      return done();
    }

    process.stderr.write("Oh my gawd, it's full of STACKS:\n");
    spinner.errors.forEach(function(e) {
      process.stderr.write(e.stack+"\n\n");
    );
  }

  spinner = spin(action, check, finish);

Contributing

If you'd like to contribute to or modify spin-test, here's a quick guide to get you started.

Development Dependencies

Set-Up

Download via GitHub and install npm dependencies:

git clone [email protected]:goinstant/spin-test.git
cd spin-test
npm install

Testing

Testing is with the mocha framework. Tests are located in the test.js file.

To run the tests:

npm test

Publishing

  1. npm version patch (increments x in z.y.x, then makes a commit for package.json, tags that commit)
  2. git push --tags origin master
  3. npm publish

Go to https://npmjs.org/package/spin-test and verify it published (can take several minutes)

Support

Email GoInstant Support or stop by #goinstant on freenode.

For responsible disclosures, email GoInstant Security.

To file a bug or propose a patch, please use github directly.

Legal

© 2013 GoInstant Inc., a salesforce.com company

Licensed under the BSD 3-clause license.