@rfprodz/backend-diagnostics 1.0.39 → 1.1.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/LICENSE +1 -1
- package/README.md +7 -5
- package/lib/controllers/diagnostics.controller.d.ts +2 -2
- package/lib/diagnostics.module.d.ts +0 -3
- package/lib/diagnostics.module.d.ts.map +1 -1
- package/lib/diagnostics.module.js +0 -3
- package/lib/gateway/diagnostics.gateway.d.ts +1 -12
- package/lib/gateway/diagnostics.gateway.d.ts.map +1 -1
- package/lib/gateway/diagnostics.gateway.js +1 -10
- package/lib/interfaces/diagnostics.interface.d.ts +1 -1
- package/lib/interfaces/diagnostics.interface.d.ts.map +1 -1
- package/lib/services/diagnostics.service.js +1 -1
- package/package.json +17 -14
- package/lib/controllers/diagnostics.controller.spec.d.ts +0 -2
- package/lib/controllers/diagnostics.controller.spec.d.ts.map +0 -1
- package/lib/controllers/diagnostics.controller.spec.js +0 -45
- package/lib/gateway/diagnostics.gateway.spec.d.ts +0 -2
- package/lib/gateway/diagnostics.gateway.spec.d.ts.map +0 -1
- package/lib/gateway/diagnostics.gateway.spec.js +0 -85
- package/lib/services/diagnostics.service.spec.d.ts +0 -2
- package/lib/services/diagnostics.service.spec.d.ts.map +0 -1
- package/lib/services/diagnostics.service.spec.js +0 -67
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# backend-diagnostics
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Description
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npx nx run tools:help --search backend-diagnostics:
|
|
9
|
-
```
|
|
7
|
+
Diagnostics module for NestJS backends.
|
|
10
8
|
|
|
11
9
|
## Usage
|
|
12
10
|
|
|
@@ -55,6 +53,10 @@ void bootstrap(server);
|
|
|
55
53
|
|
|
56
54
|
```
|
|
57
55
|
|
|
56
|
+
### Examples
|
|
57
|
+
|
|
58
|
+
Example of using the diagnostics module in [the API application module](https://github.com/rfprod/nx-ng-starter/blob/main/apps/api/src/app/api.module.ts#L66)
|
|
59
|
+
|
|
58
60
|
## References
|
|
59
61
|
|
|
60
62
|
- [Nx](https://nx.dev)
|
|
@@ -2,7 +2,7 @@ import type { IDiagnosticsService } from '../interfaces/diagnostics.interface';
|
|
|
2
2
|
export declare class AppDiagnosticsController {
|
|
3
3
|
private readonly diagnosticsService;
|
|
4
4
|
constructor(diagnosticsService: IDiagnosticsService);
|
|
5
|
-
ping(): import("
|
|
6
|
-
static(): import("rxjs").Observable<import("
|
|
5
|
+
ping(): import("../..").IPingResult;
|
|
6
|
+
static(): import("rxjs").Observable<import("../..").TDiagData>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=diagnostics.controller.d.ts.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { DynamicModule, OnModuleDestroy, Provider } from '@nestjs/common';
|
|
2
2
|
import { AppDiagnosticsGateway } from './gateway/diagnostics.gateway';
|
|
3
|
-
/**
|
|
4
|
-
* Provider definitions for the diagnostics module.
|
|
5
|
-
*/
|
|
6
3
|
export declare const diagnosticsModuleProviders: Provider[];
|
|
7
4
|
export declare class AppDiagnosticsModule implements OnModuleDestroy {
|
|
8
5
|
private readonly gateway;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.module.d.ts","sourceRoot":"","sources":["../../../../libs/backend-diagnostics/src/lib/diagnostics.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAIlF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnostics.module.d.ts","sourceRoot":"","sources":["../../../../libs/backend-diagnostics/src/lib/diagnostics.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAIlF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAMtE,eAAO,MAAM,0BAA0B,EAAE,QAAQ,EAWhD,CAAC;AAEF,qBAGa,oBAAqB,YAAW,eAAe;IAQ9C,OAAO,CAAC,QAAQ,CAAC,OAAO;WAPtB,OAAO,IAAI,aAAa;gBAOT,OAAO,EAAE,qBAAqB;IAEpD,eAAe;CAGvB"}
|
|
@@ -5,9 +5,6 @@ import { exec } from 'child_process';
|
|
|
5
5
|
import { AppDiagnosticsController } from './controllers/diagnostics.controller';
|
|
6
6
|
import { AppDiagnosticsGateway } from './gateway/diagnostics.gateway';
|
|
7
7
|
import { AppDiagnosticsService, CHILD_PROCESS_EXEC, DIAGNOSTICS_SERVICE_TOKEN } from './services/diagnostics.service';
|
|
8
|
-
/**
|
|
9
|
-
* Provider definitions for the diagnostics module.
|
|
10
|
-
*/
|
|
11
8
|
export const diagnosticsModuleProviders = [
|
|
12
9
|
AppDiagnosticsService,
|
|
13
10
|
AppDiagnosticsGateway,
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { OnGatewayConnection, OnGatewayDisconnect } from '@nestjs/websockets';
|
|
2
|
-
import { Server, WebSocket } from 'ws';
|
|
2
|
+
import { type Server, WebSocket } from 'ws';
|
|
3
3
|
import { AppDiagnosticsService } from '../services/diagnostics.service';
|
|
4
4
|
export declare class AppDiagnosticsGateway implements OnGatewayConnection, OnGatewayDisconnect {
|
|
5
5
|
private readonly service;
|
|
6
|
-
/**
|
|
7
|
-
* Platform-specific server instance.
|
|
8
|
-
*/
|
|
9
6
|
protected server?: Server;
|
|
10
7
|
private dynamicDataSub?;
|
|
11
8
|
constructor(service: AppDiagnosticsService);
|
|
12
|
-
/**
|
|
13
|
-
* Sends an event to a client.
|
|
14
|
-
* @param client web socket client
|
|
15
|
-
* @param data stringified event data
|
|
16
|
-
*/
|
|
17
9
|
sendEvent(client: WebSocket, data: string): void;
|
|
18
|
-
/**
|
|
19
|
-
* Broadcasts an event to all connected users.
|
|
20
|
-
*/
|
|
21
10
|
broadcastEvent<T = Record<string, unknown>>(event: T): void;
|
|
22
11
|
private sendClientChangeEvent;
|
|
23
12
|
handleConnection(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.gateway.d.ts","sourceRoot":"","sources":["../../../../../libs/backend-diagnostics/src/lib/gateway/diagnostics.gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EAKpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnostics.gateway.d.ts","sourceRoot":"","sources":["../../../../../libs/backend-diagnostics/src/lib/gateway/diagnostics.gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EAKpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,KAAK,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAG5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,qBAIa,qBAAsB,YAAW,mBAAmB,EAAE,mBAAmB;IASxE,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAE1B,OAAO,CAAC,cAAc,CAAC,CAAe;gBAET,OAAO,EAAE,qBAAqB;IAOpD,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;IAOzC,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAUlE,OAAO,CAAC,qBAAqB;IAehB,gBAAgB;IAIhB,gBAAgB;IAKtB,4BAA4B;IAkB5B,2BAA2B;CAMnC"}
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { SubscribeMessage, WebSocketGateway, WebSocketServer, } from '@nestjs/websockets';
|
|
3
3
|
import { tap, timer } from 'rxjs';
|
|
4
|
-
import { Server } from 'ws';
|
|
5
4
|
import { dianosticEventsGatewayPort } from '../interfaces/diagnostics.interface';
|
|
6
5
|
import { AppDiagnosticsService } from '../services/diagnostics.service';
|
|
7
6
|
let AppDiagnosticsGateway = class AppDiagnosticsGateway {
|
|
8
7
|
constructor(service) {
|
|
9
8
|
this.service = service;
|
|
10
9
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Sends an event to a client.
|
|
13
|
-
* @param client web socket client
|
|
14
|
-
* @param data stringified event data
|
|
15
|
-
*/
|
|
16
10
|
sendEvent(client, data) {
|
|
17
11
|
client.send(data);
|
|
18
12
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Broadcasts an event to all connected users.
|
|
21
|
-
*/
|
|
22
13
|
broadcastEvent(event) {
|
|
23
14
|
if (typeof this.server !== 'undefined') {
|
|
24
15
|
const clients = this.server.clients.values();
|
|
@@ -71,7 +62,7 @@ let AppDiagnosticsGateway = class AppDiagnosticsGateway {
|
|
|
71
62
|
};
|
|
72
63
|
__decorate([
|
|
73
64
|
WebSocketServer(),
|
|
74
|
-
__metadata("design:type",
|
|
65
|
+
__metadata("design:type", Function)
|
|
75
66
|
], AppDiagnosticsGateway.prototype, "server", void 0);
|
|
76
67
|
__decorate([
|
|
77
68
|
SubscribeMessage('start-diag'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.interface.d.ts","sourceRoot":"","sources":["../../../../../libs/backend-diagnostics/src/lib/interfaces/diagnostics.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnostics.interface.d.ts","sourceRoot":"","sources":["../../../../../libs/backend-diagnostics/src/lib/interfaces/diagnostics.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEvC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC;AAExC,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,aAAa,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,IAAI,WAAW,CAAC;IAEpB,MAAM,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;IAEhC,OAAO,IAAI,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,0BAA0B,OAAO,CAAC"}
|
|
@@ -13,7 +13,7 @@ let AppDiagnosticsService = class AppDiagnosticsService {
|
|
|
13
13
|
npmVersion() {
|
|
14
14
|
const observable$ = new Observable(subscriber => {
|
|
15
15
|
let version = 'N/A';
|
|
16
|
-
if (typeof process.env
|
|
16
|
+
if (typeof process.env['ELECTRON'] !== 'undefined') {
|
|
17
17
|
subscriber.next(version);
|
|
18
18
|
subscriber.complete();
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rfprodz/backend-diagnostics",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "NestJS API diagnostics module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nestjs-controller",
|
|
@@ -14,31 +14,34 @@
|
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "https://github.com/rfprod/nx-ng-starter"
|
|
17
|
+
"url": "git+https://github.com/rfprod/nx-ng-starter.git"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"author": "rfprod <zoidenmacht@zoho.com>",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"ws": "8.18.0"
|
|
22
|
+
"tslib": "2.8.1",
|
|
23
|
+
"ws": "8.18.3"
|
|
25
24
|
},
|
|
26
25
|
"peerDependencies": {
|
|
27
|
-
"@nestjs/common": "
|
|
28
|
-
"@nestjs/platform-ws": "
|
|
29
|
-
"@nestjs/websockets": "
|
|
30
|
-
"dotenv": "
|
|
31
|
-
"rxjs": "7.8.
|
|
26
|
+
"@nestjs/common": "11.1.12",
|
|
27
|
+
"@nestjs/platform-ws": "11.1.12",
|
|
28
|
+
"@nestjs/websockets": "11.1.12",
|
|
29
|
+
"dotenv": "17.2.3",
|
|
30
|
+
"rxjs": "7.8.2"
|
|
32
31
|
},
|
|
33
|
-
"packageManager": "yarn@
|
|
32
|
+
"packageManager": "yarn@4.12.0",
|
|
34
33
|
"resolutions": {
|
|
34
|
+
"@types/minimatch": "=5.1.2",
|
|
35
35
|
"colors": "1.4.0",
|
|
36
|
+
"minimatch": ">=10.0.3",
|
|
36
37
|
"semver": ">=7.5.3",
|
|
37
|
-
"
|
|
38
|
+
"vite": "7.3.1",
|
|
39
|
+
"vitest": "4.0.18",
|
|
40
|
+
"webpack": "5.104.1",
|
|
38
41
|
"word-wrap": ">=1.2.4"
|
|
39
42
|
},
|
|
43
|
+
"types": "./index.d.ts",
|
|
40
44
|
"module": "./index.js",
|
|
41
45
|
"type": "module",
|
|
42
|
-
"main": "./index.js"
|
|
43
|
-
"types": "./src/index.d.ts"
|
|
46
|
+
"main": "./index.js"
|
|
44
47
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.controller.spec.d.ts","sourceRoot":"","sources":["../../../../../libs/backend-diagnostics/src/lib/controllers/diagnostics.controller.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Test } from '@nestjs/testing';
|
|
2
|
-
import { firstValueFrom, of } from 'rxjs';
|
|
3
|
-
import { diagnosticsModuleProviders } from '../diagnostics.module';
|
|
4
|
-
import { AppDiagnosticsService } from '../services/diagnostics.service';
|
|
5
|
-
import { AppDiagnosticsController } from './diagnostics.controller';
|
|
6
|
-
describe('AppDiagnosticsController', () => {
|
|
7
|
-
let testingModule;
|
|
8
|
-
let diagController;
|
|
9
|
-
let diagService;
|
|
10
|
-
let diagServiceSpy;
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
await Test.createTestingModule({
|
|
13
|
-
controllers: [AppDiagnosticsController],
|
|
14
|
-
providers: [...diagnosticsModuleProviders],
|
|
15
|
-
})
|
|
16
|
-
.compile()
|
|
17
|
-
.then(module => {
|
|
18
|
-
testingModule = module;
|
|
19
|
-
diagController = testingModule.get(AppDiagnosticsController);
|
|
20
|
-
diagService = testingModule.get(AppDiagnosticsService);
|
|
21
|
-
diagServiceSpy = {
|
|
22
|
-
ping: jest.spyOn(diagService, 'ping').mockReturnValue({
|
|
23
|
-
message: 'Diagnostics service is online. Routes: /, /static.',
|
|
24
|
-
}),
|
|
25
|
-
static: jest.spyOn(diagService, 'static').mockReturnValue(of([
|
|
26
|
-
{
|
|
27
|
-
name: 'Node.js Version',
|
|
28
|
-
value: process.version.replace('v', ''),
|
|
29
|
-
},
|
|
30
|
-
])),
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
it('ping should return "Diagnostics service is online. Routes: /, /static."', () => {
|
|
35
|
-
expect(diagController.ping()).toEqual({
|
|
36
|
-
message: 'Diagnostics service is online. Routes: /, /static.',
|
|
37
|
-
});
|
|
38
|
-
expect(diagServiceSpy.ping).toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
it('static should return static diagnostic data', async () => {
|
|
41
|
-
const staticData = await firstValueFrom(diagController.static());
|
|
42
|
-
expect(staticData).toEqual(expect.any(Array));
|
|
43
|
-
expect(diagServiceSpy.static).toHaveBeenCalled();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.gateway.spec.d.ts","sourceRoot":"","sources":["../../../../../libs/backend-diagnostics/src/lib/gateway/diagnostics.gateway.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { WsAdapter } from '@nestjs/platform-ws';
|
|
2
|
-
import { Test } from '@nestjs/testing';
|
|
3
|
-
import { Server, WebSocket } from 'ws';
|
|
4
|
-
import { AppDiagnosticsService } from '../services/diagnostics.service';
|
|
5
|
-
import { AppDiagnosticsGateway } from './diagnostics.gateway';
|
|
6
|
-
const addWsClient = (server, wsClient) => {
|
|
7
|
-
if (typeof wsClient !== 'undefined') {
|
|
8
|
-
server.clients.add(wsClient);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
const removeWsClient = (server, wsClient) => {
|
|
12
|
-
if (typeof wsClient !== 'undefined') {
|
|
13
|
-
server.clients.clear();
|
|
14
|
-
server.clients.delete(wsClient);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
describe('AppDiagnosticsGateway', () => {
|
|
18
|
-
let testingModule;
|
|
19
|
-
let gateway;
|
|
20
|
-
let gatewaySpy;
|
|
21
|
-
let app;
|
|
22
|
-
const appPort = 8082;
|
|
23
|
-
let wsClient;
|
|
24
|
-
let server;
|
|
25
|
-
beforeAll(async () => {
|
|
26
|
-
await Test.createTestingModule({
|
|
27
|
-
providers: [
|
|
28
|
-
AppDiagnosticsGateway,
|
|
29
|
-
{
|
|
30
|
-
provide: AppDiagnosticsService,
|
|
31
|
-
useValue: {
|
|
32
|
-
dinamyc: () => [],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
})
|
|
37
|
-
.compile()
|
|
38
|
-
.then(async (module) => {
|
|
39
|
-
testingModule = module;
|
|
40
|
-
app = testingModule.createNestApplication();
|
|
41
|
-
app.useWebSocketAdapter(new WsAdapter(app));
|
|
42
|
-
await app.listen(appPort, '0.0.0.0');
|
|
43
|
-
const appUrl = await app.getUrl();
|
|
44
|
-
server = new Server({ server: app.getHttpServer() });
|
|
45
|
-
gateway = testingModule.get(AppDiagnosticsGateway);
|
|
46
|
-
gatewaySpy = {
|
|
47
|
-
sendEvent: jest.spyOn(gateway, 'sendEvent'),
|
|
48
|
-
broadcastEvent: jest.spyOn(gateway, 'broadcastEvent'),
|
|
49
|
-
};
|
|
50
|
-
gateway['server'] = server;
|
|
51
|
-
const wsUrl = `${appUrl.replace(/http/, 'ws')}/api/events`;
|
|
52
|
-
wsClient = new WebSocket(wsUrl);
|
|
53
|
-
wsClient.send = () => true;
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
afterEach(() => {
|
|
57
|
-
gatewaySpy.sendEvent.mockReset();
|
|
58
|
-
gatewaySpy.broadcastEvent.mockReset();
|
|
59
|
-
});
|
|
60
|
-
afterAll(async () => {
|
|
61
|
-
gateway.stopSendingDiagnosticEvents();
|
|
62
|
-
server.removeAllListeners();
|
|
63
|
-
app.getMicroservices().forEach(async (service) => {
|
|
64
|
-
await service.close();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
it('handleConnection should call broadcastEvent', async () => {
|
|
68
|
-
expect(wsClient).toBeDefined();
|
|
69
|
-
addWsClient(server, wsClient);
|
|
70
|
-
await gateway.handleConnection();
|
|
71
|
-
expect(gatewaySpy.broadcastEvent).toHaveBeenCalledWith({ data: [{ name: 'active', value: 1 }], event: 'users' });
|
|
72
|
-
expect(gatewaySpy.sendEvent).toHaveBeenCalled();
|
|
73
|
-
removeWsClient(server, wsClient);
|
|
74
|
-
gatewaySpy.sendEvent.mockClear();
|
|
75
|
-
});
|
|
76
|
-
it('handleDisconnect should call broadcastEvent', async () => {
|
|
77
|
-
await gateway.handleDisconnect();
|
|
78
|
-
expect(gatewaySpy.broadcastEvent).toHaveBeenCalledWith({ data: [{ name: 'active', value: 0 }], event: 'users' });
|
|
79
|
-
expect(gatewaySpy.sendEvent).not.toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
it('handleConnection should not send an event with currently connected users count if input value is not provided and here are no connected users', async () => {
|
|
82
|
-
await gateway.handleConnection();
|
|
83
|
-
expect(gatewaySpy.sendEvent).not.toHaveBeenCalled();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.service.spec.d.ts","sourceRoot":"","sources":["../../../../../libs/backend-diagnostics/src/lib/services/diagnostics.service.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Test } from '@nestjs/testing';
|
|
2
|
-
import { firstValueFrom } from 'rxjs';
|
|
3
|
-
import { AppDiagnosticsService, CHILD_PROCESS_EXEC } from './diagnostics.service';
|
|
4
|
-
describe('AppDiagnosticsService', () => {
|
|
5
|
-
let testingModule;
|
|
6
|
-
let service;
|
|
7
|
-
describe('success cases', () => {
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
await Test.createTestingModule({
|
|
10
|
-
providers: [
|
|
11
|
-
AppDiagnosticsService,
|
|
12
|
-
{
|
|
13
|
-
provide: CHILD_PROCESS_EXEC,
|
|
14
|
-
useValue: (command, callback) => callback(null, 'stdout', 'stderr'),
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
})
|
|
18
|
-
.compile()
|
|
19
|
-
.then(module => {
|
|
20
|
-
testingModule = module;
|
|
21
|
-
service = testingModule.get(AppDiagnosticsService);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
it('should return "Diagnostics service is online. Routes: /, /static."', () => {
|
|
25
|
-
expect(service.ping()).toEqual({
|
|
26
|
-
message: 'Diagnostics service is online. Routes: /, /static.',
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
it('static should return static diagnostic data', async () => {
|
|
30
|
-
const staticData = await firstValueFrom(service.static());
|
|
31
|
-
expect(staticData).toEqual(expect.any(Array));
|
|
32
|
-
});
|
|
33
|
-
it('dynamic should return dynamic diagnostic data', () => {
|
|
34
|
-
expect(service.dynamic()).toEqual(expect.any(Array));
|
|
35
|
-
});
|
|
36
|
-
it('npmVersion should return N/A for electron env', async () => {
|
|
37
|
-
process.env.ELECTRON = 'true';
|
|
38
|
-
const staticData = await firstValueFrom(service.static());
|
|
39
|
-
expect(staticData.find(item => item.name === 'NPM Version')?.value).toEqual('N/A');
|
|
40
|
-
delete process.env.ELECTRON;
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
test.todo('Debug error case');
|
|
44
|
-
// describe('error case', () => {
|
|
45
|
-
// beforeEach(async () => {
|
|
46
|
-
// await Test.createTestingModule({
|
|
47
|
-
// providers: [
|
|
48
|
-
// AppDiagnosticsService,
|
|
49
|
-
// {
|
|
50
|
-
// provide: CHILD_PROCESS_EXEC,
|
|
51
|
-
// useValue: (command: string, callback: (error: ExecException | null, stdout: string, stderr: string) => unknown) =>
|
|
52
|
-
// callback(new Error('error'), 'stdout', 'stderr'),
|
|
53
|
-
// },
|
|
54
|
-
// ],
|
|
55
|
-
// })
|
|
56
|
-
// .compile()
|
|
57
|
-
// .then(module => {
|
|
58
|
-
// testingModule = module;
|
|
59
|
-
// service = testingModule.get<AppDiagnosticsService>(AppDiagnosticsService);
|
|
60
|
-
// });
|
|
61
|
-
// });
|
|
62
|
-
// it('npmVersion should return N/A if exec error occurs', async () => {
|
|
63
|
-
// const staticData = await firstValueFrom(service.static());
|
|
64
|
-
// expect(staticData.find(item => item.name === 'NPM Version')?.value).toEqual('N/A');
|
|
65
|
-
// });
|
|
66
|
-
// });
|
|
67
|
-
});
|