{"id":13427,"library":"launchdarkly-js-test-helpers","title":"LaunchDarkly JavaScript Test Helpers","description":"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.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/launchdarkly/js-test-helpers","tags":["javascript","launchdarkly","testing","typescript"],"install":[{"cmd":"npm install launchdarkly-js-test-helpers","lang":"bash","label":"npm"},{"cmd":"yarn add launchdarkly-js-test-helpers","lang":"bash","label":"yarn"},{"cmd":"pnpm add launchdarkly-js-test-helpers","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for generating self-signed certificates for HTTPS testing.","package":"selfsigned","optional":false}],"imports":[{"note":"For ES Modules or TypeScript. Named export.","wrong":"const TestHttpServer = require('launchdarkly-js-test-helpers').TestHttpServer;","symbol":"TestHttpServer","correct":"import { TestHttpServer } from 'launchdarkly-js-test-helpers';"},{"note":"Provides static methods for common HTTP handler patterns, such as serving JSON or SSE streams.","wrong":"const TestHttpHandlers = require('launchdarkly-js-test-helpers').TestHttpHandlers;","symbol":"TestHttpHandlers","correct":"import { TestHttpHandlers } from 'launchdarkly-js-test-helpers';"},{"note":"Utility for serializing asynchronous test tasks, added in v1.3.0. Note the specific class import.","wrong":"const AsyncMutex = require('launchdarkly-js-test-helpers').AsyncMutex;","symbol":"AsyncMutex","correct":"import { AsyncMutex } from 'launchdarkly-js-test-helpers';"}],"quickstart":{"code":"import { TestHttpServer, TestHttpHandlers } from 'launchdarkly-js-test-helpers';\nimport fetch from 'node-fetch'; // For example, to make HTTP requests to the test server\n\nasync function runTest() {\n  const server = new TestHttpServer();\n  await server.start();\n\n  server.addHandler(TestHttpHandlers.jsonResponse(200, { message: 'Hello, Test!' }));\n\n  console.log(`Test HTTP server started on port ${server.port}`);\n\n  try {\n    const response = await fetch(`http://localhost:${server.port}`);\n    const data = await response.json();\n    console.log('Received data:', data); // Should log { message: 'Hello, Test!' }\n  } catch (error) {\n    console.error('Error fetching from test server:', error);\n  } finally {\n    await server.stop();\n    console.log('Test HTTP server stopped.');\n  }\n}\n\nrunTest();","lang":"typescript","description":"Sets up a basic `TestHttpServer`, adds a handler to return a JSON response, and then makes a request to it to verify functionality."},"warnings":[{"fix":"Upgrade your Node.js environment to version 12 or newer to ensure compatibility.","message":"Version 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"No direct fix needed unless custom certificate handling relies on older `selfsigned` behavior; otherwise, ensure your test environment handles standard certificate generation.","message":"The `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.","severity":"gotcha","affected_versions":">=2.2.0"},{"fix":"Do not use version 2.1.0. If you encounter issues, upgrade to 2.1.1 or any later version.","message":"Version 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.","severity":"gotcha","affected_versions":"2.1.0"},{"fix":"If experiencing issues with static method imports from `TestHttpServer`, try importing `TestHttpServers` instead: `import { TestHttpServers } from 'launchdarkly-js-test-helpers';`","message":"The `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.","severity":"gotcha","affected_versions":">=1.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"An older Node.js version is being used, or `npm install` failed to properly set up dependencies.","error":"Error: The 'selfsigned' package could not be found or loaded. This is often due to an incompatible Node.js version or corrupted node_modules."},{"fix":"Ensure you are importing the `TestHttpServer` class correctly for instantiation: `import { TestHttpServer } from 'launchdarkly-js-test-helpers'; new TestHttpServer();`","cause":"Incorrectly attempting to destructure a static method or importing `TestHttpServers` instead of `TestHttpServer` when instantiating.","error":"TypeError: TestHttpServer is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}