create-dp-koa 1.0.0
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 +50 -0
- package/index.mjs +97 -0
- package/package.json +33 -0
- package/template/.env.development +9 -0
- package/template/.env.production +12 -0
- package/template/.github/workflows/ci-cd.yml +182 -0
- package/template/.trae/documents/controller_development_plan.md +386 -0
- package/template/.trae/skills/00-backend-core.skill.md +50 -0
- package/template/.trae/skills/01-backend-skill-router.skill.md +55 -0
- package/template/.trae/skills/10-backend-api.skill.md +54 -0
- package/template/.trae/skills/11-backend-controller-recipes.skill.md +107 -0
- package/template/.trae/skills/20-backend-repository.skill.md +25 -0
- package/template/.trae/skills/21-backend-service.skill.md +135 -0
- package/template/.trae/skills/25-backend-comments-and-doc.skill.md +97 -0
- package/template/.trae/skills/30-backend-validation.skill.md +320 -0
- package/template/.trae/skills/40-backend-error-logging.skill.md +21 -0
- package/template/.trae/skills/50-backend-bootstrap-lifecycle.skill.md +90 -0
- package/template/.trae/skills/60-backend-router-registration.skill.md +71 -0
- package/template/.trae/skills/70-backend-middleware.skill.md +98 -0
- package/template/.trae/skills/80-backend-utils-and-libs.skill.md +90 -0
- package/template/.trae/skills/85-backend-plugins.rule.md +64 -0
- package/template/.trae/skills/90-backend-testing.skill.md +29 -0
- package/template/.trae/skills/README.md +49 -0
- package/template/.vscode/launch.json +38 -0
- package/template/.vscode/settings.json +1 -0
- package/template/Dockerfile +36 -0
- package/template/README.md +229 -0
- package/template/docker-compose.yml +135 -0
- package/template/docs/API_DOCUMENTATION.md +837 -0
- package/template/docs/ARCHITECTURE_REFACTOR.md +109 -0
- package/template/docs/CACHE_MIGRATION_GUIDE.md +142 -0
- package/template/docs/DEPLOYMENT_GUIDE.md +1062 -0
- package/template/docs/DEVELOPMENT_GUIDE.md +1097 -0
- package/template/docs/DOCUMENTATION_CLEANUP_REPORT.md +166 -0
- package/template/docs/DOCUMENTATION_COMPLETION_REPORT.md +223 -0
- package/template/docs/DOCUMENTATION_INDEX.md +294 -0
- package/template/docs/DOCUMENTATION_STRUCTURE.md +221 -0
- package/template/docs/ENTERPRISE_ANNOTATION_SYSTEM_GUIDE.md +2069 -0
- package/template/docs/ENTERPRISE_DATABASE_ARCHITECTURE.md +318 -0
- package/template/docs/ENTERPRISE_DEPLOYMENT_GUIDE.md +547 -0
- package/template/docs/ENTERPRISE_ERROR_HANDLING_GUIDE.md +357 -0
- package/template/docs/ENTERPRISE_LOGGING_SYSTEM_GUIDE.md +494 -0
- package/template/docs/ENVIRONMENT_CONFIG_EXAMPLE.md +69 -0
- package/template/docs/FINAL_IMPLEMENTATION_SUMMARY.md +206 -0
- package/template/docs/HEALTH_CHECK_ROUTE_FIX.md +134 -0
- package/template/docs/IMPLEMENTATION_CHECKLIST.md +204 -0
- package/template/docs/INSTALLATION_GUIDE.md +611 -0
- package/template/docs/INTERCEPTOR_TESTING_REPORT.md +226 -0
- package/template/docs/INTERCEPTOR_TESTING_SCRIPTS.md +143 -0
- package/template/docs/LOGGING_OPTIMIZATION_GUIDE.md +126 -0
- package/template/docs/MEMORY_DATABASE_GUIDE.md +212 -0
- package/template/docs/NEW_ROUTER_INTEGRATION_GUIDE.md +345 -0
- package/template/docs/NEW_ROUTER_INTEGRATION_SUMMARY.md +259 -0
- package/template/docs/NEW_ROUTER_USAGE_GUIDE.md +364 -0
- package/template/docs/QUICK_START.md +268 -0
- package/template/docs/ROUTE_SLASH_COMPATIBILITY_FIX.md +191 -0
- package/template/docs/SERVICE_INTERCEPTOR_GUIDE.md +243 -0
- package/template/docs/SERVICE_LAYER_INDEX.md +205 -0
- package/template/docs/SERVICE_PATTERN_GUIDE.md +270 -0
- package/template/docs/SERVICE_RETURN_VALUE_SPECIFICATION.md +466 -0
- package/template/docs/SWAGGER_DEBUG_MODE_GUIDE.md +80 -0
- package/template/docs/SWAGGER_INTEGRATION_GUIDE.md +416 -0
- package/template/docs/TRANSACTION_MANAGER_USAGE.md +360 -0
- package/template/docs/TROUBLESHOOTING.md +869 -0
- package/template/env.production.example +62 -0
- package/template/jest.config.js +34 -0
- package/template/package-lock.json +13240 -0
- package/template/package.json +119 -0
- package/template/patches/typeorm+0.3.25.patch +22 -0
- package/template/scripts/sync-template.mjs +84 -0
- package/template/scripts/test-annotation-system.sh +48 -0
- package/template/scripts/test-core-functionality.sh +28 -0
- package/template/src/annotations/decorators/ConfigManagement.ts +9 -0
- package/template/src/annotations/decorators/DistributedTracing.ts +9 -0
- package/template/src/annotations/decorators/EnterprisePerformance.ts +9 -0
- package/template/src/annotations/decorators/PerformanceMonitor.ts +32 -0
- package/template/src/annotations/decorators/SecurityAudit.ts +9 -0
- package/template/src/annotations/index.ts +50 -0
- package/template/src/annotations/processors/ConfigManagementProcessor.ts +369 -0
- package/template/src/annotations/processors/DistributedTracingProcessor.ts +288 -0
- package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +189 -0
- package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +101 -0
- package/template/src/annotations/processors/SecurityAuditProcessor.ts +345 -0
- package/template/src/annotations/processors/SwaggerProcessor.ts +612 -0
- package/template/src/annotations/processors/index.ts +10 -0
- package/template/src/app.ts +123 -0
- package/template/src/controllers/base.controller.ts +41 -0
- package/template/src/controllers/cacheManagement.controller.ts +131 -0
- package/template/src/controllers/captcha.controller.ts +57 -0
- package/template/src/controllers/demo/AnnotationDemoController.ts +118 -0
- package/template/src/controllers/example/EnterpriseExampleController.ts +297 -0
- package/template/src/controllers/example/ExampleController.ts +110 -0
- package/template/src/controllers/example/NewAnnotationExampleController.ts +159 -0
- package/template/src/controllers/example/SwaggerExampleController.ts +205 -0
- package/template/src/controllers/example/TransactionExample.controller.ts +336 -0
- package/template/src/controllers/health.controller.ts +235 -0
- package/template/src/controllers/home/register.controller.ts +58 -0
- package/template/src/controllers/home/ytGoods.controller.ts +92 -0
- package/template/src/controllers/home/ytShop.controller.ts +135 -0
- package/template/src/controllers/home/ytUser.controller.ts +89 -0
- package/template/src/controllers/logManagement.controller.ts +396 -0
- package/template/src/controllers/public/emailSend.controller.ts +65 -0
- package/template/src/controllers/public/ytUserAuth.controller.ts +174 -0
- package/template/src/controllers/testData.controller.ts +253 -0
- package/template/src/dto/controller/example/NewAnnotationExampleController.dto.ts +73 -0
- package/template/src/dto/controller/home/emailSend.controller.dto.ts +40 -0
- package/template/src/dto/controller/home/register.controller.dto.ts +45 -0
- package/template/src/dto/controller/home/ytGoods.controller.dto.ts +55 -0
- package/template/src/dto/controller/home/ytShop.controller.dto.ts +69 -0
- package/template/src/dto/controller/home/ytUser.controller.dto.ts +44 -0
- package/template/src/dto/controller/public/ytUserAuth.controller.dto.ts +63 -0
- package/template/src/dto/goods.dto.ts +212 -0
- package/template/src/dto/service/ytService.dto.ts +13 -0
- package/template/src/dto/user.dto.ts +177 -0
- package/template/src/entity/base.entity.ts +13 -0
- package/template/src/entity/columnTypes.ts +13 -0
- package/template/src/entity/goodsImagesUnlockKey.entity.ts +33 -0
- package/template/src/entity/goodsUnlocker.entity.ts +34 -0
- package/template/src/entity/index.ts +15 -0
- package/template/src/entity/shop.entity.ts +52 -0
- package/template/src/entity/shopUser.entity.ts +41 -0
- package/template/src/entity/ytGoods.entity.ts +94 -0
- package/template/src/entity/ytUser.entity.ts +96 -0
- package/template/src/examples/InterceptorExampleRunner.ts +284 -0
- package/template/src/examples/ServiceInterceptorExample.ts +214 -0
- package/template/src/examples/SwaggerProcessorExample.ts +169 -0
- package/template/src/examples/TransactionManagerDemo.ts +377 -0
- package/template/src/examples/cacheExamples.ts +155 -0
- package/template/src/framework/decorator/controller.ts +311 -0
- package/template/src/framework/decorator/processor/AnnotationDecorators.ts +100 -0
- package/template/src/framework/decorator/processor/AnnotationProcessor.ts +156 -0
- package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +45 -0
- package/template/src/framework/decorator/processor/AnnotationRegistry.ts +117 -0
- package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +95 -0
- package/template/src/framework/decorator/processor/ProcessorManager.ts +76 -0
- package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +126 -0
- package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +207 -0
- package/template/src/framework/decorator/refactored/DecoratorFactory.ts +99 -0
- package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +125 -0
- package/template/src/framework/decorator/refactored/DecoratorValidator.ts +128 -0
- package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +139 -0
- package/template/src/framework/decorator/refactored/index.ts +98 -0
- package/template/src/framework/decorator/swagger.ts +150 -0
- package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +375 -0
- package/template/src/framework/interceptors/ServiceCallInterceptor.ts +348 -0
- package/template/src/framework/interceptors/index.ts +19 -0
- package/template/src/framework/plugins/registry.ts +63 -0
- package/template/src/framework/plugins/types.ts +15 -0
- package/template/src/framework/types/ServiceResult.ts +151 -0
- package/template/src/framework/types/index.ts +16 -0
- package/template/src/framework/utils/CacheManager.ts +430 -0
- package/template/src/framework/utils/CacheService.ts +248 -0
- package/template/src/framework/utils/DtoValidator.ts +164 -0
- package/template/src/framework/utils/MigrationHelper.ts +179 -0
- package/template/src/framework/utils/MigrationManager.ts +256 -0
- package/template/src/framework/utils/NewRouter.ts +207 -0
- package/template/src/framework/utils/TransactionManager.ts +172 -0
- package/template/src/framework/utils/bootstrap.ts +445 -0
- package/template/src/framework/utils/cache.ts +269 -0
- package/template/src/framework/utils/databaseConfig.ts +148 -0
- package/template/src/framework/utils/db.ts +39 -0
- package/template/src/framework/utils/dbMonitor.ts +106 -0
- package/template/src/framework/utils/dynamicSwagger.ts +410 -0
- package/template/src/framework/utils/function.ts +61 -0
- package/template/src/framework/utils/gracefulShutdown.ts +131 -0
- package/template/src/framework/utils/logger.ts +388 -0
- package/template/src/framework/utils/metrics.ts +182 -0
- package/template/src/framework/utils/router.ts +417 -0
- package/template/src/framework/utils/swagger.ts +184 -0
- package/template/src/framework/utils/testDb.ts +19 -0
- package/template/src/framework/utils/token.ts +23 -0
- package/template/src/framework/utils/transform.ts +17 -0
- package/template/src/libs/aokEmailSender.ts +42 -0
- package/template/src/libs/captcha.ts +37 -0
- package/template/src/libs/cos.ts +45 -0
- package/template/src/libs/mCache.ts +7 -0
- package/template/src/libs/serviceValidate.ts +3 -0
- package/template/src/libs/tecentSms.ts +51 -0
- package/template/src/middlewares/a.middleware.ts +6 -0
- package/template/src/middlewares/error.middleware.ts +14 -0
- package/template/src/middlewares/logging.middleware.ts +187 -0
- package/template/src/middlewares/static.middleware.ts +79 -0
- package/template/src/middlewares/swagger.middleware.ts +70 -0
- package/template/src/middlewares/token.middleware.ts +32 -0
- package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +172 -0
- package/template/src/migrations/index.ts +6 -0
- package/template/src/plugins/weboffice/core/context.ts +47 -0
- package/template/src/plugins/weboffice/core/errors.ts +51 -0
- package/template/src/plugins/weboffice/core/types.ts +63 -0
- package/template/src/plugins/weboffice/core/utils.ts +7 -0
- package/template/src/plugins/weboffice/entities/index.ts +3 -0
- package/template/src/plugins/weboffice/entities/webofficeFile.entity.ts +28 -0
- package/template/src/plugins/weboffice/entities/webofficeFileVersion.entity.ts +29 -0
- package/template/src/plugins/weboffice/http/routes.ts +179 -0
- package/template/src/plugins/weboffice/index.ts +23 -0
- package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +274 -0
- package/template/src/repository/UserRepository.ts +122 -0
- package/template/src/repository/base/BaseRepository.ts +124 -0
- package/template/src/repository/interfaces/IBaseRepository.ts +67 -0
- package/template/src/routers/index.ts +49 -0
- package/template/src/service/base.service.ts +116 -0
- package/template/src/service/paramValidateTest.service.ts +139 -0
- package/template/src/service/ytGoods.service.ts +42 -0
- package/template/src/service/ytShop.service.ts +90 -0
- package/template/src/service/ytUser.service.ts +451 -0
- package/template/src/test/swaggerParameterTest.ts +90 -0
- package/template/src/utils/testDataInitializer.ts +296 -0
- package/template/static/output.json +15203 -0
- package/template/test/controllers/controllers.test.ts +173 -0
- package/template/test/controllers/example/ExampleController.test.ts +222 -0
- package/template/test/controllers/example/NewAnnotationExampleController.test.ts +200 -0
- package/template/test/framework/TransactionManagerDemo.test.ts +363 -0
- package/template/test/framework/annotation/AnnotationDecorators.test.ts +222 -0
- package/template/test/framework/annotation/AnnotationExecutor.test.ts +246 -0
- package/template/test/framework/annotation/AnnotationProcessor.test.ts +179 -0
- package/template/test/framework/annotation/CustomProcessors.test.ts +313 -0
- package/template/test/framework/annotation/DefaultProcessors.test.ts +371 -0
- package/template/test/framework/annotation/NewRouter.test.ts +272 -0
- package/template/test/framework/annotation/ProcessorManager.test.ts +248 -0
- package/template/test/framework/annotation/setup.ts +26 -0
- package/template/test/framework/cache.test.ts +101 -0
- package/template/test/framework/databaseConfig.test.ts +142 -0
- package/template/test/integration/integration.test.ts +153 -0
- package/template/test/plugins/weboffice/http.routes.int.test.ts +61 -0
- package/template/test/service/business.test.ts +87 -0
- package/template/test/service/paramValidateTest.service.test.ts +184 -0
- package/template/test/service/ytUser.service.test.ts +566 -0
- package/template/test/setup.ts +20 -0
- package/template/test/setupAfterEnv.ts +14 -0
- package/template/test/utils/testHelpers.ts +220 -0
- package/template/test_output.txt +0 -0
- package/template/tsconfig.build.json +17 -0
- package/template/tsconfig.json +31 -0
- package/template/webpack.config.js +71 -0
- package/template/yarn.lock +7354 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
import { getDataSource, initDb, closeDb } from '../../src/framework/utils/db';
|
|
3
|
+
import { testDataInitializer } from '../../src/utils/testDataInitializer';
|
|
4
|
+
import { clearAllCaches } from '../../src/framework/utils/cache';
|
|
5
|
+
import { transactionManager } from '../../src/framework/utils/TransactionManager';
|
|
6
|
+
import entities from '../../src/entity/index';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 测试数据库工具类
|
|
10
|
+
*/
|
|
11
|
+
export class TestDatabaseHelper {
|
|
12
|
+
private static dataSource: DataSource | null = null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 初始化测试数据库
|
|
16
|
+
*/
|
|
17
|
+
static async initTestDatabase(options?: { extraEntities?: any[] }): Promise<void> {
|
|
18
|
+
if (this.dataSource) {
|
|
19
|
+
return; // 已经初始化过了
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 创建内存数据库配置
|
|
23
|
+
// 自动从 src/entity/index.ts 导入所有实体,避免手动维护实体列表
|
|
24
|
+
const config = {
|
|
25
|
+
type: "sqlite" as const,
|
|
26
|
+
database: ":memory:",
|
|
27
|
+
entities: options?.extraEntities?.length ? [...entities, ...options.extraEntities] : entities,
|
|
28
|
+
synchronize: true,
|
|
29
|
+
logging: false,
|
|
30
|
+
dropSchema: true,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
await initDb(config);
|
|
34
|
+
this.dataSource = getDataSource();
|
|
35
|
+
|
|
36
|
+
// 设置 TransactionManager 的数据源
|
|
37
|
+
if (this.dataSource) {
|
|
38
|
+
transactionManager.setDataSource(this.dataSource);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 初始化测试数据
|
|
42
|
+
await testDataInitializer.initializeTestData();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 清理测试数据库
|
|
47
|
+
*/
|
|
48
|
+
static async cleanupTestDatabase(): Promise<void> {
|
|
49
|
+
if (this.dataSource) {
|
|
50
|
+
await closeDb();
|
|
51
|
+
this.dataSource = null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 清理缓存
|
|
55
|
+
clearAllCaches();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 关闭测试数据库(别名方法)
|
|
60
|
+
*/
|
|
61
|
+
static async closeTestDatabase(): Promise<void> {
|
|
62
|
+
return this.cleanupTestDatabase();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 获取测试数据源
|
|
67
|
+
*/
|
|
68
|
+
static getTestDataSource(): DataSource | null {
|
|
69
|
+
return this.dataSource;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 重置测试数据
|
|
74
|
+
*/
|
|
75
|
+
static async resetTestData(): Promise<void> {
|
|
76
|
+
if (this.dataSource) {
|
|
77
|
+
await testDataInitializer.clearTestData();
|
|
78
|
+
await testDataInitializer.initializeTestData();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 测试工具函数
|
|
85
|
+
*/
|
|
86
|
+
export class TestUtils {
|
|
87
|
+
/**
|
|
88
|
+
* 创建测试用户数据
|
|
89
|
+
*/
|
|
90
|
+
static createTestUser(overrides: any = {}) {
|
|
91
|
+
return {
|
|
92
|
+
nickName: "测试用户",
|
|
93
|
+
email: "test@example.com",
|
|
94
|
+
telnumber: "13800138000",
|
|
95
|
+
userType: 1,
|
|
96
|
+
status: 1,
|
|
97
|
+
avatar: "https://example.com/avatar.jpg",
|
|
98
|
+
gender: 1,
|
|
99
|
+
age: 25,
|
|
100
|
+
constellation: "白羊座",
|
|
101
|
+
...overrides
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 创建测试店铺数据
|
|
107
|
+
*/
|
|
108
|
+
static createTestShop(overrides: any = {}) {
|
|
109
|
+
return {
|
|
110
|
+
name: "测试店铺",
|
|
111
|
+
description: "这是一个测试店铺",
|
|
112
|
+
status: "NORMAL",
|
|
113
|
+
...overrides
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 创建测试商品数据
|
|
119
|
+
*/
|
|
120
|
+
static createTestGoods(overrides: any = {}) {
|
|
121
|
+
return {
|
|
122
|
+
name: "测试商品",
|
|
123
|
+
description: "这是一个测试商品",
|
|
124
|
+
price: 99.99,
|
|
125
|
+
albums: ["https://example.com/goods1.jpg"],
|
|
126
|
+
tags: ["测试", "商品"],
|
|
127
|
+
content: "测试商品内容",
|
|
128
|
+
imagesContent: ["https://example.com/content1.jpg"],
|
|
129
|
+
shopId: 1,
|
|
130
|
+
status: "NORMAL",
|
|
131
|
+
...overrides
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 等待指定时间
|
|
137
|
+
*/
|
|
138
|
+
static async wait(ms: number): Promise<void> {
|
|
139
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 生成随机字符串
|
|
144
|
+
*/
|
|
145
|
+
static generateRandomString(length: number = 10): string {
|
|
146
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
147
|
+
let result = '';
|
|
148
|
+
for (let i = 0; i < length; i++) {
|
|
149
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 生成随机邮箱
|
|
156
|
+
*/
|
|
157
|
+
static generateRandomEmail(): string {
|
|
158
|
+
return `test_${this.generateRandomString(8)}@example.com`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 生成随机手机号
|
|
163
|
+
*/
|
|
164
|
+
static generateRandomPhone(): string {
|
|
165
|
+
return `138${Math.floor(Math.random() * 100000000).toString().padStart(8, '0')}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 创建模拟的Koa上下文
|
|
170
|
+
*/
|
|
171
|
+
static createMockContext(state: any = {}, query: any = {}) {
|
|
172
|
+
return {
|
|
173
|
+
state,
|
|
174
|
+
query,
|
|
175
|
+
params: {},
|
|
176
|
+
body: {},
|
|
177
|
+
headers: {},
|
|
178
|
+
method: 'GET',
|
|
179
|
+
url: '/test',
|
|
180
|
+
ip: '127.0.0.1',
|
|
181
|
+
requestId: this.generateRandomString(8),
|
|
182
|
+
userId: 'test-user',
|
|
183
|
+
set: jest.fn(),
|
|
184
|
+
get: jest.fn(),
|
|
185
|
+
remove: jest.fn(),
|
|
186
|
+
status: 200
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 创建模拟的请求对象
|
|
192
|
+
*/
|
|
193
|
+
static createMockRequest(method: string = 'GET', url: string = '/test', body: any = {}) {
|
|
194
|
+
return {
|
|
195
|
+
method,
|
|
196
|
+
url,
|
|
197
|
+
body,
|
|
198
|
+
headers: {
|
|
199
|
+
'content-type': 'application/json',
|
|
200
|
+
'user-agent': 'test-agent'
|
|
201
|
+
},
|
|
202
|
+
query: {},
|
|
203
|
+
params: {}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 创建模拟的响应对象
|
|
209
|
+
*/
|
|
210
|
+
static createMockResponse() {
|
|
211
|
+
return {
|
|
212
|
+
status: 200,
|
|
213
|
+
body: null,
|
|
214
|
+
headers: {},
|
|
215
|
+
set: jest.fn(),
|
|
216
|
+
get: jest.fn(),
|
|
217
|
+
remove: jest.fn()
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES6",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"experimentalDecorators": true,
|
|
13
|
+
"emitDecoratorMetadata": true,
|
|
14
|
+
"paths": {
|
|
15
|
+
"@src/*": [
|
|
16
|
+
"./src/*"
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
"strictPropertyInitialization": false
|
|
20
|
+
},
|
|
21
|
+
"types": [
|
|
22
|
+
"jest"
|
|
23
|
+
],
|
|
24
|
+
"include": [
|
|
25
|
+
"src/**/*.ts"
|
|
26
|
+
],
|
|
27
|
+
"exclude": [
|
|
28
|
+
"node_modules",
|
|
29
|
+
"dist"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const CopyPlugin = require('copy-webpack-plugin');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
target: 'node',
|
|
6
|
+
entry: {
|
|
7
|
+
main: './src/app.ts',
|
|
8
|
+
},
|
|
9
|
+
output: {
|
|
10
|
+
path: path.resolve(__dirname, 'dist'),
|
|
11
|
+
filename: '[name].js',
|
|
12
|
+
},
|
|
13
|
+
resolve: {
|
|
14
|
+
alias: {
|
|
15
|
+
'@src': path.resolve(__dirname, 'src/')
|
|
16
|
+
},
|
|
17
|
+
extensions: ['.ts', '.js'],
|
|
18
|
+
},
|
|
19
|
+
module: {
|
|
20
|
+
rules: [
|
|
21
|
+
{
|
|
22
|
+
test: /\.ts$/,
|
|
23
|
+
use: {
|
|
24
|
+
loader: 'ts-loader',
|
|
25
|
+
options: {
|
|
26
|
+
configFile: 'tsconfig.build.json',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
exclude: /node_modules/,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
plugins: [
|
|
34
|
+
new CopyPlugin({
|
|
35
|
+
patterns: [
|
|
36
|
+
{ from: '.env.production', to: './' },
|
|
37
|
+
{ from: 'package.json', to: './' },
|
|
38
|
+
]
|
|
39
|
+
})
|
|
40
|
+
],
|
|
41
|
+
externals: {
|
|
42
|
+
'express': 'commonjs express',
|
|
43
|
+
'koa-router': 'commonjs koa-router',
|
|
44
|
+
'koa': 'commonjs koa',
|
|
45
|
+
'koa-body': 'commonjs koa-body',
|
|
46
|
+
'log4js': 'commonjs log4js',
|
|
47
|
+
'socks5': 'commonjs socks5',
|
|
48
|
+
'multer': 'commonjs multer',
|
|
49
|
+
'cos-nodejs-sdk-v5': 'commonjs cos-nodejs-sdk-v5',
|
|
50
|
+
'dotenv': 'commonjs dotenv',
|
|
51
|
+
'edge-js': 'commonjs edge-js',
|
|
52
|
+
'jsonwebtoken': 'commonjs jsonwebtoken',
|
|
53
|
+
'typeorm': 'commonjs typeorm',
|
|
54
|
+
'class-validator': 'commonjs class-validator',
|
|
55
|
+
'md5': 'commonjs md5',
|
|
56
|
+
'module-alias': 'commonjs module-alias',
|
|
57
|
+
'mysql': 'commonjs mysql',
|
|
58
|
+
'mysql2': 'commonjs mysql2',
|
|
59
|
+
'node-cache': 'commonjs node-cache',
|
|
60
|
+
'tencentcloud-sdk-nodejs': 'commonjs tencentcloud-sdk-nodejs',
|
|
61
|
+
'svg-captcha': 'commonjs svg-captcha',
|
|
62
|
+
'sqlite3': 'commonjs sqlite3',
|
|
63
|
+
'sql.js': 'commonjs sql.js',
|
|
64
|
+
'koa2-swagger-ui': 'commonjs koa2-swagger-ui',
|
|
65
|
+
'swagger-jsdoc': 'commonjs swagger-jsdoc',
|
|
66
|
+
},
|
|
67
|
+
ignoreWarnings: [
|
|
68
|
+
/require\.extensions is not supported by webpack/,
|
|
69
|
+
/Critical dependency: the request of a dependency is an expression/,
|
|
70
|
+
],
|
|
71
|
+
};
|