Registry / testing / launchdarkly-js-test-helpers

launchdarkly-js-test-helpers

JSON →
library2.2.0jsnpmunverified

This package provides a collection of JavaScript test utilities primarily developed for internal use by LaunchDarkly's JavaScript-based SDKs (browser, Node, Electron). It is designed to support unit testing environments running on Node.js (version 12 or higher since v2.0.0), offering features like HTTP server mocks, HTTP handler utilities, async mutexes, and async helper functions for managing test expectations. While useful for general JavaScript testing, its design is tailored to LaunchDarkly's specific development needs rather than being a broad, general-purpose testing framework. The current stable version is 2.2.0. Releases appear to be ad-hoc, following an 'as-needed' cadence, with the latest significant update in April 2022. The library is implemented in TypeScript and ships with type definitions.

npm install launchdarkly-js-test-helpers
INSTALL
IMPORT
SIG · LAUNCHDARKLY-JS-TE
L
launchdarkly-js-test-helpers
testingjavascriptv2.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

TestHttpServer
import { TestHttpServer } from 'launchdarkly-js-test-helpers';
const TestHttpServer = require('launchdarkly-js-test-helpers').TestHttpServer;
For ES Modules or TypeScript. Named export.
TestHttpHandlers
import { TestHttpHandlers } from 'launchdarkly-js-test-helpers';
const TestHttpHandlers = require('launchdarkly-js-test-helpers').TestHttpHandlers;
Provides static methods for common HTTP handler patterns, such as serving JSON or SSE streams.
AsyncMutex
import { AsyncMutex } from 'launchdarkly-js-test-helpers';
const AsyncMutex = require('launchdarkly-js-test-helpers').AsyncMutex;
Utility for serializing asynchronous test tasks, added in v1.3.0. Note the specific class import.

Sets up a basic `TestHttpServer`, adds a handler to return a JSON response, and then makes a request to it to verify functionality.

import { TestHttpServer, TestHttpHandlers } from 'launchdarkly-js-test-helpers'; import fetch from 'node-fetch'; // For example, to make HTTP requests to the test server async function runTest() { const server = new TestHttpServer(); await server.start(); server.addHandler(TestHttpHandlers.jsonResponse(200, { message: 'Hello, Test!' })); console.log(`Test HTTP server started on port ${server.port}`); try { const response = await fetch(`http://localhost:${server.port}`); const data = await response.json(); console.log('Received data:', data); // Should log { message: 'Hello, Test!' } } catch (error) { console.error('Error fetching from test server:', error); } finally { await server.stop(); console.log('Test HTTP server stopped.'); } } runTest();
Debug
Known issues
breakingVersion 2.0.0 changed the minimum required Node.js version from 0.6.x to 12.x. Running tests with older Node.js versions will result in compatibility errors.
fix
Upgrade your Node.js environment to version 12 or newer to ensure compatibility.
affects: >=2.0.0
gotchaThe `selfsigned` dependency, used for generating certificates for HTTPS testing, was updated to 2.x in version 2.2.0. While this is primarily an internal change, it's worth noting if you rely on very specific certificate properties in your tests, though no breaking API changes are expected from this update.
fix
No direct fix needed unless custom certificate handling relies on older `selfsigned` behavior; otherwise, ensure your test environment handles standard certificate generation.
affects: >=2.2.0
gotchaVersion 2.1.0 was damaged and did not contain source files, leading to installation or runtime issues. This was immediately corrected in version 2.1.1.
fix
Do not use version 2.1.0. If you encounter issues, upgrade to 2.1.1 or any later version.
affects: 2.1.0
gotchaThe `TestHttpServer` class was originally the primary entry point for static factory methods. To work around transpiler issues, `TestHttpServers` (plural) was introduced in v1.1.0, duplicating these static methods. While `TestHttpServer` still works, `TestHttpServers` is the recommended import for static factories if you encounter unexpected import issues with bundlers or transpilers.
fix
If experiencing issues with static method imports from `TestHttpServer`, try importing `TestHttpServers` instead: `import { TestHttpServers } from 'launchdarkly-js-test-helpers';`
affects: >=1.1.0
Errors
Common errors & fixes
Error: The 'selfsigned' package could not be found or loaded. This is often due to an incompatible Node.js version or corrupted node_modules.
An older Node.js version is being used, or `npm install` failed to properly set up dependencies.
fix
Ensure Node.js v12 or higher is installed and run `npm install` to refresh dependencies. Check `npm ls selfsigned` to verify the package is installed.
TypeError: TestHttpServer is not a constructor
Incorrectly attempting to destructure a static method or importing `TestHttpServers` instead of `TestHttpServer` when instantiating.
fix
Ensure you are importing the `TestHttpServer` class correctly for instantiation: `import { TestHttpServer } from 'launchdarkly-js-test-helpers'; new TestHttpServer();`
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
selfsignedrequiredUsed internally for generating self-signed certificates for HTTPS testing.
Agent activity
2 hits · last 30 days
node
2
Resources
launchdarkly-js-test-helpers — npm install launchdarkly-js-test-helpers · libregistry