npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mosaic-code/test-results-to-sqlite

v0.1.0

Published

CLI tool to convert Jest/Vitest JSON test output to SQLite

Readme

test-results-to-sqlite

CLI tool to convert Jest/Vitest JSON test output to SQLite. Useful for agentic workflows where you want to query test results without parsing verbose terminal output.

Installation

npm install -D @mosaic-code/test-results-to-sqlite

Usage with Vitest

{
  "scripts": {
    "test": "vitest run --reporter=json | test-results-to-sqlite ./dev-logging.db"
  }
}

Or configure the reporter in vitest.config.ts:

// vitest.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    reporters: ['json'],
  }
})
{
  "scripts": {
    "test": "vitest run | test-results-to-sqlite ./dev-logging.db"
  }
}

Usage with Jest

{
  "scripts": {
    "test": "jest --json | test-results-to-sqlite ./dev-logging.db"
  }
}

Or output to file first:

{
  "scripts": {
    "test": "jest --json --outputFile=./test-output.json && test-results-to-sqlite ./dev-logging.db --input ./test-output.json"
  }
}

CLI Options

test-results-to-sqlite <db-path> [options]

Arguments:
  db-path              Path to SQLite database (created if not exists)

Options:
  --input <file>       Read JSON from file instead of stdin
  --clear              Clear all previous runs before inserting
  --help               Show help

Schema

CREATE TABLE test_runs (
  id INTEGER PRIMARY KEY,
  started_at TEXT NOT NULL,
  duration_ms INTEGER,
  total INTEGER,
  passed INTEGER,
  failed INTEGER,
  skipped INTEGER,
  success INTEGER NOT NULL
);

CREATE TABLE test_results (
  id INTEGER PRIMARY KEY,
  run_id INTEGER NOT NULL REFERENCES test_runs(id),
  file TEXT NOT NULL,
  test_name TEXT NOT NULL,
  status TEXT NOT NULL,
  duration_ms INTEGER,
  error_message TEXT,
  stack_trace TEXT
);

Querying Results

# Get all failures from latest run
sqlite3 ./dev-logging.db "SELECT file, test_name, error_message FROM test_results WHERE status = 'failed' AND run_id = (SELECT MAX(id) FROM test_runs)"

# Get failure history for a specific test
sqlite3 ./dev-logging.db "SELECT r.started_at, tr.status, tr.error_message FROM test_results tr JOIN test_runs r ON tr.run_id = r.id WHERE tr.test_name LIKE '%should handle edge case%' ORDER BY r.started_at DESC"

# Get slowest tests
sqlite3 ./dev-logging.db "SELECT file, test_name, duration_ms FROM test_results WHERE run_id = (SELECT MAX(id) FROM test_runs) ORDER BY duration_ms DESC LIMIT 10"

# Recent run summary
sqlite3 ./dev-logging.db "SELECT started_at, total, passed, failed, success FROM test_runs ORDER BY started_at DESC LIMIT 5"

Correlating Logs with Tests

This package integrates with pino-sqlite-plus to correlate log entries with test runs. See the pino-sqlite-plus README for setup instructions on automatic test context decoration.

Query API

import { createTestResultsQuery } from '@mosaic-code/test-results-to-sqlite'

const query = createTestResultsQuery('./dev-logging.db', 'logs')

// Get failed tests with their associated logs
const failedWithLogs = query.getFailedTestsWithLogs()
for (const { test, logs } of failedWithLogs) {
  console.log(`Failed: ${test.test_name}`)
  console.log(`Logs: ${logs.length} entries`)
}

// Get logs for a specific test
const logs = query.getLogsForTest(runId, testFile, testName)

// Get all logs for a test run
const runLogs = query.getLogsForRun(runId)

// Get error-level logs for failed tests
const errorLogs = query.getErrorLogsForFailedTests(runId, 50)

query.close()

CLI Usage

# Show failed tests with their correlated logs
test-results-to-sqlite query ./dev-logging.db --failed

# Filter by specific run
test-results-to-sqlite query ./dev-logging.db --failed --run 123

# Output as JSON for LLM consumption
test-results-to-sqlite query ./dev-logging.db --failed --format json

Expected Logs Table Schema

The correlation expects a logs table (default: logs) with these optional correlation columns:

| Column | Type | Description | |--------|------|-------------| | test_run_id | TEXT | Identifier matching your test run | | node_env | TEXT | Node environment (development, test, production) | | time | INTEGER | Log timestamp (ms since epoch) | | level | TEXT | Log level (e.g., "50-error") | | msg | TEXT | Log message | | data | JSON | Full log data |

License

Do No Harm License