Skip to content

Commit

Permalink
Add README to npm package
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Oct 14, 2024
1 parent 8db2245 commit 1ca8797
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 65 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Cargo.lock
node_modules
!/fixtures/modules/node_modules

/npm/*/*
!/npm/sovra/scripts
!/npm/sovra/package.json
/npm/*
!/npm/sovra

/napi/*.node
62 changes: 0 additions & 62 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions README.md
62 changes: 62 additions & 0 deletions npm/sovra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Sovra

Fast test decider for JavaScript projects, written in Rust on top of Oxc.

## 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](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#options) |

#### Example

```ts
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

```bash
cargo test
```

## Limitations

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

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

## License

MIT © Joel Arvidsson 2024

0 comments on commit 1ca8797

Please sign in to comment.