sonamu 0.8.24 → 0.8.26
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/dist/api/__tests__/config.test.js +189 -0
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +7 -2
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +14 -10
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -1
- package/dist/auth/knex-adapter.d.ts +23 -0
- package/dist/auth/knex-adapter.d.ts.map +1 -0
- package/dist/auth/knex-adapter.js +163 -0
- package/dist/auth/plugins/wrappers/admin.d.ts +2 -2
- package/dist/bin/__tests__/ts-loader-register.test.js +45 -0
- package/dist/bin/cli.js +47 -9
- package/dist/bin/ts-loader-register.js +3 -29
- package/dist/bin/ts-loader-registration.d.ts +2 -0
- package/dist/bin/ts-loader-registration.d.ts.map +1 -0
- package/dist/bin/ts-loader-registration.js +42 -0
- package/dist/cone/cone-generator.js +3 -3
- package/dist/database/puri-subset.test-d.js +9 -1
- package/dist/database/puri-subset.types.d.ts +1 -1
- package/dist/database/puri-subset.types.d.ts.map +1 -1
- package/dist/database/puri-subset.types.js +1 -1
- package/dist/testing/fixture-generator.js +5 -5
- package/dist/ui/ai-client.js +2 -2
- package/dist/ui/api.d.ts.map +1 -1
- package/dist/ui/api.js +14 -14
- package/dist/ui/cdd-service.d.ts +15 -18
- package/dist/ui/cdd-service.d.ts.map +1 -1
- package/dist/ui/cdd-service.js +246 -222
- package/dist/ui/cdd-types.d.ts +41 -68
- package/dist/ui/cdd-types.d.ts.map +1 -1
- package/dist/ui/cdd-types.js +2 -2
- package/dist/ui-web/assets/index-CKo0Z2Iu.css +1 -0
- package/dist/ui-web/assets/{index-CxiydzeC.js → index-DK-2aacv.js} +83 -83
- package/dist/ui-web/index.html +2 -2
- package/package.json +6 -2
- package/src/api/__tests__/config.test.ts +225 -0
- package/src/api/config.ts +10 -4
- package/src/api/sonamu.ts +16 -13
- package/src/auth/index.ts +1 -0
- package/src/auth/knex-adapter.ts +208 -0
- package/src/bin/__tests__/ts-loader-register.test.ts +62 -0
- package/src/bin/cli.ts +52 -9
- package/src/bin/ts-loader-register.ts +2 -32
- package/src/bin/ts-loader-registration.ts +55 -0
- package/src/cone/cone-generator.ts +2 -2
- package/src/database/puri-subset.test-d.ts +102 -0
- package/src/database/puri-subset.types.ts +1 -1
- package/src/skills/commands/sonamu-skills.md +20 -0
- package/src/skills/sonamu/SKILL.md +179 -137
- package/src/skills/sonamu/ai-agents.md +69 -69
- package/src/skills/sonamu/api.md +147 -147
- package/src/skills/sonamu/auth-migration.md +220 -220
- package/src/skills/sonamu/auth-plugins.md +83 -83
- package/src/skills/sonamu/auth.md +106 -106
- package/src/skills/sonamu/cdd.md +65 -200
- package/src/skills/sonamu/cone.md +138 -138
- package/src/skills/sonamu/config.md +191 -191
- package/src/skills/sonamu/create-sonamu.md +66 -66
- package/src/skills/sonamu/database.md +158 -158
- package/src/skills/sonamu/entity-basic.md +292 -293
- package/src/skills/sonamu/entity-relations.md +246 -246
- package/src/skills/sonamu/entity-validation-checklist.md +124 -124
- package/src/skills/sonamu/fixture-cli.md +231 -231
- package/src/skills/sonamu/framework-change.md +37 -37
- package/src/skills/sonamu/frontend.md +223 -223
- package/src/skills/sonamu/i18n.md +82 -82
- package/src/skills/sonamu/migration.md +77 -77
- package/src/skills/sonamu/model.md +222 -222
- package/src/skills/sonamu/naite.md +86 -86
- package/src/skills/sonamu/project-init.md +228 -228
- package/src/skills/sonamu/puri.md +122 -122
- package/src/skills/sonamu/scaffolding.md +154 -154
- package/src/skills/sonamu/skill-contribution.md +124 -124
- package/src/skills/sonamu/subset.md +46 -46
- package/src/skills/sonamu/tasks.md +82 -82
- package/src/skills/sonamu/testing-devrunner.md +147 -147
- package/src/skills/sonamu/testing.md +673 -673
- package/src/skills/sonamu/upsert.md +79 -79
- package/src/skills/sonamu/vector.md +67 -67
- package/src/testing/fixture-generator.ts +4 -4
- package/src/ui/ai-client.ts +1 -1
- package/src/ui/api.ts +18 -17
- package/src/ui/cdd-service.ts +264 -254
- package/src/ui/cdd-types.ts +40 -75
- package/dist/ui-web/assets/index-BrQKU3j9.css +0 -1
- package/src/skills/sonamu/workflow.md +0 -317
|
@@ -1,96 +1,96 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: sonamu-testing-devrunner
|
|
3
|
-
description: DevRunner (sonamu test)
|
|
3
|
+
description: DevRunner (sonamu test) execution and test environment configuration. sonamu test execution errors, HMR integration, Naite trace CLI, parallel testing, vitest.config.ts/sonamu.config.ts setup. Use when 'sonamu test' fails, configuring DevRunner, or setting up parallel testing.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# DevRunner
|
|
6
|
+
# DevRunner and Test Configuration
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Running Tests
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
**Principle: Use `pnpm sonamu test` during development.** Assume the dev server is always running. If the dev server is down, start it first with `pnpm sonamu dev`, then run tests. Use `pnpm test` only in CI environments.
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
# dev
|
|
13
|
+
# Check dev server (start if it's down)
|
|
14
14
|
pnpm sonamu dev
|
|
15
15
|
|
|
16
|
-
#
|
|
16
|
+
# Tests during development (default)
|
|
17
17
|
pnpm sonamu test
|
|
18
18
|
pnpm sonamu test user.model
|
|
19
19
|
pnpm sonamu test user.model -p "findMany"
|
|
20
20
|
|
|
21
|
-
# CI
|
|
21
|
+
# CI environments only
|
|
22
22
|
pnpm test
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
## DevRunner — `sonamu test` (
|
|
27
|
+
## DevRunner — `sonamu test` (Default Test Execution Method)
|
|
28
28
|
|
|
29
|
-
`sonamu test
|
|
29
|
+
`sonamu test` runs tests through a Vitest Node API instance that resides inside the `sonamu dev` process. Instead of starting Vitest fresh each time, it reuses an already-initialized instance, making execution 3.2x faster, and it integrates with HMR so tests always run against the latest code immediately after source changes.
|
|
30
30
|
|
|
31
|
-
###
|
|
31
|
+
### Prerequisites
|
|
32
32
|
|
|
33
|
-
**1. sonamu.config.ts
|
|
33
|
+
**1. Enable devRunner in sonamu.config.ts:**
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
36
|
export default defineConfig({
|
|
37
37
|
test: {
|
|
38
38
|
devRunner: {
|
|
39
39
|
enabled: true,
|
|
40
|
-
// routePrefix: "/__test__", // optional,
|
|
41
|
-
// vitestConfigPath: undefined, // optional,
|
|
40
|
+
// routePrefix: "/__test__", // optional, default value
|
|
41
|
+
// vitestConfigPath: undefined, // optional, default: vitest.config.ts (relative to api-root)
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
- `enabled: boolean` —
|
|
49
|
-
- `routePrefix?: string` —
|
|
50
|
-
- `vitestConfigPath?: string` — vitest.config.ts
|
|
47
|
+
Configuration type (`SonamuDevRunnerConfig`):
|
|
48
|
+
- `enabled: boolean` — Whether to enable DevRunner (default: false)
|
|
49
|
+
- `routePrefix?: string` — Test endpoint path prefix (default: `/__test__`)
|
|
50
|
+
- `vitestConfigPath?: string` — vitest.config.ts path (relative to api-root)
|
|
51
51
|
|
|
52
|
-
**2. dev
|
|
52
|
+
**2. Start the dev server:**
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
sonamu dev #
|
|
55
|
+
sonamu dev # or pnpm dev
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
dev
|
|
58
|
+
When the dev server starts, `DevVitestManager` is automatically initialized under the `isLocal() && devRunner.enabled` condition, and test endpoints are registered with Fastify.
|
|
59
59
|
|
|
60
|
-
### CLI
|
|
60
|
+
### CLI Usage
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
|
-
#
|
|
63
|
+
# Run all tests
|
|
64
64
|
sonamu test
|
|
65
65
|
|
|
66
|
-
#
|
|
66
|
+
# Specify file (matched by partial filename — uses globTestSpecifications)
|
|
67
67
|
sonamu test user.model
|
|
68
68
|
|
|
69
|
-
#
|
|
69
|
+
# Multiple files
|
|
70
70
|
sonamu test user.model order.model
|
|
71
71
|
|
|
72
|
-
#
|
|
72
|
+
# Run specific test cases only (test name pattern)
|
|
73
73
|
sonamu test user.model --pattern "findMany"
|
|
74
74
|
sonamu test user.model -p "findMany"
|
|
75
75
|
|
|
76
|
-
# Naite
|
|
76
|
+
# Print Naite traces
|
|
77
77
|
sonamu test user.model --traces
|
|
78
78
|
sonamu test user.model -t
|
|
79
79
|
|
|
80
|
-
#
|
|
80
|
+
# Combine file + pattern + trace
|
|
81
81
|
sonamu test user.model -p "findMany" -t
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
- `--pattern` / `-p`:
|
|
86
|
-
- `--traces` / `-t`: boolean
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
84
|
+
Argument processing rules:
|
|
85
|
+
- `--pattern` / `-p`: test name string filter (`setGlobalTestNamePattern` → `resetGlobalTestNamePattern` after execution)
|
|
86
|
+
- `--traces` / `-t`: boolean flag, enables Naite trace output
|
|
87
|
+
- Arguments not starting with `-`: treated as file list
|
|
88
|
+
- Multiple files allowed
|
|
89
|
+
- `ok: false` in server response is reflected as exit code 1
|
|
90
90
|
|
|
91
|
-
### Naite
|
|
91
|
+
### Naite Trace Output
|
|
92
92
|
|
|
93
|
-
`--traces` / `-t`
|
|
93
|
+
The `--traces` / `-t` flag lets you view `Naite.t(key, data)` records from test code in the CLI:
|
|
94
94
|
|
|
95
95
|
```
|
|
96
96
|
Tests: 5 passed, 0 failed, 5 total
|
|
@@ -98,7 +98,7 @@ Duration: 791ms
|
|
|
98
98
|
|
|
99
99
|
Traces:
|
|
100
100
|
|
|
101
|
-
UserModel > BaseModel
|
|
101
|
+
UserModel > BaseModel basic functionality check > Model.findMany() with num = 0
|
|
102
102
|
user.model.test.ts
|
|
103
103
|
|
|
104
104
|
[esq-query] user.model.ts:113
|
|
@@ -108,47 +108,47 @@ Traces:
|
|
|
108
108
|
select COUNT(*)::integer as "total" from "users" limit 1
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
`--traces`
|
|
111
|
+
Without the `--traces` flag, traces are not printed. The API response (`POST /__test__/run`) always includes a `traces` field, so external tools can make use of it.
|
|
112
112
|
|
|
113
|
-
trace
|
|
113
|
+
For trace data details: see `naite.md`
|
|
114
114
|
|
|
115
|
-
### HMR
|
|
115
|
+
### HMR Integration — Automatic Vitest Module Graph Invalidation on Source Changes
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
1.
|
|
119
|
-
2. Vitest
|
|
117
|
+
When a source file is modified, `syncFromWatcher` in the syncer triggers both of the following simultaneously:
|
|
118
|
+
1. Server HMR cache invalidation (`hot.invalidateFile`)
|
|
119
|
+
2. Vitest module graph invalidation (`Sonamu.devVitestManager.invalidateFiles([filePath])`)
|
|
120
120
|
|
|
121
121
|
```
|
|
122
|
-
user.model.ts
|
|
123
|
-
|
|
124
|
-
sonamu test user.model ←
|
|
122
|
+
Modify user.model.ts → save
|
|
123
|
+
Server log: "Test invalidated: src/application/user/user.model.ts"
|
|
124
|
+
sonamu test user.model ← runs with latest code
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
Vite
|
|
127
|
+
Because Vite's `moduleGraph.invalidateModule()` recursively cascades in the importer direction, invalidating a single source file automatically invalidates any test files that import it. No restart is needed.
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
- `utils.ts`
|
|
129
|
+
**Transitive dependency example:**
|
|
130
|
+
- Change `utils.ts` → `user.model.ts` (imports utils) → `user.model.test.ts` all automatically invalidated
|
|
131
131
|
|
|
132
|
-
### HTTP API
|
|
132
|
+
### Direct HTTP API Calls
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
You can call the HTTP API directly instead of using the CLI:
|
|
135
135
|
|
|
136
136
|
```bash
|
|
137
|
-
#
|
|
137
|
+
# Run tests
|
|
138
138
|
curl -X POST http://localhost:3000/__test__/run \
|
|
139
139
|
-H "Content-Type: application/json" \
|
|
140
140
|
-d '{"files": ["user.model"], "pattern": "findMany"}'
|
|
141
141
|
|
|
142
|
-
#
|
|
142
|
+
# Check status
|
|
143
143
|
curl http://localhost:3000/__test__/status
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
**POST `/__test__/run`**
|
|
146
|
+
**POST `/__test__/run`** request:
|
|
147
147
|
```json
|
|
148
148
|
{ "files": ["src/user/user.model.test.ts"], "pattern": "should create user" }
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
Response (success):
|
|
152
152
|
```json
|
|
153
153
|
{
|
|
154
154
|
"ok": true,
|
|
@@ -168,177 +168,177 @@ curl http://localhost:3000/__test__/status
|
|
|
168
168
|
}
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
**GET `/__test__/status`**
|
|
171
|
+
**GET `/__test__/status`** response:
|
|
172
172
|
```json
|
|
173
173
|
{ "ready": true, "running": false, "lastRunAt": "2026-02-13T12:34:56.000Z" }
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
###
|
|
176
|
+
### Internal Architecture
|
|
177
177
|
|
|
178
178
|
**DevVitestManager** (`testing/dev-vitest-manager.ts`):
|
|
179
|
-
- `createVitest('test', cliOptions, viteOverrides)
|
|
180
|
-
- `watch: true, standalone: true
|
|
179
|
+
- Creates a resident instance with `createVitest('test', cliOptions, viteOverrides)`
|
|
180
|
+
- Configured with `watch: true, standalone: true`, but blocks automatic re-runs:
|
|
181
181
|
- `forceRerunTriggers: []`
|
|
182
|
-
- `server.watch: null` (chokidar
|
|
182
|
+
- `server.watch: null` (chokidar not created)
|
|
183
183
|
- `onFilterWatchedSpecification(() => false)`
|
|
184
|
-
-
|
|
185
|
-
- **
|
|
186
|
-
-
|
|
187
|
-
-
|
|
184
|
+
- Explicitly sets `env: { NODE_ENV: "test" }` so worker processes use the test DB
|
|
185
|
+
- **Queue-based sequential execution**: prevents result mixing on concurrent requests, processes in order and responds to each
|
|
186
|
+
- **Result aggregation**: filters only the modules requested for execution using `specModuleIds` (works around the issue where `testModules` includes all modules in standalone mode)
|
|
187
|
+
- Keeps loading the project's `vitest.config.ts` (reuses existing sequencer/reporter/globalSetup)
|
|
188
188
|
|
|
189
|
-
**Fastify
|
|
190
|
-
- `registerDevTestRoutes(server, config)
|
|
191
|
-
- `Sonamu.devVitestManager
|
|
192
|
-
- `server.addHook('onClose')
|
|
189
|
+
**Fastify integration** (`testing/dev-test-routes.ts`):
|
|
190
|
+
- Registers routes with `registerDevTestRoutes(server, config)`
|
|
191
|
+
- Stores manager instance in `Sonamu.devVitestManager`
|
|
192
|
+
- Ensures `shutdown()` is called in `server.addHook('onClose')`
|
|
193
193
|
|
|
194
194
|
**CLI** (`bin/test-command.ts`):
|
|
195
|
-
- `
|
|
196
|
-
- `bootstrap()
|
|
197
|
-
-
|
|
195
|
+
- Calls `testCommand()` directly before `tsicli` matching (to handle variadic arguments)
|
|
196
|
+
- Included in `bootstrap()`'s `notToInit` list (no need for `Sonamu.init` since it only makes HTTP calls)
|
|
197
|
+
- Server port/host read from `server.listen` in `sonamu.config.ts`
|
|
198
198
|
|
|
199
|
-
###
|
|
199
|
+
### Performance Comparison (miomock baseline)
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
Single file (`user.model.test.ts`):
|
|
202
202
|
|
|
203
|
-
|
|
|
203
|
+
| Item | `vitest run` | `sonamu test` | Difference |
|
|
204
204
|
|---|---|---|---|
|
|
205
|
-
|
|
|
206
|
-
|
|
|
205
|
+
| Test execution time | 2,610ms | 823ms | 3.2x faster |
|
|
206
|
+
| Total elapsed time (wall clock) | 4,118ms | 1,907ms | 2.2x faster |
|
|
207
207
|
|
|
208
|
-
|
|
208
|
+
Multiple files (puri tests, 4 files 147 tests):
|
|
209
209
|
|
|
210
|
-
|
|
|
210
|
+
| Item | `vitest run` | `sonamu test` | Difference |
|
|
211
211
|
|---|---|---|---|
|
|
212
|
-
|
|
|
213
|
-
|
|
|
212
|
+
| Test execution time | 5,740ms | 1,774ms | 3.2x faster |
|
|
213
|
+
| Total elapsed time (wall clock) | 7,035ms | 2,673ms | 2.6x faster |
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
Speed difference reason: `vitest run` requires process boot (~1.5s) + module transform (~400ms) on every execution, whereas `sonamu test` reuses an already-initialized instance and avoids this overhead.
|
|
216
216
|
|
|
217
|
-
### `pnpm sonamu test` vs `pnpm test`
|
|
217
|
+
### `pnpm sonamu test` vs `pnpm test` Comparison
|
|
218
218
|
|
|
219
|
-
| | `pnpm sonamu test` (
|
|
219
|
+
| | `pnpm sonamu test` (default) | `pnpm test` (CI/fallback) |
|
|
220
220
|
|---|---|---|
|
|
221
|
-
|
|
|
222
|
-
|
|
|
223
|
-
| HMR
|
|
224
|
-
| Naite trace | `--traces`
|
|
225
|
-
|
|
|
226
|
-
|
|
|
221
|
+
| Execution method | Resident instance inside dev server | Independent Vitest process |
|
|
222
|
+
| Initialization cost | None (already initialized) | Initialization on every run |
|
|
223
|
+
| HMR integration | Source changes reflected immediately | Not applicable |
|
|
224
|
+
| Naite trace | CLI output via `--traces` flag | Available through reporter |
|
|
225
|
+
| Use case | **Default test execution during development** | CI environments |
|
|
226
|
+
| Prerequisite | `sonamu dev` running (assumed always running) | None |
|
|
227
227
|
|
|
228
|
-
###
|
|
228
|
+
### Troubleshooting
|
|
229
229
|
|
|
230
|
-
**"
|
|
231
|
-
→ `sonamu dev
|
|
230
|
+
**"Cannot connect to dev server"**
|
|
231
|
+
→ Check that `sonamu dev` is running. The CLI sends HTTP requests to `config.server.listen.port`.
|
|
232
232
|
|
|
233
|
-
**"devRunner
|
|
234
|
-
→ `
|
|
233
|
+
**"devRunner is not enabled" (or 404 response)**
|
|
234
|
+
→ `test.devRunner.enabled: true` must be set in `sonamu.config.ts`. DevRunner is only activated in `isLocal()` environments.
|
|
235
235
|
|
|
236
|
-
**"Vitest
|
|
237
|
-
→
|
|
236
|
+
**"Vitest instance is not ready yet" (500 response)**
|
|
237
|
+
→ Request was made before Vitest initialization completed immediately after dev server startup. Check `GET /__test__/status` for `ready: true` before running.
|
|
238
238
|
|
|
239
|
-
|
|
240
|
-
→
|
|
239
|
+
**Tests running against old code**
|
|
240
|
+
→ After saving a source file, check whether a `"Test invalidated: ..."` log appears. If not, verify that `devRunner.enabled` is `true` and that the syncer is working correctly.
|
|
241
241
|
|
|
242
242
|
---
|
|
243
243
|
|
|
244
|
-
## sonamu.config.ts
|
|
244
|
+
## Complete Map of Test-Related Settings in sonamu.config.ts
|
|
245
245
|
|
|
246
|
-
`pnpm sonamu test` (DevRunner,
|
|
246
|
+
Both `pnpm sonamu test` (DevRunner, default) and `pnpm test` (direct Vitest execution, CI) reference settings from `sonamu.config.ts`.
|
|
247
247
|
|
|
248
|
-
###
|
|
248
|
+
### Configuration Type Definition (SonamuTestConfig)
|
|
249
249
|
|
|
250
250
|
```typescript
|
|
251
251
|
// config.ts
|
|
252
252
|
export type SonamuTestConfig = {
|
|
253
|
-
/**
|
|
253
|
+
/** Enable parallel testing (default: false) */
|
|
254
254
|
parallel?: boolean;
|
|
255
|
-
/**
|
|
255
|
+
/** Number of parallel execution workers (default: 4) */
|
|
256
256
|
maxWorkers?: number;
|
|
257
|
-
/**
|
|
257
|
+
/** Resident Vitest instance settings inside dev server */
|
|
258
258
|
devRunner?: SonamuDevRunnerConfig;
|
|
259
259
|
};
|
|
260
260
|
|
|
261
261
|
export type SonamuDevRunnerConfig = {
|
|
262
|
-
/**
|
|
262
|
+
/** Whether to enable DevRunner (default: false) */
|
|
263
263
|
enabled: boolean;
|
|
264
|
-
/**
|
|
264
|
+
/** Test endpoint path prefix (default: /__test__) */
|
|
265
265
|
routePrefix?: string;
|
|
266
|
-
/** vitest.config.ts
|
|
266
|
+
/** vitest.config.ts path (relative to api-root) */
|
|
267
267
|
vitestConfigPath?: string;
|
|
268
268
|
};
|
|
269
269
|
```
|
|
270
270
|
|
|
271
|
-
###
|
|
271
|
+
### Parallel Test Configuration (Optional)
|
|
272
272
|
|
|
273
|
-
`pnpm sonamu test
|
|
273
|
+
Both `pnpm sonamu test` and `pnpm test` share the parallel configuration. Only configure this if parallel execution is needed:
|
|
274
274
|
|
|
275
275
|
```typescript
|
|
276
276
|
export default defineConfig({
|
|
277
277
|
test: {
|
|
278
|
-
parallel: true, //
|
|
279
|
-
maxWorkers: 4, //
|
|
278
|
+
parallel: true, // Separate DB execution per worker
|
|
279
|
+
maxWorkers: 4, // Number of workers (default: 4)
|
|
280
280
|
},
|
|
281
281
|
});
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
`parallel: true
|
|
284
|
+
When `parallel: true`, `getSonamuTestConfig()` (vitest-helpers.ts) injects `pool: "forks"`, `maxWorkers`, and `env: { SONAMU_WORKER_DB: "true" }` into vitest, and `globalSetup` (global-setup.ts) creates DBs `{database.name}_test_1` through `{database.name}_test_{maxWorkers}` by cloning from the template (`{database.name}_test`).
|
|
285
285
|
|
|
286
|
-
### DevRunner
|
|
286
|
+
### DevRunner Configuration (Required)
|
|
287
287
|
|
|
288
|
-
`pnpm sonamu test
|
|
288
|
+
To use `pnpm sonamu test`, DevRunner must be enabled. Just add `test.devRunner.enabled: true`:
|
|
289
289
|
|
|
290
290
|
```typescript
|
|
291
291
|
export default defineConfig({
|
|
292
292
|
server: {
|
|
293
293
|
listen: {
|
|
294
|
-
port: 3000, // CLI
|
|
295
|
-
host: "localhost", // CLI
|
|
294
|
+
port: 3000, // CLI sends HTTP requests to this port
|
|
295
|
+
host: "localhost", // CLI connects to this host (default: localhost)
|
|
296
296
|
},
|
|
297
297
|
},
|
|
298
298
|
|
|
299
299
|
test: {
|
|
300
300
|
devRunner: {
|
|
301
|
-
enabled: true, //
|
|
302
|
-
// routePrefix: "/__test__", //
|
|
303
|
-
// vitestConfigPath: undefined, //
|
|
301
|
+
enabled: true, // Required: enable DevRunner
|
|
302
|
+
// routePrefix: "/__test__", // Optional: endpoint path (default value)
|
|
303
|
+
// vitestConfigPath: undefined, // Optional: vitest.config.ts path (default: vitest.config.ts in api-root)
|
|
304
304
|
},
|
|
305
|
-
// parallel: true, //
|
|
306
|
-
// maxWorkers: 4, //
|
|
305
|
+
// parallel: true, // Optional: independent of DevRunner
|
|
306
|
+
// maxWorkers: 4, // Optional: when using parallel
|
|
307
307
|
},
|
|
308
308
|
});
|
|
309
309
|
```
|
|
310
310
|
|
|
311
|
-
###
|
|
311
|
+
### Source Code Reference Locations per Setting
|
|
312
312
|
|
|
313
|
-
|
|
|
313
|
+
| Setting path | Default | Reference location | Purpose |
|
|
314
314
|
|---|---|---|---|
|
|
315
|
-
| `test.devRunner.enabled` | `false` | `sonamu.ts` L394, `test-command.ts` | DevRunner
|
|
316
|
-
| `test.devRunner.routePrefix` | `"/__test__"` | `dev-test-routes.ts`, `test-command.ts` | HTTP
|
|
317
|
-
| `test.devRunner.vitestConfigPath` | `undefined` | `dev-vitest-manager.ts` `start()` | Vitest
|
|
318
|
-
| `test.parallel` | `false` | `vitest-helpers.ts` `getSonamuTestConfig()` | `pool: "forks"` + `SONAMU_WORKER_DB` env
|
|
319
|
-
| `test.maxWorkers` | `4` | `vitest-helpers.ts`, `global-setup.ts` | Vitest maxWorkers + worker
|
|
320
|
-
| `server.listen.port` | `3000` | `test-command.ts` | CLI → dev
|
|
321
|
-
| `server.listen.host` | `"localhost"` | `test-command.ts` | CLI → dev
|
|
322
|
-
| `database.name` | — | `db.ts` `generateDBConfig()`, `global-setup.ts` |
|
|
315
|
+
| `test.devRunner.enabled` | `false` | `sonamu.ts` L394, `test-command.ts` | DevRunner activation condition |
|
|
316
|
+
| `test.devRunner.routePrefix` | `"/__test__"` | `dev-test-routes.ts`, `test-command.ts` | HTTP endpoint path |
|
|
317
|
+
| `test.devRunner.vitestConfigPath` | `undefined` | `dev-vitest-manager.ts` `start()` | Vitest config file location |
|
|
318
|
+
| `test.parallel` | `false` | `vitest-helpers.ts` `getSonamuTestConfig()` | `pool: "forks"` + `SONAMU_WORKER_DB` env injection |
|
|
319
|
+
| `test.maxWorkers` | `4` | `vitest-helpers.ts`, `global-setup.ts` | Vitest maxWorkers + number of worker DBs |
|
|
320
|
+
| `server.listen.port` | `3000` | `test-command.ts` | CLI → dev server HTTP connection port |
|
|
321
|
+
| `server.listen.host` | `"localhost"` | `test-command.ts` | CLI → dev server HTTP connection host |
|
|
322
|
+
| `database.name` | — | `db.ts` `generateDBConfig()`, `global-setup.ts` | Test DB name (`{name}_test`) |
|
|
323
323
|
|
|
324
|
-
###
|
|
324
|
+
### Activation Conditions
|
|
325
325
|
|
|
326
|
-
DevRunner
|
|
326
|
+
DevRunner is registered in `sonamu.ts` under the condition `isLocal() && config.test?.devRunner?.enabled`. `isLocal()` returns true when the `LR` environment variable is undefined or `"local"` (`controller.ts`). It only works in local development environments and is disabled in remote (production/staging) environments.
|
|
327
327
|
|
|
328
|
-
###
|
|
328
|
+
### Parallel Test DB Flow
|
|
329
329
|
|
|
330
|
-
`test.parallel: true`
|
|
330
|
+
DB flow when `test.parallel: true` is set:
|
|
331
331
|
|
|
332
|
-
1. **globalSetup** (`global-setup.ts`): `{database.name}
|
|
333
|
-
2. **getSonamuTestConfig** (`vitest-helpers.ts`):
|
|
334
|
-
3. **DB.getDB** (`db.ts`): `SONAMU_WORKER_DB=true
|
|
335
|
-
4. **globalTeardown**:
|
|
332
|
+
1. **globalSetup** (`global-setup.ts`): Clones `{database.name}_test_1` through `_test_{maxWorkers}` from `{database.name}_test` as template
|
|
333
|
+
2. **getSonamuTestConfig** (`vitest-helpers.ts`): Injects `env: { SONAMU_WORKER_DB: "true" }` into vitest
|
|
334
|
+
3. **DB.getDB** (`db.ts`): When `SONAMU_WORKER_DB=true`, selects worker-specific DB using `VITEST_POOL_ID` environment variable (`{database.name}_test_{workerId}`)
|
|
335
|
+
4. **globalTeardown**: Deletes all worker DBs
|
|
336
336
|
|
|
337
|
-
`test.parallel: false`(
|
|
337
|
+
When `test.parallel: false` (default), all tests run sequentially on the single `{database.name}_test` DB.
|
|
338
338
|
|
|
339
339
|
---
|
|
340
340
|
|
|
341
|
-
##
|
|
341
|
+
## Configuration Files
|
|
342
342
|
|
|
343
343
|
### vitest.config.ts
|
|
344
344
|
|
|
@@ -367,15 +367,15 @@ dotenv.config();
|
|
|
367
367
|
export { setup } from "sonamu/test";
|
|
368
368
|
```
|
|
369
369
|
|
|
370
|
-
### sonamu.config.ts (test
|
|
370
|
+
### sonamu.config.ts (test configuration)
|
|
371
371
|
|
|
372
372
|
```typescript
|
|
373
373
|
export default defineConfig({
|
|
374
374
|
test: {
|
|
375
|
-
parallel: true, //
|
|
376
|
-
maxWorkers: 4, //
|
|
375
|
+
parallel: true, // Enable parallel testing
|
|
376
|
+
maxWorkers: 4, // Number of workers (default: 4)
|
|
377
377
|
devRunner: {
|
|
378
|
-
enabled: true, // DevRunner
|
|
378
|
+
enabled: true, // Enable DevRunner
|
|
379
379
|
},
|
|
380
380
|
},
|
|
381
381
|
});
|
|
@@ -383,8 +383,8 @@ export default defineConfig({
|
|
|
383
383
|
|
|
384
384
|
---
|
|
385
385
|
|
|
386
|
-
##
|
|
386
|
+
## References
|
|
387
387
|
|
|
388
|
-
-
|
|
389
|
-
- **Naite
|
|
388
|
+
- **Test writing guide**: `testing.md`
|
|
389
|
+
- **Naite tracing system**: `naite.md`
|
|
390
390
|
- **Fixture CLI**: `fixture-cli.md`
|