Registry / testing / promises-aplus-tests

promises-aplus-tests

JSON →
library2.1.2jsnpmunverified

This package provides the official compliance test suite for the Promises/A+ specification, currently at version 2.1.2. It is designed to verify that a promise implementation correctly adheres to the `then()` method behavior defined in the Promises/A+ specification. The suite can be run in both Node.js and browser environments, requiring a minimal adapter interface from the promise library under test. Key differentiators include its status as the authoritative test suite for the specification, allowing compliant libraries to display the Promises/A+ logo. Releases appear to be driven by specification updates and maintenance, with the last major update (v2.0.0) aligning with Promises/A+ v1.1. It ensures comprehensive test coverage for various promise states and operations, making it an essential tool for promise library authors.

npm install promises-aplus-tests
INSTALL
IMPORT
SIG · PROMISES-APLUS-TES
P
promises-aplus-tests
testingjavascriptv2.1.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import promisesAplusTests from 'promises-aplus-tests';
✗ const promisesAplusTests = require('promises-aplus-tests');
The package's main export is a function that serves as the test runner. It's consumed as a default import in ESM or via `require` in CommonJS. The library itself primarily uses CommonJS style internally.

Demonstrates how to programmatically run the Promises/A+ compliance test suite against a provided custom promise adapter, outputting results using Mocha's 'spec' reporter.

/* adapter.js - Your custom promise implementation adapter */ module.exports = { resolved: function (value) { // Replace `MyPromise` with your actual Promise constructor, e.g., `new MyPromise(resolve => resolve(value))` // Using native Promise for demonstration; replace with your library's equivalent. return Promise.resolve(value); }, rejected: function (reason) { // Replace `MyPromise` with your actual Promise constructor, e.g., `new MyPromise((_, reject) => reject(reason))` // Using native Promise for demonstration; replace with your library's equivalent. return Promise.reject(reason); }, deferred: function () { let resolve, reject; // Replace `MyPromise` with your actual Promise constructor const promise = new Promise((res, rej) => { resolve = res; reject = rej; }); return { promise, resolve, reject }; } }; /* test-runner.js - Script to run the tests */ const promisesAplusTests = require('promises-aplus-tests'); const adapter = require('./adapter.js'); // Path to your adapter file console.log('Running Promises/A+ compliance tests...'); promisesAplusTests(adapter, { reporter: 'spec' }, function (err) { if (err) { console.error('Promises/A+ tests failed:', err); console.error(`Total failures: ${err.failures}`); process.exit(1); } else { console.log('Promises/A+ tests passed successfully!'); process.exit(0); } });
promises-aplus-tests --version
Debug
Known issues
breakingThe adapter interface underwent a breaking change in version 2.0.0. The methods `fulfilled(value)` and `deferred.fulfill(value)` were renamed to `resolved(value)` and `deferred.resolve(value)` respectively.
fix
Update your promise adapter to use `resolved` and `resolve` instead of `fulfilled` and `fulfill` to align with Promises/A+ specification v1.1.
affects: >=2.0.0
gotchaAll functions within your custom promise adapter (e.g., `resolved`, `rejected`, `deferred().resolve`, `deferred().reject`) are expected not to throw exceptions. If your promise implementation can throw, you must wrap these calls in `try`/`catch` blocks within the adapter.
fix
Ensure your adapter code includes robust error handling, wrapping any potentially throwing operations from your promise library in `try`/`catch` statements to prevent test failures.
affects: *
gotchaWhile `resolved` and `rejected` exports in the adapter are optional (the test runner can generate them), providing your promise library's native implementations is strongly recommended. This provides better code coverage and can help uncover specific bugs in those native factory methods.
fix
If your promise library has factory methods for already-resolved or already-rejected promises, implement and export `resolved(value)` and `rejected(reason)` functions in your adapter.
affects: *
gotchaWhen using the command-line interface, prior to version 2.0.4, there was a bug affecting the parsing of no-value Mocha arguments (like `--bail`) when they were passed as the last argument.
fix
If you are using an older version (prior to 2.0.4), ensure that no-value Mocha arguments are not the final argument, or update the package to version 2.0.4 or newer.
affects: <2.0.4
Errors
Common errors & fixes
Error: Adapter must export a 'deferred' function.
The `deferred()` function, which is a mandatory part of the adapter interface, is either missing or incorrectly exported from your adapter file.
fix
Ensure your adapter module (e.g., `module.exports = { deferred: ... }`) includes a correctly implemented `deferred` function that returns `{ promise, resolve, reject }`.
TypeError: resolve is not a function
The object returned by your adapter's `deferred()` function does not contain a callable `resolve` property (or similar for `reject`).
fix
Verify that the `deferred()` function in your adapter returns an object with `promise`, `resolve`, and `reject` properties, and that `resolve` and `reject` are indeed functions.
Promises/A+ tests failed: { failures: N, ... }
The test suite detected one or more non-compliance issues with the promise implementation provided by your adapter, indicated by a non-zero number of failures.
fix
Review the detailed output from the test runner (Mocha) in your console to identify which specific Promises/A+ specification points failed and debug your promise library accordingly. The `err.failures` property will indicate the count of failed tests.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies
mocharequiredUsed as the underlying test runner for the compliance suite. While typically installed as a devDependency of 'promises-aplus-tests', users leveraging the CLI or programmatic API should be aware that Mocha drives the execution and reporting.
Agent activity
5 hits · last 30 days
node
4
Resources
promises-aplus-tests — npm install promises-aplus-tests · libregistry