|
1
|
# Writing and Running Regression Tests |
|
2
|
|
|
3
|
## Choose the test layer |
|
4
|
|
|
5
|
Pick the lowest layer that reproduces the bug. |
|
6
|
|
|
7
|
| Bug lives in | Test type | Location | Needs DB | |
|
8
|
| --- | --- | --- | --- | |
|
9
|
| Pure logic in `packages/core/*` (utils, workflows-sdk, orchestration, js-sdk) | Unit | `src/**/__tests__/*.spec.ts` next to the code | No | |
|
10
|
| Workflow/step in `core-flows` | Unit if mockable, else HTTP integration | `src/**/__tests__/` or `integration-tests/http/__tests__/` | Maybe | |
|
11
|
| Module service / repository / model | Module integration | `packages/modules/<module>/integration-tests/__tests__/` | Yes | |
|
12
|
| API route, validator, middleware, query config | HTTP integration | `integration-tests/http/__tests__/<domain>/` | Yes | |
|
13
|
| Admin dashboard | Vitest unit | `packages/admin/dashboard/src/**/*.test.ts(x)` | No | |
|
14
|
|
|
15
|
> **CRITICAL:** Add to an existing spec file for the same code when one exists. Read a nearby test first and copy its setup, helpers, and naming. |
|
16
|
|
|
17
|
## Run commands |
|
18
|
|
|
19
|
Run from the package directory, filtered to the test: |
|
20
|
|
|
21
|
```bash |
|
22
|
# Unit (Jest) |
|
23
|
cd packages/<path> && npx jest <spec-path> -t "<describe or it name>" |
|
24
|
|
|
25
|
# Module integration (needs Postgres) |
|
26
|
cd packages/modules/<module> && yarn test:integration <spec-path> |
|
27
|
|
|
28
|
# HTTP integration (needs Postgres; slow, run one file) |
|
29
|
cd integration-tests/http && yarn test:integration <spec-path> |
|
30
|
|
|
31
|
# Admin dashboard (Vitest) |
|
32
|
cd packages/admin/dashboard && npx vitest --run <spec-path> |
|
33
|
``` |
|
34
|
|
|
35
|
If a DB-backed layer can't run in the environment, write the test anyway, say so in `pr-body.md` under Testing, and add a unit-level test too if possible. |
|
36
|
|
|
37
|
## Writing the test |
|
38
|
|
|
39
|
- Name `it` for the behavior expected after the fix, e.g. `"should pass the renamed step's own compensate input when the original step was skipped"`. |
|
40
|
- Cover the reported scenario **and** the worst sibling case found during validation (e.g. silent wrong data, not just `undefined`). |
|
41
|
- Assert on the observable symptom the reporter saw (output, state, error), not on internals. |
|
42
|
- Use synthetic data only, never reporter data. |
|
43
|
- No comments explaining the bug; that belongs in the PR body. |
|
44
|
|
|
45
|
## Confirm it fails for the right reason |
|
46
|
|
|
47
|
Run the test on the unfixed code and read the failure: |
|
48
|
|
|
49
|
- ✅ Assertion failure whose received value matches the reported symptom. |
|
50
|
- ❌ Import/compile error, `TypeError` in setup, timeout, missing fixture, wrong ID → fix the test, re-run. |
|
51
|
|
|
52
|
Record the received vs expected values; they go in the PR body. |
|
53
|
|
|
54
|
## After the fix |
|
55
|
|
|
56
|
1. Re-run the new test(s) → must pass. |
|
57
|
2. Run the whole spec file → must pass. |
|
58
|
3. Run the package's unit suite (`yarn test` in the package) → must pass. |
|
59
|
4. If something else fails, `git stash` and re-run it on the base code. Pre-existing failures are noted in the PR body, not fixed. |