sovra
v0.2.0
Published
Rust-based Test Decider using Oxc
Downloads
24
Readme
Sovra
Rust-based Test Decider for JavaScript using Oxc
Speed up your monorepo pipeline by only running the tests affected by your code diff.
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