{"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,"search_vec":"'1.0.2':27 '2023':92 'account':47 'also':49 'cadenc':88 'clean':82 'cleanup':57 'cli':62,75 'compar':72 'connect':42 'creat':40 'differenti':68 'direct':79 'export':50 'fixtur':86 'framework':23 'function':31 'fund':46 'generat':53 'getaccount':51 'global':85 'infrequ':89 'instal':67 'instanc':16,43 'integr':81 'intend':18 'javascript':6,93 'js':5 'keypair':54 'last':90 'librari':7 'like':24 'local':12 'manual':74 'mocha':25,84 'option':45 'process':39 'programmat':17 'provid':28 'releas':87 'requir':59 'setup':71 'simplifi':69 'solana':2,13,36,61 'solana-test-valid':35 'solana-test-validator-j':1 'spawn':33,76 'spin':9 'startandconnect':30 'suit':64 'support':77 'test':3,14,22,37,70 'tool':63 'type':58 'typescript':78,94 'updat':91 'use':20 'valid':4,15,38 'version':26","created_at":"2026-05-09T05:54:14.568855+00:00","updated_at":"2026-05-09T05:54:14.568855+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/littleboycoding/solana-test-validator-js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/solana-test-validator-js","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-09","next_check":"2026-08-07","install_tag":null}}