
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Spin on a test until it passes.
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.
npm install --save-dev spin-test
This module exports a function spin
.
var spin = require('spin-test');
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.
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;
Want the action
to run immediately, not after setImmediate
? We got you covered.
spinner.start();
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);
If you'd like to contribute to or modify spin-test, here's a quick guide to get you started.
Download via GitHub and install npm dependencies:
git clone git@github.com:goinstant/spin-test.git
cd spin-test
npm install
Testing is with the mocha framework.
Tests are located in the test.js
file.
To run the tests:
npm test
npm version patch
(increments x
in z.y.x
, then makes a commit for package.json, tags that commit)git push --tags origin master
npm publish
Go to https://npmjs.org/package/spin-test and verify it published (can take several minutes)
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.
© 2013 GoInstant Inc., a salesforce.com company
Licensed under the BSD 3-clause license.
FAQs
Spin on a test until it passes
The npm package spin-test receives a total of 1 weekly downloads. As such, spin-test popularity was classified as not popular.
We found that spin-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.