1. test-peer-range
Test a package against the full range of major supported versions of a peer dependency
test-peer-range
Package: test-peer-range
Created by: bendrucker
Last modified: Tue, 02 Aug 2022 00:05:23 GMT
Version: 3.0.0
License: MIT
Downloads: 48
Repository: https://github.com/bendrucker/test-peer-range

Install

npm install test-peer-range
yarn add test-peer-range

test-peer-range

Test a package against the full range of major supported versions of a peer dependency

Install

npm install --save-dev test-peer-range

Usage

 test-peer-range browserify

In package.json:

 {
  "name": "transformify",
  "description": "A browserify transform",
  "scripts": {
    "test": "test-peer-range browserify",
    "test-main": "node test.js"
  },
  "devDependencies": {
    "browserify": "16",
    "test-peer-range": "*"
  },
  "peerDependencies": {
    "browserify": ">= 14"
  }
}

The program will execute test-main for each major version (e.g. 14, 15, 16) of the peer. This is useful for maintaining backward compatibility for plugins. As long as the peer dependency follows semver, you can be confident that your code works on old versions while developing against a more recent line.

Arguments are passed through, so running npm test -- --inspect would result in node test.js --inspect as your test command.

CLI

test-peer-range <name>

name

Required
Type: string

The package name of the peer.

--versions

Type: array[string]
Alias: -v
Default: test-main

Additional versions to test, on top of major versions specified in peerDependencies. Repeat this flag to specify multiple versions, e.g. -v 1.2.3 -v 4.5.6.

--command

Type: string
Alias: -c
Default: test-main

A command to run for each version. By default this is expected to be an npm script.

--npm

Type: boolean
Default: true

Disable npm to run the --command directly.

--bail

Type: boolean
Default: false

Exit immediately when any test fails.

API

run(name, range, [options], callback)

name

Required
Type: string

The name of the peer to test against.

range

Required
Type: string

The semver range of the peer versions to use for testing.

options
command

Type: string
Default: test-main

The test command to run.

arguments

Type: array[string]
Default: []

Additional command line arguments to pass to the command. For npm scripts, these will be passed to the script itself, not npm run.

npm

Type: boolean
Default: true

Run the command as an npm script.

bail

Type: boolean
Default: true

Immediately end the run when a test fails.

callback

Required
Type: function
Arguments: err, results[{version, passed}]

The callback to call when done. Receives an array of objects with version (string) and passed (integer) properties.

License

MIT © Ben Drucker

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code