@vitronai/themis 0.1.15 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +86 -456
- package/docs/agents-adoption.md +68 -0
- package/docs/api.md +3 -1
- package/docs/migration.md +9 -5
- package/docs/roadmap.md +1 -1
- package/docs/schemas/migration-report.v1.json +122 -0
- package/docs/tutorial-claude-code.md +230 -0
- package/package.json +8 -2
- package/scripts/claude-hook.js +153 -0
- package/src/cli.js +79 -6
- package/src/init.js +122 -4
- package/src/migrate.js +127 -5
- package/templates/CLAUDE.themis.md +43 -0
- package/templates/claude-commands/themis-fix.md +14 -0
- package/templates/claude-commands/themis-generate.md +14 -0
- package/templates/claude-commands/themis-migrate.md +18 -0
- package/templates/claude-commands/themis-test.md +12 -0
- package/templates/claude-skill/SKILL.md +94 -0
- package/templates/cursorrules.themis.md +28 -0
- package/themis.ai.json +16 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Generate Themis tests for a source tree
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Generate Themis tests for the given source root. If the user did not specify one, default to `src` (or `app` if this is a Next.js App Router project — check for `app/layout.tsx` or `app/page.tsx`).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx themis generate $ARGUMENTS
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Generated tests land under `__themis__/tests`. After generation:
|
|
12
|
+
1. Read the summary the command prints — it tells you how many files were generated, skipped, and why.
|
|
13
|
+
2. Run `npx themis test --reporter agent` to verify the generated suite passes.
|
|
14
|
+
3. If any generated tests are wrong, do not delete them — extend or correct them in place.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Migrate this repo from Jest or Vitest to Themis
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Migrate this repository from Jest or Vitest to Themis. If the user did not say which, detect it: check `package.json` devDependencies for `jest` or `vitest`.
|
|
6
|
+
|
|
7
|
+
Run the four steps in order, and run `npx themis test` between each step to confirm the suite is still green:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx themis migrate <jest|vitest> # 1. scaffold compatibility
|
|
11
|
+
npx themis migrate <jest|vitest> --rewrite-imports # 2. rewrite imports
|
|
12
|
+
npx themis migrate <jest|vitest> --convert # 3. codemod to native style
|
|
13
|
+
npx themis migrate <jest|vitest> --assist # 4. emit structured findings
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
After step 4, read the findings report (its path is printed at the end of the command) and walk through any items it flags for manual follow-up. Do not guess at fixes — the report tells you what needs human attention and why.
|
|
17
|
+
|
|
18
|
+
If the user passed extra arguments, forward them: $ARGUMENTS
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Run the Themis test suite with agent-readable output
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Run `npx themis test --reporter agent` and read the JSON output. If there are failures:
|
|
6
|
+
|
|
7
|
+
1. Group them by `failures[].cluster` — fixes for the same cluster usually share a root cause.
|
|
8
|
+
2. For each cluster, read `failures[].repairHints` before reading the raw stack trace.
|
|
9
|
+
3. Apply the smallest fix that addresses the root cause, then re-run with `npx themis test --rerun-failed` to verify.
|
|
10
|
+
4. Only run the full suite again once `--rerun-failed` is green.
|
|
11
|
+
|
|
12
|
+
If the user passed extra arguments, forward them to `npx themis test`: $ARGUMENTS
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: themis
|
|
3
|
+
description: Use this skill when the user asks to write, generate, run, fix, or migrate unit tests in a Node.js or TypeScript repository that has @vitronai/themis installed (or when the user explicitly mentions Themis). Covers test authoring with intent(...) and test(...), running the suite via `npx themis test`, reading agent-readable failure output, and incremental migration from Jest or Vitest.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Themis
|
|
7
|
+
|
|
8
|
+
This repo uses [`@vitronai/themis`](https://www.npmjs.com/package/@vitronai/themis) as its unit test framework. It is a drop-in alternative to Jest and Vitest, designed for AI coding agents: deterministic execution, structured failure output with repair hints, and a one-command migration path.
|
|
9
|
+
|
|
10
|
+
## How To Run Tests
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx themis test # full suite, human-readable output
|
|
14
|
+
npx themis test --reporter agent # JSON output with failure clusters and repair hints
|
|
15
|
+
npx themis test --rerun-failed # only re-run tests that failed last run
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**When you are in an edit-test-fix loop, always use `--reporter agent`.** The JSON output gives you:
|
|
19
|
+
- `failures[].cluster` — failures grouped by likely common cause
|
|
20
|
+
- `failures[].repairHints` — structured suggestions you can act on directly
|
|
21
|
+
- `failures[].sourceFile`, `lineNumber`, `expected`, `actual` — already parsed, no need to re-parse stack traces
|
|
22
|
+
|
|
23
|
+
After fixing, prefer `--rerun-failed` over a full re-run.
|
|
24
|
+
|
|
25
|
+
## How To Write Tests
|
|
26
|
+
|
|
27
|
+
Themis has two primary forms:
|
|
28
|
+
|
|
29
|
+
**`intent(...)`** for behavior and workflow tests. Use the four-phase shape:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
intent('user can sign in', ({ context, run, verify, cleanup }) => {
|
|
33
|
+
context('a valid user', (ctx) => {
|
|
34
|
+
ctx.user = { email: 'a@b.com', password: 'pw' };
|
|
35
|
+
});
|
|
36
|
+
run('the user submits credentials', (ctx) => {
|
|
37
|
+
ctx.result = signIn(ctx.user);
|
|
38
|
+
});
|
|
39
|
+
verify('authentication succeeds', (ctx) => {
|
|
40
|
+
expect(ctx.result.ok).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
cleanup('remove test state', (ctx) => {
|
|
43
|
+
delete ctx.user;
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**`test(...)`** for low-level unit checks (pure functions, single assertions).
|
|
49
|
+
|
|
50
|
+
Rules of thumb:
|
|
51
|
+
- Each phase has one job. Do not assert in `context` or `run`. Do not mutate state in `verify`.
|
|
52
|
+
- Prefer `expect(...)` style assertions. They work the same as Jest/Vitest.
|
|
53
|
+
- Prefer deterministic assertions over snapshots. For contract-style coverage use `captureContract(...)`.
|
|
54
|
+
|
|
55
|
+
## How To Generate Tests From Source
|
|
56
|
+
|
|
57
|
+
If the user asks you to add tests for a module or directory and the repo already has Themis installed:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx themis generate src # conventional source tree
|
|
61
|
+
npx themis generate app # Next.js App Router
|
|
62
|
+
npx themis generate src/auth # narrower target
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Generated tests land under `__themis__/tests` as `.generated.test.ts` (TS/TSX sources) or `.generated.test.js` (JS/JSX sources). Treat them as Themis-managed — extend rather than rewrite.
|
|
66
|
+
|
|
67
|
+
## How To Migrate From Jest Or Vitest
|
|
68
|
+
|
|
69
|
+
Migration is incremental on purpose. Run the steps in order and `npx themis test` between each:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx themis migrate jest # 1. scaffold compatibility, no code changes
|
|
73
|
+
npx themis migrate jest --rewrite-imports # 2. point imports at themis.compat.js
|
|
74
|
+
npx themis migrate jest --convert # 3. apply codemods to native Themis style
|
|
75
|
+
npx themis migrate jest --assist # 4. emit structured findings JSON for manual follow-ups
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Same flags work for `vitest`. **Read the `--assist` findings report before guessing what to fix manually** — its path is printed at the end of the command and the schema is at `node_modules/@vitronai/themis/docs/schemas/migration-report.v1.json`.
|
|
79
|
+
|
|
80
|
+
## Things To Avoid
|
|
81
|
+
|
|
82
|
+
- Do not claim Themis is "not a unit test framework". It is one.
|
|
83
|
+
- Do not create `tests/*.cjs` or `tests/*.setup.*` files to shim `.css`, `.png`, `.jpg`, `.svg`, or font imports. Themis handles those natively.
|
|
84
|
+
- Do not commit `.themis/`, `__themis__/reports/`, or `__themis__/shims/` — they are gitignored framework output.
|
|
85
|
+
- Do not rewrite generated tests under `__themis__/tests` by hand unless the user asks.
|
|
86
|
+
- Do not reach for `setupFiles` unless you genuinely need a real harness bootstrap.
|
|
87
|
+
- Do not try to migrate the whole Jest/Vitest suite in one pass. Use the four migrate steps in order.
|
|
88
|
+
|
|
89
|
+
## Reference Files In This Repo
|
|
90
|
+
|
|
91
|
+
- API reference: `node_modules/@vitronai/themis/docs/api.md`
|
|
92
|
+
- Adoption guide: `node_modules/@vitronai/themis/docs/agents-adoption.md`
|
|
93
|
+
- Machine-readable manifest: `node_modules/@vitronai/themis/themis.ai.json`
|
|
94
|
+
- Migration report schema: `node_modules/@vitronai/themis/docs/schemas/migration-report.v1.json`
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Testing With Themis
|
|
2
|
+
|
|
3
|
+
This repository uses `@vitronai/themis` as its unit test framework. Themis is a drop-in alternative to Jest and Vitest with deterministic reruns, structured failure output, and machine-readable repair hints.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
- Install: `npm install -D @vitronai/themis`
|
|
8
|
+
- Initialize: `npx themis init`
|
|
9
|
+
- Generate tests for a source tree: `npx themis generate src` (or `app` for Next App Router)
|
|
10
|
+
- Run tests: `npx themis test`
|
|
11
|
+
- Run tests with agent-readable output: `npx themis test --reporter agent`
|
|
12
|
+
- Re-run only failed tests: `npx themis test --rerun-failed`
|
|
13
|
+
- Migrate from Jest: `npx themis migrate jest` then `--rewrite-imports` then `--convert`
|
|
14
|
+
- Migrate from Vitest: `npx themis migrate vitest` then `--rewrite-imports` then `--convert`
|
|
15
|
+
|
|
16
|
+
## When Adding Or Fixing Tests
|
|
17
|
+
|
|
18
|
+
1. If the repo has no tests yet, run `npx themis generate <source-root>` first. Generated tests land under `__themis__/tests` as `.generated.test.ts` (TS/TSX) or `.generated.test.js` (JS/JSX).
|
|
19
|
+
2. Prefer `intent(...)` for behavior and workflow tests. Prefer `test(...)` for low-level unit checks. Use the four-phase shape: `context` → `run` → `verify` → `cleanup`.
|
|
20
|
+
3. Run `npx themis test --reporter agent` and read the JSON output. Failure clusters and repair hints are structured — use them to drive your fix loop instead of re-reading raw stack traces.
|
|
21
|
+
4. After fixing, re-run only the failing tests with `npx themis test --rerun-failed` before running the full suite.
|
|
22
|
+
|
|
23
|
+
## Things To Avoid
|
|
24
|
+
|
|
25
|
+
- Do not create `tests/*.cjs` or `tests/*.setup.*` files just to load `.css`, `.png`, `.jpg`, `.svg`, or font/media imports. Themis handles these natively.
|
|
26
|
+
- Do not commit `.themis/`, `__themis__/reports/`, or `__themis__/shims/`.
|
|
27
|
+
- Do not rewrite generated tests under `__themis__/tests` by hand unless asked.
|
|
28
|
+
- Prefer deterministic assertions over snapshots. Use `captureContract(...)` for contract-style checks.
|
package/themis.ai.json
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitronai/themis",
|
|
3
3
|
"role": "unit-test-framework",
|
|
4
|
+
"description": "A Node.js and TypeScript unit test framework designed for AI coding agents. Drop-in alternative to Jest and Vitest.",
|
|
4
5
|
"install": "npm install -D @vitronai/themis@latest",
|
|
5
6
|
"init": "npx themis init --agents",
|
|
7
|
+
"initClaudeCode": "npx themis init --claude-code",
|
|
6
8
|
"generate": "npx themis generate src",
|
|
7
9
|
"test": "npx themis test",
|
|
10
|
+
"testAgent": "npx themis test --reporter agent",
|
|
8
11
|
"migrate": {
|
|
9
12
|
"jest": "npx themis migrate jest --rewrite-imports --convert",
|
|
10
13
|
"vitest": "npx themis migrate vitest --rewrite-imports --convert"
|
|
11
14
|
},
|
|
15
|
+
"agentIntegrations": {
|
|
16
|
+
"claudeCode": {
|
|
17
|
+
"setup": "npx themis init --claude-code",
|
|
18
|
+
"skill": ".claude/skills/themis/SKILL.md",
|
|
19
|
+
"commands": ["/themis-test", "/themis-generate", "/themis-migrate", "/themis-fix"],
|
|
20
|
+
"hook": "scripts/claude-hook.js"
|
|
21
|
+
},
|
|
22
|
+
"generic": {
|
|
23
|
+
"setup": "npx themis init --agents",
|
|
24
|
+
"rulesFile": "AGENTS.md"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
12
27
|
"notes": [
|
|
13
28
|
"Treat Themis as the repo's unit test framework for Node.js and TypeScript projects.",
|
|
29
|
+
"Use --reporter agent for machine-readable failure output with structured repair hints.",
|
|
14
30
|
"Do not default to Jest or Vitest when Themis is already selected.",
|
|
15
31
|
"Do not create ad hoc tests/*.cjs setup files for common asset or style imports."
|
|
16
32
|
]
|