tst is a tool from TST-Studio that automatically generates unit tests for JavaScript and TypeScript code, helping developers maintain flow, reduce boilerplate, and improve test coverage.
Built with TypeScript, Vitest, OCLIF, ts-morph, and LLMs (like OpenAI, Claude, etc).
export function add(a: number, b: number): number {
return a + b;
}import { describe, it, expect } from 'vitest';
import { add } from './math';
describe('add', () => {
it('adds two numbers', () => {
expect(add(2, 3)).toBe(5);
});
});- Language: TypeScript
- Test Runner: Vitest
- CLI Framework: OCLIF
- LLM Integration: OpenAI
- AST Parsing: ts-morph
- Generate unit tests automatically from source files
- Output structured, runnable Vitest test files
- CLI interface for smooth developer workflow
You can use this tool in your own repositories.
$ npm install -D @tst-studio/tst- Add an entry into
package.jsonscriptsto access the command from the repository
"scripts": {
"tst": "tst generate"
}- Add a
tst.config.jsonconfiguration file to configuretstcommand behavior:
$ tst configure
Wrote tst.config.json- Create an
.envfile to store the token for accessing the LLM. This example uses OpenAI:
$ cat .env
TST_OPENAI_API_KEY='sk-proj-....'- Ensure you do not check this into your repository by including
.envin your.gitignorefile
$ npm run tst ./src/fib.js
> cli-demo@1.0.0 tst
> tst generate ./src/fib.js
π Generated test file: src/fib.test.js πThis will submit the whole file to the LLM and create a test file in the appropriate location.
TST-Studio is passionate about making test creation as seamless as possible in any IDE. The tst-cli was created to ensure compatibility across many IDEs.
For example, here is a fairly simple way to integrate the IDE command into VSCode.
Assuming, the package.json commands have the following entry:
"scripts": {
"tst": "tst generate"
}One can create a .vscode/tasks.json configuration:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run tst command on current file",
"type": "shell",
"command": "npm run tst",
"args": ["${file}"], // the file you have open/active
"presentation": { "reveal": "always" },
"problemMatcher": []
}
]
}Then, from the Command Pallet, the "Tasks: Run Task" will have a task named "Run tst command on current file".
If one runs tasks often, this will be the top task on the list.
To make this a more streamlined process, one can configure Key Bindings that, when pressed, will run this task. Ensure the task name matches the task above exactly: Run tst command on current file.
.vscode/keybindings.json:
[
{
"key": "ctrl+alt+r",
"mac": "cmd+alt+r",
"command": "workbench.action.tasks.runTask",
"args": { "task": "Run tst command on current file" }
}
]Help us build the most seamless automated test generation tool possible.
- Repo: https://github.com/TST-Studio/tst-cli
- Issues: https://github.com/TST-Studio/tst-cli/issues
- Write tests where appropriate (or use this tool! π )
- Run
npm run format:check && npm test.
Ensure you have the following installed:
-
Language:
-
CLI Framework:
-
Parsing & Utilities:
-
Developer Tooling:
- ESLint + Prettier β Code linting and formatting
- Husky β Git hooks (e.g., lint on commit)
- tsx β Run TypeScript directly in dev mode
- TypeScript (tsc) β Compiler
- @types/node β Node.js type definitions
-
OCLIF Support:
- oclif β CLI scaffolding and packaging
- @oclif/plugin-legacy β Legacy command support
oclif.manifest.jsonβ Generated CLI manifest
The dev.js command is a development command that represents the tst command but will continue to compile Typescript on the fly while developing.
$ bin/dev.js
LLM-powered unit test generator CLI by TST-Studio
VERSION
@tst-studio/tst/0.1.0 darwin-arm64 node-v22.17.1
USAGE
$ tst [COMMAND]
TOPICS
auth Write API key to local .env or create one
COMMANDS
configure Create or update tst.config.json
generate Generate Vitest tests from a source file
To test outside of the tst-cli repo (e.g., to test against a different tsconfig.json file without breaking the tst command), use another repository like this sandbox repository:
https://github.com/TST-Studio/demo-test-script
Use this checklist when cutting a new release to npm.
- You are a maintainer for the @tst-studio org/package.
- Your npm account has 2FA enabled.
- Youβre logged in:
npm whoami(login withnpm loginif needed)
Ensure:
- All code is formatted consistently:
npm run format README.mdis up to date- All code is committed
Ensure main is clean:
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
Next steps may fail if main is not clean.
Verify the package contents
- Build the
tstcommand:
npm run build
- Pack the
tstcommand and inspect the tarball
npm pack
- View a publish dry run. Sanity check what is included:
npm publish --dry-run
This step updates package.json, creates a git tag (e.g., v0.1.1), and commits.
Determine if this is:
-
A patch (bug fix. No functionality changed)
-
A minor release (functionality was added)
-
A major release (backwards incompatible changes added)
-
Ensure main is clean (see step 1).
NOTE: The following instructions need to have single quotes (not double quotes) as they can include an exclamation mark (used by the "npm version" command). Without the single quotes, the exclamation mark can be interpreted as a history command by the shell.
npm version patch -m 'chore(release): Bump version to %s'
npm version minor -m 'feat!(release): Bump version to %s'
npm version major -m 'feat!(release): Bump version to %s'
npm publish
git push --follow-tags
npm view @tst-studio/tst version
-
EPUBLISHCONFLICT: That version already exists
-
E403 / not authorized to publish: Youβre not a maintainer for @tst-studio/tst under the org; ask an admin to add you or your team.
-
2FA errors: Provide --otp=(Your code) or re-enable 2FA on your account.
-
Wrong files in the tarball: Use
.npmignoreor files inpackage.json; re-run npm pack to confirm.
You can control where test files are generated using the outFormat option in tst.config.json.
-
sameLocation
tst generate ./src/queue.js --outFormat=sameLocation
Produces:
./src/queue.test.js -
testDir
tst generate ./src/queue.js --outFormat=testDir --outBaseSrc=./src --outBaseTest=./tests
Produces:
./tests/queue.test.js
tst expects a configuration file in your project root:
tst.config.json
Example:
{
"provider": "openai",
"model": "gpt-4o-mini",
"outFormat": "testDir",
"outBaseSrc": "./src",
"outBaseTest": "./tests",
"astLibrary": "ts-morph",
"testingFramework": "vitest",
"moduleType": "module"
}- provider:
"openai"(future:"anthropic","vertex","azure-openai","bedrock", etc.) - model:
"gpt-4o-mini"(future:"gpt-4o","gpt-4.1","gpt-4.1-mini") - outFormat:
"sameLocation" | "testDir" - outBaseSrc: Root including
src(used whenoutFormatistestDir) - outBaseTest: Root including
tests(used whenoutFormatistestDir) - astLibrary:
"ts-morph"(future:"babel") - testingFramework:
"vitest"(future:"jest", etc.) - moduleType:
"module"(future:"commonjs", etc.)
tst configureGenerates tst.config.json. You can also specify fields via flags:
tst configure --provider=openai --model=gpt-4o-mini --outFormat=testDir --outBaseSrc=./src --outBaseTest=./tests --astLibrary=ts-morph --testingFramework=vitest --moduleType=moduletst generate ./src/utils/math.js # Generate unit tests for an entire file
tst generate ./src/utils/math.js --function=add # Generate unit tests for a specific function
tst auth set --provider=openai --api-key=$TST_OPENAI_API_KEY
# Store API key for a specific provider
tst auth status
# Show current authentication statustst --help # Display available commands and usage
tst --version # Show the current CLI versionexport TST_OPENAI_API_KEY=sk-...The API key is required to communicate with the LLM.
MIT (c) TST-Studio

