wynkjs 1.0.2 → 1.0.3
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 +163 -71
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/testing/index.d.ts +74 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +106 -0
- package/dist/testing/test-utils.d.ts +31 -0
- package/dist/testing/test-utils.d.ts.map +1 -0
- package/dist/testing/test-utils.js +72 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -371,12 +371,9 @@ wynkjs generate dto payment
|
|
|
371
371
|
wynkjs g m product
|
|
372
372
|
# Creates:
|
|
373
373
|
# src/modules/product/
|
|
374
|
-
# ├──
|
|
375
|
-
#
|
|
376
|
-
#
|
|
377
|
-
# │ └── product.service.ts # All CRUD methods
|
|
378
|
-
# └── dto/
|
|
379
|
-
# └── product.dto.ts # Validation schemas
|
|
374
|
+
# ├── product.controller.ts # Full CRUD controller
|
|
375
|
+
# ├── product.service.ts # All CRUD methods
|
|
376
|
+
# └── product.dto.ts # Validation schemas
|
|
380
377
|
```
|
|
381
378
|
|
|
382
379
|
**Auto-imports:** Controllers are automatically imported and added to `src/index.ts`!
|
|
@@ -597,8 +594,6 @@ export class UserService {
|
|
|
597
594
|
|
|
598
595
|
WynkJS provides automatic request validation with **full IntelliSense support** and customizable error formats:
|
|
599
596
|
|
|
600
|
-
> 💡 **New in v1.0.2**: Type `DTO.` and get full autocomplete! See [INTELLISENSE_GUIDE.md](./docs/INTELLISENSE_GUIDE.md)
|
|
601
|
-
|
|
602
597
|
```typescript
|
|
603
598
|
// user.dto.ts
|
|
604
599
|
import { DTO, CommonDTO } from "wynkjs";
|
|
@@ -699,7 +694,7 @@ const app = WynkFactory.create({
|
|
|
699
694
|
});
|
|
700
695
|
```
|
|
701
696
|
|
|
702
|
-
**See [VALIDATION_FORMATTERS.md](./VALIDATION_FORMATTERS.md) for all available error formats**
|
|
697
|
+
**See [VALIDATION_FORMATTERS.md](./docs-wynkjs/VALIDATION_FORMATTERS.md) for all available error formats**
|
|
703
698
|
|
|
704
699
|
### 🚫 Exception Handling
|
|
705
700
|
|
|
@@ -792,22 +787,38 @@ export class ApiController {
|
|
|
792
787
|
|
|
793
788
|
## 🏗️ Project Structure
|
|
794
789
|
|
|
790
|
+
Recommended project structure for WynkJS applications:
|
|
791
|
+
|
|
795
792
|
```
|
|
796
793
|
my-wynk-app/
|
|
797
794
|
├── src/
|
|
798
|
-
│ ├──
|
|
799
|
-
│ │
|
|
800
|
-
│ ├──
|
|
801
|
-
│ │
|
|
802
|
-
│
|
|
803
|
-
│ │ └──
|
|
795
|
+
│ ├── modules/
|
|
796
|
+
│ │ ├── user/
|
|
797
|
+
│ │ │ ├── user.controller.ts
|
|
798
|
+
│ │ │ ├── user.service.ts
|
|
799
|
+
│ │ │ └── user.dto.ts
|
|
800
|
+
│ │ └── product/
|
|
801
|
+
│ │ ├── product.controller.ts
|
|
802
|
+
│ │ ├── product.service.ts
|
|
803
|
+
│ │ └── product.dto.ts
|
|
804
804
|
│ ├── exceptions/
|
|
805
|
-
│ │ └──
|
|
805
|
+
│ │ └── custom.exceptions.ts
|
|
806
|
+
│ ├── guards/
|
|
807
|
+
│ │ └── auth.guard.ts
|
|
808
|
+
│ ├── filters/
|
|
809
|
+
│ │ └── http-exception.filter.ts
|
|
806
810
|
│ └── index.ts
|
|
807
811
|
├── package.json
|
|
808
812
|
└── tsconfig.json
|
|
809
813
|
```
|
|
810
814
|
|
|
815
|
+
**Module-based Organization:**
|
|
816
|
+
|
|
817
|
+
- Each feature/domain lives in its own module folder
|
|
818
|
+
- Controllers, services, and DTOs are co-located
|
|
819
|
+
- Easy to navigate and maintain
|
|
820
|
+
- Generated automatically by `wynkjs-cli`
|
|
821
|
+
|
|
811
822
|
---
|
|
812
823
|
|
|
813
824
|
## 🎨 Complete Working Example
|
|
@@ -1049,12 +1060,11 @@ npx create-wynkjs
|
|
|
1049
1060
|
```
|
|
1050
1061
|
my-wynkjs-app/
|
|
1051
1062
|
├── src/
|
|
1052
|
-
│ ├──
|
|
1053
|
-
│ │ └── user
|
|
1054
|
-
│ ├──
|
|
1055
|
-
│ │
|
|
1056
|
-
│
|
|
1057
|
-
│ │ └── user.dto.ts
|
|
1063
|
+
│ ├── modules/
|
|
1064
|
+
│ │ └── user/
|
|
1065
|
+
│ │ ├── user.controller.ts
|
|
1066
|
+
│ │ ├── user.service.ts
|
|
1067
|
+
│ │ └── user.dto.ts
|
|
1058
1068
|
│ └── index.ts
|
|
1059
1069
|
├── .eslintrc.json
|
|
1060
1070
|
├── .prettierrc
|
|
@@ -1078,8 +1088,7 @@ my-wynkjs-app/
|
|
|
1078
1088
|
|
|
1079
1089
|
- 📚 [Full Documentation](https://github.com/wynkjs/wynkjs-core)
|
|
1080
1090
|
- 🚀 [CLI Tool (create-wynkjs)](./packages/create-wynkjs/README.md)
|
|
1081
|
-
-
|
|
1082
|
-
- 🎨 [Validation Formatters](./VALIDATION_FORMATTERS.md)
|
|
1091
|
+
- 🎨 [Validation Formatters](./docs-wynkjs/VALIDATION_FORMATTERS.md)
|
|
1083
1092
|
- 📝 [Changelog](./CHANGELOG.md)
|
|
1084
1093
|
- 🐛 [Report Issues](https://github.com/wynkjs/wynkjs-core/issues)
|
|
1085
1094
|
|
|
@@ -1087,83 +1096,166 @@ my-wynkjs-app/
|
|
|
1087
1096
|
|
|
1088
1097
|
## 🤝 Contributing
|
|
1089
1098
|
|
|
1090
|
-
|
|
1099
|
+
We welcome contributions from the community! Whether you're fixing bugs, improving documentation, or proposing new features, your help is appreciated.
|
|
1091
1100
|
|
|
1092
|
-
|
|
1101
|
+
### 🐛 Reporting Issues
|
|
1093
1102
|
|
|
1094
|
-
|
|
1103
|
+
If you find a bug or have a feature request:
|
|
1095
1104
|
|
|
1096
|
-
|
|
1105
|
+
1. **Check existing issues** to avoid duplicates
|
|
1106
|
+
2. **Create a new issue** with a clear title and description
|
|
1107
|
+
3. **Provide details**: Steps to reproduce, expected behavior, actual behavior
|
|
1108
|
+
4. **Include environment info**: Bun version, OS, WynkJS version
|
|
1097
1109
|
|
|
1098
|
-
|
|
1110
|
+
[Report an issue →](https://github.com/wynkjs/wynkjs-core/issues)
|
|
1099
1111
|
|
|
1100
|
-
|
|
1112
|
+
### 💡 Contributing Code
|
|
1101
1113
|
|
|
1102
|
-
|
|
1103
|
-
- `globalGuards?: Array<Guard>` - Global guards (optional)
|
|
1104
|
-
- `globalInterceptors?: Array<Interceptor>` - Global interceptors (optional)
|
|
1105
|
-
- `globalPipes?: Array<Pipe>` - Global pipes (optional)
|
|
1106
|
-
- `globalFilters?: Array<Filter>` - Global exception filters (optional)
|
|
1114
|
+
#### Getting Started
|
|
1107
1115
|
|
|
1108
|
-
**
|
|
1116
|
+
1. **Fork the repository**
|
|
1109
1117
|
|
|
1110
|
-
|
|
1118
|
+
```bash
|
|
1119
|
+
# Fork on GitHub, then clone your fork
|
|
1120
|
+
git clone https://github.com/YOUR_USERNAME/wynkjs-core.git
|
|
1121
|
+
cd wynkjs-core
|
|
1122
|
+
```
|
|
1111
1123
|
|
|
1112
|
-
|
|
1124
|
+
2. **Install dependencies**
|
|
1113
1125
|
|
|
1114
|
-
|
|
1126
|
+
```bash
|
|
1127
|
+
bun install
|
|
1128
|
+
```
|
|
1115
1129
|
|
|
1116
|
-
|
|
1130
|
+
3. **Build the packages**
|
|
1117
1131
|
|
|
1118
|
-
|
|
1132
|
+
```bash
|
|
1133
|
+
# Build main framework
|
|
1134
|
+
bun run build
|
|
1119
1135
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
| Fastify | ~45,000 | ~2.2ms |
|
|
1125
|
-
| Express | ~12,000 | ~8.3ms |
|
|
1136
|
+
# Build CLI tools
|
|
1137
|
+
cd packages/create-wynkjs && bun run build
|
|
1138
|
+
cd ../wynkjs-cli && bun run build
|
|
1139
|
+
```
|
|
1126
1140
|
|
|
1127
|
-
|
|
1141
|
+
4. **Create a branch**
|
|
1142
|
+
```bash
|
|
1143
|
+
git checkout -b feature/your-feature-name
|
|
1144
|
+
# or
|
|
1145
|
+
git checkout -b fix/bug-description
|
|
1146
|
+
```
|
|
1128
1147
|
|
|
1129
|
-
|
|
1148
|
+
#### Development Workflow
|
|
1130
1149
|
|
|
1131
|
-
|
|
1150
|
+
1. **Make your changes** in the appropriate package:
|
|
1132
1151
|
|
|
1133
|
-
|
|
1152
|
+
- `core/` - Core framework decorators and utilities
|
|
1153
|
+
- `packages/create-wynkjs/` - Project scaffolding CLI
|
|
1154
|
+
- `packages/wynkjs-cli/` - Code generator CLI
|
|
1134
1155
|
|
|
1135
|
-
|
|
1156
|
+
2. **Test your changes**
|
|
1136
1157
|
|
|
1137
|
-
|
|
1158
|
+
```bash
|
|
1159
|
+
# Test in the example project
|
|
1160
|
+
cd example
|
|
1161
|
+
bun run dev
|
|
1138
1162
|
|
|
1139
|
-
|
|
1163
|
+
# Test CLI generation
|
|
1164
|
+
cd /tmp && bunx /path/to/wynkjs-core/packages/create-wynkjs
|
|
1165
|
+
```
|
|
1140
1166
|
|
|
1141
|
-
|
|
1167
|
+
3. **Build all packages**
|
|
1142
1168
|
|
|
1143
|
-
|
|
1169
|
+
```bash
|
|
1170
|
+
# From project root
|
|
1171
|
+
bun run build
|
|
1172
|
+
cd packages/create-wynkjs && bun run build
|
|
1173
|
+
cd ../wynkjs-cli && bun run build
|
|
1174
|
+
```
|
|
1144
1175
|
|
|
1145
|
-
|
|
1146
|
-
- [Issue Tracker](https://github.com/alamjamal/wynkjs/issues)
|
|
1147
|
-
- [Elysia Documentation](https://elysiajs.com/)
|
|
1148
|
-
- [TypeScript Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
|
|
1176
|
+
4. **Commit your changes**
|
|
1149
1177
|
|
|
1150
|
-
|
|
1178
|
+
```bash
|
|
1179
|
+
git add .
|
|
1180
|
+
git commit -m "feat: add new feature"
|
|
1181
|
+
# or
|
|
1182
|
+
git commit -m "fix: resolve issue with decorators"
|
|
1183
|
+
```
|
|
1151
1184
|
|
|
1152
|
-
|
|
1185
|
+
**Commit Convention:**
|
|
1153
1186
|
|
|
1154
|
-
|
|
1187
|
+
- `feat:` - New feature
|
|
1188
|
+
- `fix:` - Bug fix
|
|
1189
|
+
- `docs:` - Documentation changes
|
|
1190
|
+
- `refactor:` - Code refactoring
|
|
1191
|
+
- `test:` - Adding tests
|
|
1192
|
+
- `chore:` - Maintenance tasks
|
|
1155
1193
|
|
|
1156
|
-
|
|
1157
|
-
- [tsyringe](https://github.com/microsoft/tsyringe) - Dependency injection
|
|
1158
|
-
- [TypeScript](https://www.typescriptlang.org/) - Type safety
|
|
1194
|
+
5. **Push and create a Pull Request**
|
|
1159
1195
|
|
|
1160
|
-
|
|
1196
|
+
```bash
|
|
1197
|
+
git push origin feature/your-feature-name
|
|
1198
|
+
```
|
|
1161
1199
|
|
|
1162
|
-
|
|
1200
|
+
Then open a Pull Request on GitHub with:
|
|
1163
1201
|
|
|
1164
|
-
|
|
1202
|
+
- Clear description of changes
|
|
1203
|
+
- Link to related issues
|
|
1204
|
+
- Screenshots/examples if applicable
|
|
1165
1205
|
|
|
1166
|
-
|
|
1206
|
+
#### Code Style
|
|
1207
|
+
|
|
1208
|
+
- **TypeScript**: Strict mode enabled
|
|
1209
|
+
- **Formatting**: Use Prettier (run `bun run format` if available)
|
|
1210
|
+
- **Linting**: Follow ESLint rules
|
|
1211
|
+
- **Naming**:
|
|
1212
|
+
- PascalCase for classes and interfaces
|
|
1213
|
+
- camelCase for functions and variables
|
|
1214
|
+
- kebab-case for file names
|
|
1215
|
+
|
|
1216
|
+
#### Testing Guidelines
|
|
1217
|
+
|
|
1218
|
+
- Test your changes in the `example/` directory
|
|
1219
|
+
- Ensure existing examples still work
|
|
1220
|
+
- Add new examples for new features
|
|
1221
|
+
- Test CLI tools in a fresh directory
|
|
1222
|
+
|
|
1223
|
+
### 📝 Documentation
|
|
1224
|
+
|
|
1225
|
+
Documentation improvements are always welcome!
|
|
1226
|
+
|
|
1227
|
+
- **README updates**: Keep examples current and clear
|
|
1228
|
+
- **Code comments**: Add JSDoc comments for public APIs
|
|
1229
|
+
- **Guides**: Create helpful guides in `docs-wynkjs/`
|
|
1230
|
+
- **Examples**: Add real-world usage examples
|
|
1231
|
+
|
|
1232
|
+
### 🚀 Release Process (Maintainers)
|
|
1233
|
+
|
|
1234
|
+
1. Update `CHANGELOG.md` with changes
|
|
1235
|
+
2. Bump version in `package.json` files
|
|
1236
|
+
3. Build all packages
|
|
1237
|
+
4. Commit and tag the release
|
|
1238
|
+
5. Publish to npm:
|
|
1239
|
+
```bash
|
|
1240
|
+
npm publish --access public
|
|
1241
|
+
cd packages/create-wynkjs && npm publish --access public
|
|
1242
|
+
cd ../wynkjs-cli && npm publish --access public
|
|
1243
|
+
```
|
|
1244
|
+
|
|
1245
|
+
### 💬 Community
|
|
1246
|
+
|
|
1247
|
+
- **GitHub Discussions**: Ask questions and share ideas
|
|
1248
|
+
- **Discord**: (Coming soon) Join our community chat
|
|
1249
|
+
- **Twitter**: Follow [@wynkjs](https://twitter.com/wynkjs) for updates
|
|
1250
|
+
|
|
1251
|
+
### 📜 License
|
|
1252
|
+
|
|
1253
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|
|
1254
|
+
|
|
1255
|
+
---
|
|
1256
|
+
|
|
1257
|
+
**Thank you for contributing to WynkJS! 🎉**
|
|
1258
|
+
|
|
1259
|
+
```
|
|
1167
1260
|
|
|
1168
|
-
</div>
|
|
1169
1261
|
```
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,kBAAkB,CAAC;AAI1B,OAAO,EACL,UAAU,EACV,MAAM,EACN,SAAS,EACT,cAAc,EACd,QAAQ,EACR,SAAS,GACV,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpD,OAAO,EACL,UAAU,IAAI,UAAU,EACxB,MAAM,IAAI,MAAM,EAChB,SAAS,IAAI,SAAS,EACtB,cAAc,IAAI,cAAc,EAChC,QAAQ,IAAI,QAAQ,EACpB,SAAS,IAAI,SAAS,GACvB,MAAM,UAAU,CAAC;AAGlB,cAAc,8BAA8B,CAAC;AAG7C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAGlD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAI3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAIhD,cAAc,kCAAkC,CAAC;AASjD,cAAc,OAAO,CAAC;AAGtB,cAAc,WAAW,CAAC;AAE1B;;GAEG;AACH,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,kBAAkB,CAAC;AAI1B,OAAO,EACL,UAAU,EACV,MAAM,EACN,SAAS,EACT,cAAc,EACd,QAAQ,EACR,SAAS,GACV,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpD,OAAO,EACL,UAAU,IAAI,UAAU,EACxB,MAAM,IAAI,MAAM,EAChB,SAAS,IAAI,SAAS,EACtB,cAAc,IAAI,cAAc,EAChC,QAAQ,IAAI,QAAQ,EACpB,SAAS,IAAI,SAAS,GACvB,MAAM,UAAU,CAAC;AAGlB,cAAc,8BAA8B,CAAC;AAG7C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAGlD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAI3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAIhD,cAAc,kCAAkC,CAAC;AASjD,cAAc,OAAO,CAAC;AAGtB,cAAc,WAAW,CAAC;AAG1B,cAAc,WAAW,CAAC;AAE1B;;GAEG;AACH,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WynkJS Testing Module
|
|
3
|
+
* Provides utilities for testing WynkJS applications
|
|
4
|
+
* Similar to @nestjs/testing
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Test class for creating isolated testing modules
|
|
8
|
+
*/
|
|
9
|
+
export declare class Test {
|
|
10
|
+
/**
|
|
11
|
+
* Create a testing module with providers
|
|
12
|
+
* @param options Testing module options
|
|
13
|
+
* @returns TestingModule instance
|
|
14
|
+
*/
|
|
15
|
+
static createTestingModule(options: TestingModuleOptions): TestingModule;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for creating a testing module
|
|
19
|
+
*/
|
|
20
|
+
export interface TestingModuleOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Array of providers (services, classes) to register in the testing container
|
|
23
|
+
*/
|
|
24
|
+
providers?: any[];
|
|
25
|
+
/**
|
|
26
|
+
* Array of controllers to register in the testing container
|
|
27
|
+
*/
|
|
28
|
+
controllers?: any[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Testing module that provides isolated dependency injection container
|
|
32
|
+
*/
|
|
33
|
+
export declare class TestingModule {
|
|
34
|
+
private testContainer;
|
|
35
|
+
private providers;
|
|
36
|
+
private controllers;
|
|
37
|
+
constructor(options: TestingModuleOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Compile the testing module (register all providers and controllers)
|
|
40
|
+
*/
|
|
41
|
+
compile(): Promise<TestingModule>;
|
|
42
|
+
/**
|
|
43
|
+
* Get an instance of a provider from the testing container
|
|
44
|
+
* @param type The class/token to resolve
|
|
45
|
+
* @returns Instance of the requested type
|
|
46
|
+
*/
|
|
47
|
+
get<T>(type: any): T;
|
|
48
|
+
/**
|
|
49
|
+
* Close the testing module and clean up
|
|
50
|
+
*/
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Mock factory for creating mock instances
|
|
55
|
+
*/
|
|
56
|
+
export declare class MockFactory {
|
|
57
|
+
/**
|
|
58
|
+
* Create a mock object with methods
|
|
59
|
+
* @param methods Object with method names and return values
|
|
60
|
+
* @returns Mock object
|
|
61
|
+
*/
|
|
62
|
+
static createMock<T = any>(methods?: Record<string, any>): T;
|
|
63
|
+
/**
|
|
64
|
+
* Create a spy function that tracks calls
|
|
65
|
+
* @param implementation Optional implementation
|
|
66
|
+
* @returns Spy function
|
|
67
|
+
*/
|
|
68
|
+
static createSpy(implementation?: (...args: any[]) => any): any;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Export everything for convenient imports
|
|
72
|
+
*/
|
|
73
|
+
export * from "./test-utils";
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../core/testing/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;GAEG;AACH,qBAAa,IAAI;IACf;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa;CAGzE;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,WAAW,CAAQ;gBAEf,OAAO,EAAE,oBAAoB;IAOzC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IAcvC;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAIpB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,CAAC;IAchE;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,GAAG;CAiBhE;AAED;;GAEG;AACH,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WynkJS Testing Module
|
|
3
|
+
* Provides utilities for testing WynkJS applications
|
|
4
|
+
* Similar to @nestjs/testing
|
|
5
|
+
*/
|
|
6
|
+
import { container } from "tsyringe";
|
|
7
|
+
/**
|
|
8
|
+
* Test class for creating isolated testing modules
|
|
9
|
+
*/
|
|
10
|
+
export class Test {
|
|
11
|
+
/**
|
|
12
|
+
* Create a testing module with providers
|
|
13
|
+
* @param options Testing module options
|
|
14
|
+
* @returns TestingModule instance
|
|
15
|
+
*/
|
|
16
|
+
static createTestingModule(options) {
|
|
17
|
+
return new TestingModule(options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Testing module that provides isolated dependency injection container
|
|
22
|
+
*/
|
|
23
|
+
export class TestingModule {
|
|
24
|
+
testContainer;
|
|
25
|
+
providers;
|
|
26
|
+
controllers;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
// Create a child container for isolation
|
|
29
|
+
this.testContainer = container.createChildContainer();
|
|
30
|
+
this.providers = options.providers || [];
|
|
31
|
+
this.controllers = options.controllers || [];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compile the testing module (register all providers and controllers)
|
|
35
|
+
*/
|
|
36
|
+
async compile() {
|
|
37
|
+
// Register all providers
|
|
38
|
+
for (const provider of this.providers) {
|
|
39
|
+
this.testContainer.register(provider, { useClass: provider });
|
|
40
|
+
}
|
|
41
|
+
// Register all controllers
|
|
42
|
+
for (const controller of this.controllers) {
|
|
43
|
+
this.testContainer.register(controller, { useClass: controller });
|
|
44
|
+
}
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get an instance of a provider from the testing container
|
|
49
|
+
* @param type The class/token to resolve
|
|
50
|
+
* @returns Instance of the requested type
|
|
51
|
+
*/
|
|
52
|
+
get(type) {
|
|
53
|
+
return this.testContainer.resolve(type);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Close the testing module and clean up
|
|
57
|
+
*/
|
|
58
|
+
async close() {
|
|
59
|
+
// Reset the test container
|
|
60
|
+
this.testContainer.reset();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Mock factory for creating mock instances
|
|
65
|
+
*/
|
|
66
|
+
export class MockFactory {
|
|
67
|
+
/**
|
|
68
|
+
* Create a mock object with methods
|
|
69
|
+
* @param methods Object with method names and return values
|
|
70
|
+
* @returns Mock object
|
|
71
|
+
*/
|
|
72
|
+
static createMock(methods = {}) {
|
|
73
|
+
const mock = {};
|
|
74
|
+
for (const [key, value] of Object.entries(methods)) {
|
|
75
|
+
if (typeof value === "function") {
|
|
76
|
+
mock[key] = value;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
mock[key] = () => value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return mock;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a spy function that tracks calls
|
|
86
|
+
* @param implementation Optional implementation
|
|
87
|
+
* @returns Spy function
|
|
88
|
+
*/
|
|
89
|
+
static createSpy(implementation) {
|
|
90
|
+
const calls = [];
|
|
91
|
+
const spy = (...args) => {
|
|
92
|
+
calls.push(args);
|
|
93
|
+
return implementation ? implementation(...args) : undefined;
|
|
94
|
+
};
|
|
95
|
+
spy.calls = calls;
|
|
96
|
+
spy.mock = {
|
|
97
|
+
calls,
|
|
98
|
+
results: calls.map((args) => implementation ? implementation(...args) : undefined),
|
|
99
|
+
};
|
|
100
|
+
return spy;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Export everything for convenient imports
|
|
105
|
+
*/
|
|
106
|
+
export * from "./test-utils";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utilities and helpers
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create a mock request object for testing controllers
|
|
6
|
+
*/
|
|
7
|
+
export declare function createMockRequest(options?: {
|
|
8
|
+
method?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
body?: any;
|
|
11
|
+
params?: Record<string, string>;
|
|
12
|
+
query?: Record<string, any>;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}): any;
|
|
15
|
+
/**
|
|
16
|
+
* Create a mock response object for testing controllers
|
|
17
|
+
*/
|
|
18
|
+
export declare function createMockResponse(): any;
|
|
19
|
+
/**
|
|
20
|
+
* Create a mock execution context for testing guards, interceptors, etc.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createMockExecutionContext(request?: any, response?: any): any;
|
|
23
|
+
/**
|
|
24
|
+
* Assert that a value is defined (not null or undefined)
|
|
25
|
+
*/
|
|
26
|
+
export declare function assertDefined<T>(value: T | null | undefined): asserts value is T;
|
|
27
|
+
/**
|
|
28
|
+
* Assert that a value is an instance of a class
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertInstanceOf<T>(value: any, type: new (...args: any[]) => T): asserts value is T;
|
|
31
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../core/testing/test-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B,GACL,GAAG,CASL;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,GAAG,CAwBxC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,GAAyB,EAClC,QAAQ,GAAE,GAA0B,GACnC,GAAG,CASL;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAC1B,OAAO,CAAC,KAAK,IAAI,CAAC,CAIpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAC9B,OAAO,CAAC,KAAK,IAAI,CAAC,CAIpB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utilities and helpers
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create a mock request object for testing controllers
|
|
6
|
+
*/
|
|
7
|
+
export function createMockRequest(options = {}) {
|
|
8
|
+
return {
|
|
9
|
+
method: options.method || "GET",
|
|
10
|
+
url: options.url || "/",
|
|
11
|
+
body: options.body || {},
|
|
12
|
+
params: options.params || {},
|
|
13
|
+
query: options.query || {},
|
|
14
|
+
headers: options.headers || {},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a mock response object for testing controllers
|
|
19
|
+
*/
|
|
20
|
+
export function createMockResponse() {
|
|
21
|
+
const response = {
|
|
22
|
+
statusCode: 200,
|
|
23
|
+
headers: {},
|
|
24
|
+
body: null,
|
|
25
|
+
status: function (code) {
|
|
26
|
+
this.statusCode = code;
|
|
27
|
+
return this;
|
|
28
|
+
},
|
|
29
|
+
send: function (data) {
|
|
30
|
+
this.body = data;
|
|
31
|
+
return this;
|
|
32
|
+
},
|
|
33
|
+
json: function (data) {
|
|
34
|
+
this.body = data;
|
|
35
|
+
return this;
|
|
36
|
+
},
|
|
37
|
+
setHeader: function (name, value) {
|
|
38
|
+
this.headers[name] = value;
|
|
39
|
+
return this;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a mock execution context for testing guards, interceptors, etc.
|
|
46
|
+
*/
|
|
47
|
+
export function createMockExecutionContext(request = createMockRequest(), response = createMockResponse()) {
|
|
48
|
+
return {
|
|
49
|
+
getRequest: () => request,
|
|
50
|
+
getResponse: () => response,
|
|
51
|
+
switchToHttp: () => ({
|
|
52
|
+
getRequest: () => request,
|
|
53
|
+
getResponse: () => response,
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Assert that a value is defined (not null or undefined)
|
|
59
|
+
*/
|
|
60
|
+
export function assertDefined(value) {
|
|
61
|
+
if (value === null || value === undefined) {
|
|
62
|
+
throw new Error("Expected value to be defined");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Assert that a value is an instance of a class
|
|
67
|
+
*/
|
|
68
|
+
export function assertInstanceOf(value, type) {
|
|
69
|
+
if (!(value instanceof type)) {
|
|
70
|
+
throw new Error(`Expected value to be instance of ${type.name}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
package/package.json
CHANGED