nest-monitor 0.3.3 → 0.3.4
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/auto-test/auto-test.decorator.d.ts +2 -3
- package/dist/auto-test/auto-test.decorator.js +3 -7
- package/dist/auto-test/auto-test.module.d.ts +1 -0
- package/dist/auto-test/auto-test.module.js +21 -10
- package/dist/auto-test/auto-test.service.d.ts +3 -5
- package/dist/auto-test/auto-test.service.js +26 -28
- package/dist/interfaces/auto-test-endpoint.interface.d.ts +4 -0
- package/package.json +1 -1
- package/dist/interfaces/auto-test-metadata.interface.d.ts +0 -6
- /package/dist/interfaces/{auto-test-metadata.interface.js → auto-test-endpoint.interface.js} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Помечает
|
|
3
|
-
* @param path Относительный путь к эндпоинту (например, '/health')
|
|
2
|
+
* Помечает весь контроллер для автоматического тестирования всех GET-эндпоинтов.
|
|
4
3
|
*/
|
|
5
|
-
export declare const AutoTest: (
|
|
4
|
+
export declare const AutoTest: () => ClassDecorator;
|
|
@@ -4,13 +4,9 @@ exports.AutoTest = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const auto_test_constants_1 = require("./auto-test.constants");
|
|
6
6
|
/**
|
|
7
|
-
* Помечает
|
|
8
|
-
* @param path Относительный путь к эндпоинту (например, '/health')
|
|
7
|
+
* Помечает весь контроллер для автоматического тестирования всех GET-эндпоинтов.
|
|
9
8
|
*/
|
|
10
|
-
const AutoTest = (
|
|
11
|
-
return (0, common_1.SetMetadata)(auto_test_constants_1.AUTO_TEST_METADATA,
|
|
12
|
-
path,
|
|
13
|
-
method: 'GET',
|
|
14
|
-
});
|
|
9
|
+
const AutoTest = () => {
|
|
10
|
+
return (0, common_1.SetMetadata)(auto_test_constants_1.AUTO_TEST_METADATA, true);
|
|
15
11
|
};
|
|
16
12
|
exports.AutoTest = AutoTest;
|
|
@@ -23,18 +23,29 @@ let AutoTestModule = class AutoTestModule {
|
|
|
23
23
|
}
|
|
24
24
|
onModuleInit() {
|
|
25
25
|
const controllers = this.discoveryService.getControllers();
|
|
26
|
-
for (const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
for (const wrapper of controllers) {
|
|
27
|
+
const metatype = wrapper.metatype;
|
|
28
|
+
const shouldAutoTest = this.reflector.get(auto_test_constants_1.AUTO_TEST_METADATA, metatype);
|
|
29
|
+
if (!shouldAutoTest)
|
|
30
|
+
continue;
|
|
31
|
+
const endpoints = this.extractGetEndpoints(metatype);
|
|
32
|
+
const controllerName = metatype.name || 'UnknownController';
|
|
33
|
+
this.autoTestService.registerControllerEndpoints(controllerName, endpoints);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
extractGetEndpoints(metatype) {
|
|
37
|
+
const endpoints = [];
|
|
38
|
+
const prototype = Object.getPrototypeOf(metatype.prototype);
|
|
39
|
+
const methodNames = Object.getOwnPropertyNames(prototype).filter((name) => name !== 'constructor' && typeof prototype[name] === 'function');
|
|
40
|
+
for (const methodName of methodNames) {
|
|
41
|
+
const methodRef = prototype[methodName];
|
|
42
|
+
const routePath = Reflect.getMetadata('path', methodRef);
|
|
43
|
+
const requestMethod = Reflect.getMetadata('method', methodRef);
|
|
44
|
+
if (routePath !== undefined && requestMethod === 0) {
|
|
45
|
+
endpoints.push({ path: routePath, methodName });
|
|
36
46
|
}
|
|
37
47
|
}
|
|
48
|
+
return endpoints;
|
|
38
49
|
}
|
|
39
50
|
};
|
|
40
51
|
exports.AutoTestModule = AutoTestModule;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { HttpService } from '@nestjs/axios';
|
|
2
2
|
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
3
|
-
import {
|
|
4
|
-
import { IAutoTestMetadata } from '../interfaces/auto-test-metadata.interface';
|
|
3
|
+
import { IAutoTestEndpoint } from '../interfaces/auto-test-endpoint.interface';
|
|
5
4
|
export declare class AutoTestService implements OnApplicationBootstrap {
|
|
6
5
|
private readonly httpService;
|
|
7
|
-
private readonly reflector;
|
|
8
6
|
private endpoints;
|
|
9
|
-
constructor(httpService: HttpService
|
|
10
|
-
|
|
7
|
+
constructor(httpService: HttpService);
|
|
8
|
+
registerControllerEndpoints(controllerName: string, endpoints: IAutoTestEndpoint[]): void;
|
|
11
9
|
onApplicationBootstrap(): Promise<void>;
|
|
12
10
|
}
|
|
@@ -12,52 +12,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AutoTestService = void 0;
|
|
13
13
|
const axios_1 = require("@nestjs/axios");
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
-
const core_1 = require("@nestjs/core");
|
|
16
15
|
const rxjs_1 = require("rxjs");
|
|
17
16
|
let AutoTestService = class AutoTestService {
|
|
18
|
-
constructor(httpService
|
|
17
|
+
constructor(httpService) {
|
|
19
18
|
this.httpService = httpService;
|
|
20
|
-
this.reflector = reflector;
|
|
21
19
|
this.endpoints = [];
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
methodName,
|
|
28
|
-
});
|
|
21
|
+
registerControllerEndpoints(controllerName, endpoints) {
|
|
22
|
+
if (endpoints.length > 0) {
|
|
23
|
+
this.endpoints.push({ controllerName, endpoints });
|
|
24
|
+
}
|
|
29
25
|
}
|
|
30
26
|
async onApplicationBootstrap() {
|
|
31
27
|
if (this.endpoints.length === 0) {
|
|
32
|
-
console.log('[AutoTest] Нет
|
|
28
|
+
console.log('[AutoTest] Нет контроллеров для автоматического тестирования.');
|
|
33
29
|
return;
|
|
34
30
|
}
|
|
35
|
-
console.log(`\n[AutoTest] Запуск
|
|
31
|
+
console.log(`\n[AutoTest] Запуск тестов для ${this.endpoints.length} контроллеров...\n`);
|
|
36
32
|
const host = process.env.HOST || '127.0.0.1';
|
|
37
33
|
const port = process.env.PORT || '3000';
|
|
38
34
|
const baseUrl = `http://${host}:${port}`;
|
|
39
|
-
for (const
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
for (const { controllerName, endpoints } of this.endpoints) {
|
|
36
|
+
console.log(`\n🔍 [AutoTest] Контроллер: ${controllerName}`);
|
|
37
|
+
for (const endpoint of endpoints) {
|
|
38
|
+
const url = `${baseUrl}${endpoint.path}`;
|
|
39
|
+
const start = Date.now();
|
|
40
|
+
try {
|
|
41
|
+
console.log(` → Тестирую: GET ${url}`);
|
|
42
|
+
const response = await (0, rxjs_1.firstValueFrom)(this.httpService.get(url));
|
|
43
|
+
const duration = Date.now() - start;
|
|
44
|
+
console.log(` ✅ УСПЕХ: статус ${response.status} (${duration}мс)`);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
const duration = Date.now() - start;
|
|
48
|
+
const status = error.response?.status || '???';
|
|
49
|
+
const message = error.message || 'Неизвестная ошибка';
|
|
50
|
+
console.error(` ❌ ОШИБКА: статус ${status} (${duration}мс) — ${message}`);
|
|
51
|
+
}
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
console.log('[AutoTest] Автоматическое тестирование завершено.\n');
|
|
54
|
+
console.log('\n[AutoTest] Автоматическое тестирование завершено.\n');
|
|
56
55
|
}
|
|
57
56
|
};
|
|
58
57
|
exports.AutoTestService = AutoTestService;
|
|
59
58
|
exports.AutoTestService = AutoTestService = __decorate([
|
|
60
59
|
(0, common_1.Injectable)(),
|
|
61
|
-
__metadata("design:paramtypes", [axios_1.HttpService
|
|
62
|
-
core_1.Reflector])
|
|
60
|
+
__metadata("design:paramtypes", [axios_1.HttpService])
|
|
63
61
|
], AutoTestService);
|
package/package.json
CHANGED
/package/dist/interfaces/{auto-test-metadata.interface.js → auto-test-endpoint.interface.js}
RENAMED
|
File without changes
|