{"id":28197,"library":"solana-test-validator-js","title":"solana-test-validator-js","description":"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).","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/littleboycoding/solana-test-validator-js","tags":["javascript","typescript"],"install":[{"cmd":"npm install solana-test-validator-js","lang":"bash","label":"npm"},{"cmd":"yarn add solana-test-validator-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add solana-test-validator-js","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Connection and Keypair types; required to use the library.","package":"@solana/web3.js","optional":false}],"imports":[{"note":"Library is ESM-only; CommonJS require will fail in recent Node versions.","wrong":"const { startAndConnect } = require('solana-test-validator-js')","symbol":"startAndConnect","correct":"import { startAndConnect } from 'solana-test-validator-js'"},{"note":"getAccounts is a named export, not default. Use destructured import.","wrong":"import getAccounts from 'solana-test-validator-js'","symbol":"getAccounts","correct":"import { getAccounts } from 'solana-test-validator-js'"},{"note":"Cleanup is a type alias for a function; only needed for TypeScript type annotations.","wrong":null,"symbol":"Cleanup","correct":"import { Cleanup } from 'solana-test-validator-js'"},{"note":"connection is a singleton Connection instance exposed after startAndConnect is called. Connection (capital C) is from @solana/web3.js.","wrong":"import { Connection } from 'solana-test-validator-js'","symbol":"connection","correct":"import { connection } from 'solana-test-validator-js'"}],"quickstart":{"code":"import { Connection, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js';\nimport { startAndConnect, getAccounts, Cleanup } from 'solana-test-validator-js';\n\n// Start test validator with 1 funded account of 10000 SOL\nconst accounts = getAccounts(1);\nconst [connection, cleanup]: [Connection, Cleanup] = startAndConnect([], {\n  number: 1,\n  lamports: LAMPORTS_PER_SOL * 10000,\n});\n\n// Use connection and accounts in tests\nconsole.log('Validator PID:', (connection as any).rpcEndpoint);\n\n// After tests\ncleanup();","lang":"typescript","description":"Launch a local Solana test validator with one funded account, obtain a Connection, and clean up after tests."},"warnings":[{"fix":"Install Solana CLI tools: sh -c \"$(curl -sSfL https://release.solana.com/stable/install)\"","message":"solana-test-validator not found. Ensure the Solana CLI is installed","severity":"missing-dependency","affected_versions":"all"},{"fix":"Use a mainnet or devnet connection for production code.","message":"Deprecated: Do not use this library in production. It is intended for local testing only.","severity":"gotcha","affected_versions":"all"},{"fix":"Always call startAndConnect before accessing the connection singleton. Alternatively, use the returned connection from startAndConnect.","message":"The connection export may be undefined if startAndConnect hasn't been called.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Add test-ledger/ to .gitignore and manually delete the folder between test runs.","message":"Solana ledger data may persist across test runs if test-ledger/ directory is not cleaned.","severity":"gotcha","affected_versions":"all"},{"fix":"Set mocha timeout to at least 60000ms: this.timeout(60000);","message":"Timeout for entire test suite should be increased (default 2000ms). The test validator takes several seconds to start.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run: npm install -D solana-test-validator-js","cause":"Library not installed or not in node_modules.","error":"Error: Cannot find module 'solana-test-validator-js'"},{"fix":"Use import { startAndConnect } from 'solana-test-validator-js' and ensure your project uses ESM (type: module in package.json or .mjs extension).","cause":"Using CommonJS require instead of ESM import.","error":"TypeError: (0 , solana_test_validator_js.startAndConnect) is not a function"},{"fix":"Install Solana CLI tools and ensure solana-test-validator is accessible in your terminal.","cause":"Solana CLI not installed or not in PATH.","error":"Error: spawn solana-test-validator ENOENT"},{"fix":"Ensure startAndConnect returns a tuple: [connection, cleanup]. Check that solana-test-validator process started successfully.","cause":"Destructured cleanup from startAndConnect incorrectly, or startAndConnect failed.","error":"TypeError: cleanup is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}