Registry / testing / solana-test-validator-js

solana-test-validator-js

JSON →
library1.0.2jsnpmunverified

JavaScript library for spinning up a local Solana test validator instance programmatically, intended for use with test frameworks like Mocha. Version 1.0.2 provides a startAndConnect function that spawns a solana-test-validator process, creates a Connection instance, and optionally funds accounts. It also exports getAccounts for generating Keypairs and a Cleanup type. Requires the Solana CLI tool suite to be installed. Differentiators: simplifies test setup compared to manual CLI spawning, supports TypeScript directly, and integrates cleanly with Mocha global fixtures. Release cadence: infrequent (last update 2023).

npm install solana-test-validator-js
INSTALL
IMPORT
SIG · SOLANA-TEST-VALIDA
S
solana-test-validator-js
testingjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

startAndConnect
import { startAndConnect } from 'solana-test-validator-js'
const { startAndConnect } = require('solana-test-validator-js')
Library is ESM-only; CommonJS require will fail in recent Node versions.
getAccounts
import { getAccounts } from 'solana-test-validator-js'
import getAccounts from 'solana-test-validator-js'
getAccounts is a named export, not default. Use destructured import.
Cleanup
import { Cleanup } from 'solana-test-validator-js'
Cleanup is a type alias for a function; only needed for TypeScript type annotations.
connection
import { connection } from 'solana-test-validator-js'
import { Connection } from 'solana-test-validator-js'
connection is a singleton Connection instance exposed after startAndConnect is called. Connection (capital C) is from @solana/web3.js.

Launch a local Solana test validator with one funded account, obtain a Connection, and clean up after tests.

import { Connection, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js'; import { startAndConnect, getAccounts, Cleanup } from 'solana-test-validator-js'; // Start test validator with 1 funded account of 10000 SOL const accounts = getAccounts(1); const [connection, cleanup]: [Connection, Cleanup] = startAndConnect([], { number: 1, lamports: LAMPORTS_PER_SOL * 10000, }); // Use connection and accounts in tests console.log('Validator PID:', (connection as any).rpcEndpoint); // After tests cleanup();
Debug
Known issues
missing-dependencysolana-test-validator not found. Ensure the Solana CLI is installed
fix
Install Solana CLI tools: sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
affects: all
gotchaDeprecated: Do not use this library in production. It is intended for local testing only.
fix
Use a mainnet or devnet connection for production code.
affects: all
breakingThe connection export may be undefined if startAndConnect hasn't been called.
fix
Always call startAndConnect before accessing the connection singleton. Alternatively, use the returned connection from startAndConnect.
affects: >=1.0.0
gotchaSolana ledger data may persist across test runs if test-ledger/ directory is not cleaned.
fix
Add test-ledger/ to .gitignore and manually delete the folder between test runs.
affects: all
deprecatedTimeout for entire test suite should be increased (default 2000ms). The test validator takes several seconds to start.
fix
Set mocha timeout to at least 60000ms: this.timeout(60000);
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'solana-test-validator-js'
Library not installed or not in node_modules.
fix
Run: npm install -D solana-test-validator-js
TypeError: (0 , solana_test_validator_js.startAndConnect) is not a function
Using CommonJS require instead of ESM import.
fix
Use import { startAndConnect } from 'solana-test-validator-js' and ensure your project uses ESM (type: module in package.json or .mjs extension).
Error: spawn solana-test-validator ENOENT
Solana CLI not installed or not in PATH.
fix
Install Solana CLI tools and ensure solana-test-validator is accessible in your terminal.
TypeError: cleanup is not a function
Destructured cleanup from startAndConnect incorrectly, or startAndConnect failed.
fix
Ensure startAndConnect returns a tuple: [connection, cleanup]. Check that solana-test-validator process started successfully.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
@solana/web3.jsrequiredPeer dependency for Connection and Keypair types; required to use the library.
Agent activity
8 hits · last 30 days
node
8
Resources
solana-test-validator-js — npm install solana-test-validator-js · libregistry