Skip to content
/ sovra Public

🤏 Rust-based Test Decider for JavaScript using Oxc

License

Notifications You must be signed in to change notification settings

oblador/sovra

Repository files navigation

Sovra

Rust-based Test Decider for JavaScript using Oxc

Speed up your monorepo pipeline by only running the tests affected by your code diff.

X (formerly Twitter) Follow GitHub followers


CI GitHub top language NPM Version NPM License

Features

  • TypeScript support, including path aliases
  • Configurable resolver, with support for extensions, export conditions and more
  • High performance because it is written in Rust using Oxc
  • Easy to use with Node API

Installation

yarn add sovra

Usage

getAffected(testFiles: string[], changedFiles: string[], resolverOptions: OxcResolverOptions)

Returns a subset of testFiles that have changedFiles in their import graph. This is useful in order to determine which tests to run in a large repo.

Arguments

Name Description
testFiles List of files to check if they were affected by changes
changedFiles List of changed files
resolverOptions Configuration on how to resolve imports, see oxc-resolver

Example

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

const testFiles = glob.sync("src/**/*.spec.{ts,tsx}");
const changedFiles = execSync("git diff --name-only main", { encoding: "utf8" })
  .trim()
  .split("\n");
const resolverOptions = {
  tsconfig: {
    configFile: "tsconfig.json",
  },
};

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

if (affected.errors) {
  console.error(...affected.errors);
} else {
  console.log(affected.files);
}

Test

cargo test

Limitations

Imports using variables or expressions are not supported as they can only be determined during runtime:

require(process.env.SOME_VAR + ".js"); // ❌
import(`./file.${platform}.mjs`); // ❌

License

MIT © Joel Arvidsson 2024

About

🤏 Rust-based Test Decider for JavaScript using Oxc

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project