@elsikora/cladi 2.1.0 → 2.1.1-dev.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/README.md +36 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
- [Project Structure](#-project-structure)
|
|
30
30
|
- [Prerequisites](#-prerequisites)
|
|
31
31
|
- [Installation](#-installation)
|
|
32
|
+
- [Testing Toolkit](#-testing-toolkit)
|
|
32
33
|
- [Usage](#-usage)
|
|
33
34
|
- [API Quick Reference](#-api-quick-reference)
|
|
34
35
|
- [Production Bootstrap](#-production-bootstrap)
|
|
@@ -81,6 +82,7 @@ ClaDI ships with **5 provider strategies** (`useValue`, `useClass`, `useFactory`
|
|
|
81
82
|
- ✨ **Module System** — `createModule()` and `composeModules()` enable declarative, bounded-context module composition with explicit export contracts
|
|
82
83
|
- ✨ **Decorator Support** — Optional `@Injectable()`, `@Inject()`, `@Module()`, `@OnInit()`, `@AfterResolve()`, and `@OnDispose()` without requiring `reflect-metadata`
|
|
83
84
|
- ✨ **Decorator Composition Helpers** — `autowire()`, `createModuleFromDecorator()`, and `composeDecoratedModules()` keep decorator workflows explicit but concise
|
|
85
|
+
- ✨ **Companion Testing Toolkit** — `@elsikora/cladi-testing` adds test container helpers (`createTestingContainer`, `mockProvider`, `overrideProvider`) for app-level integration and unit tests
|
|
84
86
|
- ✨ **Runtime Diagnostics** — `explain(token)`, `snapshot()`, and `exportGraph()` provide operational visibility into provider lookup and dependency edges
|
|
85
87
|
- ✨ **Deterministic Disposal** — `dispose()` waits for in-flight async resolutions, runs disposers in reverse order, and supports `Symbol.dispose` / `Symbol.asyncDispose`
|
|
86
88
|
- ✨ **Resolve Interceptors** — Hook into every resolution with `onStart`, `onSuccess`, and `onError` callbacks for logging, metrics, or tracing
|
|
@@ -301,6 +303,40 @@ npm run test:all
|
|
|
301
303
|
npm run lint:all
|
|
302
304
|
```
|
|
303
305
|
|
|
306
|
+
## 🧪 Testing Toolkit
|
|
307
|
+
|
|
308
|
+
For application tests, use the companion package `@elsikora/cladi-testing` with ClaDI `>=2.1.0`:
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
npm install -D @elsikora/cladi @elsikora/cladi-testing
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
import { createModule, createToken } from "@elsikora/cladi";
|
|
316
|
+
import { createTestingContainer, mockProvider, overrideProvider, resetTestingContainer } from "@elsikora/cladi-testing";
|
|
317
|
+
|
|
318
|
+
const UserRepoToken = createToken<{ findNameById(id: string): string | undefined }>("UserRepo");
|
|
319
|
+
const UserServiceToken = createToken<{ readName(id: string): string }>("UserService");
|
|
320
|
+
|
|
321
|
+
const appModule = createModule({
|
|
322
|
+
exports: [UserServiceToken],
|
|
323
|
+
providers: [
|
|
324
|
+
mockProvider(UserRepoToken, { findNameById: () => "Alice" }),
|
|
325
|
+
{
|
|
326
|
+
deps: [UserRepoToken],
|
|
327
|
+
provide: UserServiceToken,
|
|
328
|
+
useFactory: (repository) => ({
|
|
329
|
+
readName: (id: string): string => repository.findNameById(id) ?? "unknown",
|
|
330
|
+
}),
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
const container = createTestingContainer({ modules: [appModule], shouldValidateOnCreate: true });
|
|
336
|
+
await overrideProvider(container, mockProvider(UserRepoToken, { findNameById: () => "Bob" }));
|
|
337
|
+
await resetTestingContainer(container);
|
|
338
|
+
```
|
|
339
|
+
|
|
304
340
|
## 💡 Usage
|
|
305
341
|
|
|
306
342
|
### Quick Start — Your First Composition Root
|