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 🙏

© 2026 – Pkg Stats / Ryan Hefner

polytest

v0.0.1

Published

test multiple versions of node dependencies

Readme

Polytest

npm tests dependencies

Test multiple versions of node dependencies

Note: This project is in early development, and versioning is a little different. Read this for more details.

Why should you care?

If you want to run tests in node using multiple versions of one or more dependencies from your package.json file, this is currently not possible, as only one version can be installed at a time. This has been confirmed by Isaacs here. The suggestion he makes for solving the problem is to set up a script that installs multiple versions of the dependency in other directories, which is less than ideal.

This library takes care of the "test multiple version of dependencies" issue without you needing to hack together a script to do so, which turns out to be quite ugly and difficult.

Installation

npm i polytest

Usage

The purpose of this script is to be able to run a specific test suite with a specific set of dependencies, independent of your package.json file. In order to get set up, you must initialize a polytest object with the alternate package.json you want to use and the command to run the tests. As such, the constructor takes two arguments. The first is the command you use to run the test suite, and the second is a JSON object representing a package.json file, or a string that represents a path where one can be loaded. For example:

var Polytest = require('polytest');

module.exports = new Polytest({
  cmd: 'mocha test/old/all.js',
  pkg: 'test/old/package.json'
});

A couple things happening here. First of all, you can see the two arguments as described above -- command to run the tests and path to a package.json file with which to run the tests. These arguments are accepted through an object. The cmd option takes a string, which is a command to be run via command line. The pkg argument takes either a string, which is a path to a package.json file, or an object, which is the contents of a package.json file.

Second, you'll notice these are relative paths. These will be executed relative to the cwd from which polytest is executed. If this is confusing or tripping you up, feel free to simply pass an absolute path. Finally, you'll notice that it returns a stream. The stream will simply pass through the command's output and you can do whatever you'd like with it, in the above example it's just logged through the console.

Now, in order to install the alternate dependencies and run the test suite, you can use polytest.install and polytest.run, respectively.

var polytest = require('./path_to_above_example');

polytest.install(function(){
  polytest.run().pipe(process.stdout);
});

So here, we require the initialized polytest object, install the dependencies, and after this is done, run the tests. polytest.run returns a stream of the test output, and here we simply pipe it to the console, but you can handle it in any way you'd normally handle a stream.

You might be asking, why do we require the polytest instance at the top here, rather than just putting them both in the same file? Well, you also will need to patch your test scripts so that polytest can work correctly, and the test script patch alsp requires the polytest instance.

Fortunately, it's a small and easy patch, just a single line. Here's an example:

polytest = require('./path_to_above_example');
require = polytest.require();

// rest of your test file

NOTE: One of our goals is to have you able to execute a file without polytest and still have it work correctly, even with the path. We have not yet completed this, so at the moment the patch will mess up the file when not run with polytest. We'll remove this note once this is no longer the case!

You will notice that polytest generates a directory at the root of your project to store the node modules according to the package.json that you pass to it. On the initialized polytest instance, the absolute path to this directory can be accessed via polytest.path. If you'd like to get rid of this directory, you can remove it using polytest.remove_modules(callback). If you'd like to keep it, tests will still run and polytest.install() will simply update the dependencies when run. However, I'd advise adding polytest_* to your .gitignore file to make sure these folders are not pushed to git, much like you do with node_modules.

License & Contributing