Sovra Test Decider

0.2.0 · active · verified Tue Apr 21

Sovra is a high-performance, Rust-based utility for monorepos designed to identify affected test files by analyzing code changes and their import graphs. It leverages Oxc for its underlying dependency resolution, ensuring fast execution. The library provides a Node.js API to determine which tests should be run in a given CI pipeline, significantly speeding up large repository workflows. It ships with comprehensive TypeScript support, including path aliases, and offers configurable resolver options that align with `oxc-resolver`. Currently at version 0.2.0, it is in active development, focusing on performance and accuracy for JavaScript and TypeScript projects. Its primary differentiator is its Rust-powered speed and its direct integration for test selection based on file changes.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `getAffected` to find test files impacted by recent Git changes, leveraging `glob` for file discovery and `tsconfig.json` for path resolution.

import { getAffected } from "sovra";
import { execSync } from "node:child_process";
import { glob } from "glob";

async function runAffectedTests() {
  const testFiles = await glob("src/**/*.spec.{ts,tsx}");
  const changedFiles = execSync("git diff --name-only main", { encoding: "utf8" })
    .trim()
    .split("\n")
    .filter(Boolean);

  if (testFiles.length === 0 || changedFiles.length === 0) {
    console.log("No test files or changed files found.");
    return;
  }

  const resolverOptions = {
    tsconfig: {
      configFile: "tsconfig.json"
    }
  };

  const affected = await getAffected(testFiles, changedFiles, resolverOptions);

  if (affected.errors && affected.errors.length > 0) {
    console.error("Errors determining affected files:", ...affected.errors);
  } else if (affected.files && affected.files.length > 0) {
    console.log("Affected test files:", affected.files);
    // Example: Run these tests with your test runner
    // execSync(`pnpm jest ${affected.files.join(' ')}`, { stdio: 'inherit' });
  } else {
    console.log("No tests affected by the changes.");
  }
}

runAffectedTests().catch(console.error);

view raw JSON →