@nathapp/nestjs-health 3.3.0 → 4.0.1
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/package.json +13 -15
- package/.eslintrc.js +0 -8
- package/.nax/features/nestjs-health/.nax-acceptance.test.ts +0 -756
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -15
- package/lib/constant/health.constants.ts +0 -23
- package/lib/constant/index.ts +0 -1
- package/lib/controller/health.controller.ts +0 -37
- package/lib/controller/index.ts +0 -1
- package/lib/index.ts +0 -6
- package/lib/indicator/cache-health.check.ts +0 -59
- package/lib/indicator/generic-health.check.ts +0 -43
- package/lib/indicator/index.ts +0 -4
- package/lib/indicator/prisma-health.check.ts +0 -59
- package/lib/indicator/queue-health.check.ts +0 -72
- package/lib/interface/health-indicator.interface.ts +0 -18
- package/lib/interface/health-module-options.interface.ts +0 -85
- package/lib/interface/index.ts +0 -2
- package/lib/module/health.module.ts +0 -62
- package/lib/module/index.ts +0 -1
- package/lib/service/health-executor.service.ts +0 -69
- package/lib/service/index.ts +0 -1
- package/test/constant/health.constants.spec.ts +0 -34
- package/test/controller/health.controller.spec.ts +0 -117
- package/test/indicator/cache-health.check.spec.ts +0 -88
- package/test/indicator/generic-health.check.spec.ts +0 -61
- package/test/indicator/prisma-health.check.spec.ts +0 -69
- package/test/indicator/queue-health.check.spec.ts +0 -88
- package/test/interface/health-module-options.spec.ts +0 -59
- package/test/jest-nax.json +0 -27
- package/test/jest-test.json +0 -28
- package/test/module/health.module.spec.ts +0 -311
- package/test/service/health-executor.service.spec.ts +0 -186
- package/tsconfig.json +0 -9
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, beforeAll, afterAll } from '@jest/globals';
|
|
2
|
-
import {
|
|
3
|
-
Injectable,
|
|
4
|
-
INestApplication,
|
|
5
|
-
} from '@nestjs/common';
|
|
6
|
-
import { TerminusModule } from '@nestjs/terminus';
|
|
7
|
-
import { Test } from '@nestjs/testing';
|
|
8
|
-
import * as supertest from 'supertest';
|
|
9
|
-
import {
|
|
10
|
-
createHealthController,
|
|
11
|
-
HEALTH_MODULE_OPTIONS,
|
|
12
|
-
HealthExecutorService,
|
|
13
|
-
} from '../../lib';
|
|
14
|
-
|
|
15
|
-
describe('createHealthController', () => {
|
|
16
|
-
it('AC5: returns a class with controller metadata usable as a NestJS controller', () => {
|
|
17
|
-
const HealthController = createHealthController({
|
|
18
|
-
livenessPath: 'health/live',
|
|
19
|
-
readinessPath: 'health/ready',
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
expect(typeof HealthController).toBe('function');
|
|
23
|
-
|
|
24
|
-
const controllerPath = Reflect.getMetadata('path', HealthController);
|
|
25
|
-
expect(controllerPath).toBeDefined();
|
|
26
|
-
|
|
27
|
-
const handlerNames = Object.getOwnPropertyNames(HealthController.prototype)
|
|
28
|
-
.filter((name) => name !== 'constructor')
|
|
29
|
-
.map((name) => HealthController.prototype[name])
|
|
30
|
-
.filter(
|
|
31
|
-
(fn) => Reflect.getMetadata('method', fn) === 0,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
expect(handlerNames.length).toBeGreaterThanOrEqual(2);
|
|
35
|
-
|
|
36
|
-
const paths = handlerNames
|
|
37
|
-
.map((fn) => Reflect.getMetadata('path', fn))
|
|
38
|
-
.sort();
|
|
39
|
-
expect(paths).toEqual(['health/live', 'health/ready']);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('AC6/AC7: mounted in a Nest application with the real HealthExecutorService', () => {
|
|
43
|
-
let upApp: INestApplication;
|
|
44
|
-
let downApp: INestApplication;
|
|
45
|
-
|
|
46
|
-
beforeAll(async () => {
|
|
47
|
-
@Injectable()
|
|
48
|
-
class UpAdapter {
|
|
49
|
-
async isHealthy() {
|
|
50
|
-
return { upSvc: { status: 'up' as const } };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const HealthController = createHealthController({
|
|
55
|
-
livenessPath: 'health/live',
|
|
56
|
-
readinessPath: 'health/ready',
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const upModuleRef = await Test.createTestingModule({
|
|
60
|
-
imports: [TerminusModule],
|
|
61
|
-
controllers: [HealthController],
|
|
62
|
-
providers: [
|
|
63
|
-
HealthExecutorService,
|
|
64
|
-
UpAdapter,
|
|
65
|
-
{
|
|
66
|
-
provide: HEALTH_MODULE_OPTIONS,
|
|
67
|
-
useValue: { liveness: [], readiness: [UpAdapter] },
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
}).compile();
|
|
71
|
-
upApp = upModuleRef.createNestApplication();
|
|
72
|
-
await upApp.init();
|
|
73
|
-
|
|
74
|
-
@Injectable()
|
|
75
|
-
class DownAdapter {
|
|
76
|
-
async isHealthy() {
|
|
77
|
-
return { downSvc: { status: 'down' as const } };
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const DownHealthController = createHealthController({
|
|
82
|
-
livenessPath: 'health/live',
|
|
83
|
-
readinessPath: 'health/ready',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const downModuleRef = await Test.createTestingModule({
|
|
87
|
-
imports: [TerminusModule],
|
|
88
|
-
controllers: [DownHealthController],
|
|
89
|
-
providers: [
|
|
90
|
-
HealthExecutorService,
|
|
91
|
-
DownAdapter,
|
|
92
|
-
{
|
|
93
|
-
provide: HEALTH_MODULE_OPTIONS,
|
|
94
|
-
useValue: { liveness: [], readiness: [DownAdapter] },
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
}).compile();
|
|
98
|
-
downApp = downModuleRef.createNestApplication();
|
|
99
|
-
await downApp.init();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
afterAll(async () => {
|
|
103
|
-
await upApp?.close();
|
|
104
|
-
await downApp?.close();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('AC6: GET /health/live returns HTTP 200', async () => {
|
|
108
|
-
const res = await supertest(upApp.getHttpServer()).get('/health/live');
|
|
109
|
-
expect(res.status).toBe(200);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('AC7: GET /health/ready returns HTTP 503 when readiness adapter reports down', async () => {
|
|
113
|
-
const res = await supertest(downApp.getHttpServer()).get('/health/ready');
|
|
114
|
-
expect(res.status).toBe(503);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { HealthIndicatorService, TerminusModule } from '@nestjs/terminus';
|
|
3
|
-
import { Test } from '@nestjs/testing';
|
|
4
|
-
import { CACHE_HEALTH_SOURCE, CacheHealthCheck } from '../../lib';
|
|
5
|
-
|
|
6
|
-
describe('CacheHealthCheck', () => {
|
|
7
|
-
it('AC1: is resolvable as an injectable provider from a compiled test module', async () => {
|
|
8
|
-
const moduleRef = await Test.createTestingModule({
|
|
9
|
-
imports: [TerminusModule],
|
|
10
|
-
providers: [CacheHealthCheck],
|
|
11
|
-
}).compile();
|
|
12
|
-
|
|
13
|
-
const instance = moduleRef.get(CacheHealthCheck);
|
|
14
|
-
expect(instance).toBeDefined();
|
|
15
|
-
expect(instance).toBeInstanceOf(CacheHealthCheck);
|
|
16
|
-
await moduleRef.close();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('AC2: with bound source returning healthy=true, isHealthy returns cache entry up', async () => {
|
|
20
|
-
const connections = [{ name: 'redis', status: 'connected' }];
|
|
21
|
-
const source = {
|
|
22
|
-
isHealthy: () => Promise.resolve({ healthy: true, connections }),
|
|
23
|
-
};
|
|
24
|
-
const moduleRef = await Test.createTestingModule({
|
|
25
|
-
imports: [TerminusModule],
|
|
26
|
-
providers: [
|
|
27
|
-
CacheHealthCheck,
|
|
28
|
-
{ provide: CACHE_HEALTH_SOURCE, useValue: source },
|
|
29
|
-
],
|
|
30
|
-
}).compile();
|
|
31
|
-
|
|
32
|
-
const check = moduleRef.get(CacheHealthCheck);
|
|
33
|
-
const result: any = await check.isHealthy('cache');
|
|
34
|
-
expect(result?.cache?.status).toBe('up');
|
|
35
|
-
expect(result?.cache?.connections).toEqual(connections);
|
|
36
|
-
await moduleRef.close();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('AC3: with bound source returning healthy=false, isHealthy returns cache entry down', async () => {
|
|
40
|
-
const connections = [{ name: 'redis', status: 'error' }];
|
|
41
|
-
const source = {
|
|
42
|
-
isHealthy: () => Promise.resolve({ healthy: false, connections }),
|
|
43
|
-
};
|
|
44
|
-
const moduleRef = await Test.createTestingModule({
|
|
45
|
-
imports: [TerminusModule],
|
|
46
|
-
providers: [
|
|
47
|
-
CacheHealthCheck,
|
|
48
|
-
{ provide: CACHE_HEALTH_SOURCE, useValue: source },
|
|
49
|
-
],
|
|
50
|
-
}).compile();
|
|
51
|
-
|
|
52
|
-
const check = moduleRef.get(CacheHealthCheck);
|
|
53
|
-
const result: any = await check.isHealthy('cache');
|
|
54
|
-
expect(result?.cache?.status).toBe('down');
|
|
55
|
-
expect(result?.cache?.connections).toEqual(connections);
|
|
56
|
-
await moduleRef.close();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('AC4: when no cache source token is bound, isHealthy resolves with cache entry down and does not throw', async () => {
|
|
60
|
-
const moduleRef = await Test.createTestingModule({
|
|
61
|
-
imports: [TerminusModule],
|
|
62
|
-
providers: [CacheHealthCheck],
|
|
63
|
-
}).compile();
|
|
64
|
-
|
|
65
|
-
const check = moduleRef.get(CacheHealthCheck);
|
|
66
|
-
await expect(check.isHealthy('cache')).resolves.toBeDefined();
|
|
67
|
-
const result: any = await check.isHealthy('cache');
|
|
68
|
-
expect(result?.cache?.status).toBe('down');
|
|
69
|
-
await moduleRef.close();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('best-effort: when the bound source rejects, isHealthy resolves with cache entry down', async () => {
|
|
73
|
-
const source = { isHealthy: () => Promise.reject(new Error('boom')) };
|
|
74
|
-
const moduleRef = await Test.createTestingModule({
|
|
75
|
-
imports: [TerminusModule],
|
|
76
|
-
providers: [
|
|
77
|
-
CacheHealthCheck,
|
|
78
|
-
{ provide: CACHE_HEALTH_SOURCE, useValue: source },
|
|
79
|
-
],
|
|
80
|
-
}).compile();
|
|
81
|
-
|
|
82
|
-
const check = moduleRef.get(CacheHealthCheck);
|
|
83
|
-
await expect(check.isHealthy('cache')).resolves.toBeDefined();
|
|
84
|
-
const result: any = await check.isHealthy('cache');
|
|
85
|
-
expect(result?.cache?.status).toBe('down');
|
|
86
|
-
await moduleRef.close();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { HealthIndicatorService, TerminusModule } from '@nestjs/terminus';
|
|
3
|
-
import { Test } from '@nestjs/testing';
|
|
4
|
-
import { GenericHealthCheck } from '../../lib';
|
|
5
|
-
|
|
6
|
-
describe('GenericHealthCheck', () => {
|
|
7
|
-
it('is resolvable as an injectable provider from a compiled test module', async () => {
|
|
8
|
-
const moduleRef = await Test.createTestingModule({
|
|
9
|
-
imports: [TerminusModule],
|
|
10
|
-
providers: [GenericHealthCheck],
|
|
11
|
-
}).compile();
|
|
12
|
-
|
|
13
|
-
const instance = moduleRef.get(GenericHealthCheck);
|
|
14
|
-
expect(instance).toBeDefined();
|
|
15
|
-
expect(instance).toBeInstanceOf(GenericHealthCheck);
|
|
16
|
-
await moduleRef.close();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('isHealthy returns svc status up when normalize maps the source result to true', async () => {
|
|
20
|
-
const hi = new HealthIndicatorService();
|
|
21
|
-
const source = { isHealthy: () => Promise.resolve({ status: 'ok' }) };
|
|
22
|
-
const normalize = (r: { status: string }) => r.status === 'ok';
|
|
23
|
-
const check = new GenericHealthCheck(
|
|
24
|
-
hi as any,
|
|
25
|
-
source as any,
|
|
26
|
-
normalize as any,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const result: any = await check.isHealthy('svc');
|
|
30
|
-
expect(result?.svc?.status).toBe('up');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('isHealthy returns svc status down when normalize maps the source result to false', async () => {
|
|
34
|
-
const hi = new HealthIndicatorService();
|
|
35
|
-
const source = { isHealthy: () => Promise.resolve({ status: 'degraded' }) };
|
|
36
|
-
const normalize = (r: { status: string }) => r.status !== 'degraded';
|
|
37
|
-
const check = new GenericHealthCheck(
|
|
38
|
-
hi as any,
|
|
39
|
-
source as any,
|
|
40
|
-
normalize as any,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const result: any = await check.isHealthy('svc');
|
|
44
|
-
expect(result?.svc?.status).toBe('down');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('isHealthy resolves (does not reject) with svc status down when the source rejects', async () => {
|
|
48
|
-
const hi = new HealthIndicatorService();
|
|
49
|
-
const source = { isHealthy: () => Promise.reject(new Error('boom')) };
|
|
50
|
-
const normalize = (_: unknown) => true;
|
|
51
|
-
const check = new GenericHealthCheck(
|
|
52
|
-
hi as any,
|
|
53
|
-
source as any,
|
|
54
|
-
normalize as any,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
await expect(check.isHealthy('svc')).resolves.toBeDefined();
|
|
58
|
-
const result: any = await check.isHealthy('svc');
|
|
59
|
-
expect(result?.svc?.status).toBe('down');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { TerminusModule } from '@nestjs/terminus';
|
|
3
|
-
import { Test } from '@nestjs/testing';
|
|
4
|
-
import { PRISMA_HEALTH_SOURCE, PrismaHealthCheck } from '../../lib';
|
|
5
|
-
|
|
6
|
-
describe('PrismaHealthCheck', () => {
|
|
7
|
-
it('AC1: is resolvable as an injectable provider from a compiled test module', async () => {
|
|
8
|
-
const moduleRef = await Test.createTestingModule({
|
|
9
|
-
imports: [TerminusModule],
|
|
10
|
-
providers: [PrismaHealthCheck],
|
|
11
|
-
}).compile();
|
|
12
|
-
|
|
13
|
-
const instance = moduleRef.get(PrismaHealthCheck);
|
|
14
|
-
expect(instance).toBeDefined();
|
|
15
|
-
expect(instance).toBeInstanceOf(PrismaHealthCheck);
|
|
16
|
-
await moduleRef.close();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('AC5: with bound source returning status=up, isHealthy returns prisma entry up; with status=down+message returns down', async () => {
|
|
20
|
-
const upSource = { isHealthy: () => Promise.resolve({ status: 'up' }) };
|
|
21
|
-
const downSource = {
|
|
22
|
-
isHealthy: () => Promise.resolve({ status: 'down', message: 'Not connected' }),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const upModule = await Test.createTestingModule({
|
|
26
|
-
imports: [TerminusModule],
|
|
27
|
-
providers: [
|
|
28
|
-
PrismaHealthCheck,
|
|
29
|
-
{ provide: PRISMA_HEALTH_SOURCE, useValue: upSource },
|
|
30
|
-
],
|
|
31
|
-
}).compile();
|
|
32
|
-
|
|
33
|
-
const upCheck = upModule.get(PrismaHealthCheck);
|
|
34
|
-
const upResult: any = await upCheck.isHealthy('prisma');
|
|
35
|
-
expect(upResult?.prisma?.status).toBe('up');
|
|
36
|
-
await upModule.close();
|
|
37
|
-
|
|
38
|
-
const downModule = await Test.createTestingModule({
|
|
39
|
-
imports: [TerminusModule],
|
|
40
|
-
providers: [
|
|
41
|
-
PrismaHealthCheck,
|
|
42
|
-
{ provide: PRISMA_HEALTH_SOURCE, useValue: downSource },
|
|
43
|
-
],
|
|
44
|
-
}).compile();
|
|
45
|
-
|
|
46
|
-
const downCheck = downModule.get(PrismaHealthCheck);
|
|
47
|
-
const downResult: any = await downCheck.isHealthy('prisma');
|
|
48
|
-
expect(downResult?.prisma?.status).toBe('down');
|
|
49
|
-
expect(downResult?.prisma?.message).toBe('Not connected');
|
|
50
|
-
await downModule.close();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('AC6: when the bound source throws, isHealthy resolves with prisma entry down (best-effort)', async () => {
|
|
54
|
-
const source = { isHealthy: () => Promise.reject(new Error('boom')) };
|
|
55
|
-
const moduleRef = await Test.createTestingModule({
|
|
56
|
-
imports: [TerminusModule],
|
|
57
|
-
providers: [
|
|
58
|
-
PrismaHealthCheck,
|
|
59
|
-
{ provide: PRISMA_HEALTH_SOURCE, useValue: source },
|
|
60
|
-
],
|
|
61
|
-
}).compile();
|
|
62
|
-
|
|
63
|
-
const check = moduleRef.get(PrismaHealthCheck);
|
|
64
|
-
await expect(check.isHealthy('prisma')).resolves.toBeDefined();
|
|
65
|
-
const result: any = await check.isHealthy('prisma');
|
|
66
|
-
expect(result?.prisma?.status).toBe('down');
|
|
67
|
-
await moduleRef.close();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { TerminusModule } from '@nestjs/terminus';
|
|
3
|
-
import { Test } from '@nestjs/testing';
|
|
4
|
-
import { QUEUE_HEALTH_SOURCE, QueueHealthCheck } from '../../lib';
|
|
5
|
-
|
|
6
|
-
describe('QueueHealthCheck', () => {
|
|
7
|
-
it('AC1: is resolvable as an injectable provider from a compiled test module', async () => {
|
|
8
|
-
const moduleRef = await Test.createTestingModule({
|
|
9
|
-
imports: [TerminusModule],
|
|
10
|
-
providers: [QueueHealthCheck],
|
|
11
|
-
}).compile();
|
|
12
|
-
|
|
13
|
-
const instance = moduleRef.get(QueueHealthCheck);
|
|
14
|
-
expect(instance).toBeDefined();
|
|
15
|
-
expect(instance).toBeInstanceOf(QueueHealthCheck);
|
|
16
|
-
await moduleRef.close();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('AC7: with bound source returning healthy=true, isHealthy returns queue entry up; with healthy=false returns down', async () => {
|
|
20
|
-
const upConnections = [{ name: 'redis', status: 'connected' }];
|
|
21
|
-
const upSource = {
|
|
22
|
-
isHealthy: () =>
|
|
23
|
-
Promise.resolve({
|
|
24
|
-
healthy: true,
|
|
25
|
-
provider: 'bullmq',
|
|
26
|
-
connections: upConnections,
|
|
27
|
-
latencyMs: 5,
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
const downConnections = [{ name: 'redis', status: 'error' }];
|
|
31
|
-
const downSource = {
|
|
32
|
-
isHealthy: () =>
|
|
33
|
-
Promise.resolve({
|
|
34
|
-
healthy: false,
|
|
35
|
-
provider: 'bullmq',
|
|
36
|
-
connections: downConnections,
|
|
37
|
-
}),
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const upModule = await Test.createTestingModule({
|
|
41
|
-
imports: [TerminusModule],
|
|
42
|
-
providers: [
|
|
43
|
-
QueueHealthCheck,
|
|
44
|
-
{ provide: QUEUE_HEALTH_SOURCE, useValue: upSource },
|
|
45
|
-
],
|
|
46
|
-
}).compile();
|
|
47
|
-
|
|
48
|
-
const upCheck = upModule.get(QueueHealthCheck);
|
|
49
|
-
const upResult: any = await upCheck.isHealthy('queue');
|
|
50
|
-
expect(upResult?.queue?.status).toBe('up');
|
|
51
|
-
expect(upResult?.queue?.provider).toBe('bullmq');
|
|
52
|
-
expect(upResult?.queue?.connections).toEqual(upConnections);
|
|
53
|
-
expect(upResult?.queue?.latencyMs).toBe(5);
|
|
54
|
-
await upModule.close();
|
|
55
|
-
|
|
56
|
-
const downModule = await Test.createTestingModule({
|
|
57
|
-
imports: [TerminusModule],
|
|
58
|
-
providers: [
|
|
59
|
-
QueueHealthCheck,
|
|
60
|
-
{ provide: QUEUE_HEALTH_SOURCE, useValue: downSource },
|
|
61
|
-
],
|
|
62
|
-
}).compile();
|
|
63
|
-
|
|
64
|
-
const downCheck = downModule.get(QueueHealthCheck);
|
|
65
|
-
const downResult: any = await downCheck.isHealthy('queue');
|
|
66
|
-
expect(downResult?.queue?.status).toBe('down');
|
|
67
|
-
expect(downResult?.queue?.provider).toBe('bullmq');
|
|
68
|
-
expect(downResult?.queue?.connections).toEqual(downConnections);
|
|
69
|
-
await downModule.close();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('best-effort: when the bound source throws, isHealthy resolves with queue entry down', async () => {
|
|
73
|
-
const source = { isHealthy: () => Promise.reject(new Error('boom')) };
|
|
74
|
-
const moduleRef = await Test.createTestingModule({
|
|
75
|
-
imports: [TerminusModule],
|
|
76
|
-
providers: [
|
|
77
|
-
QueueHealthCheck,
|
|
78
|
-
{ provide: QUEUE_HEALTH_SOURCE, useValue: source },
|
|
79
|
-
],
|
|
80
|
-
}).compile();
|
|
81
|
-
|
|
82
|
-
const check = moduleRef.get(QueueHealthCheck);
|
|
83
|
-
await expect(check.isHealthy('queue')).resolves.toBeDefined();
|
|
84
|
-
const result: any = await check.isHealthy('queue');
|
|
85
|
-
expect(result?.queue?.status).toBe('down');
|
|
86
|
-
await moduleRef.close();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import {
|
|
3
|
-
resolveHealthControllerOptions,
|
|
4
|
-
} from '../../lib/interface/health-module-options.interface';
|
|
5
|
-
|
|
6
|
-
function asPaths(opts: ReturnType<typeof resolveHealthControllerOptions>): {
|
|
7
|
-
livenessPath: string;
|
|
8
|
-
readinessPath: string;
|
|
9
|
-
} {
|
|
10
|
-
if (opts === false) {
|
|
11
|
-
throw new Error('expected controller options, got false');
|
|
12
|
-
}
|
|
13
|
-
return opts;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe('resolveHealthControllerOptions', () => {
|
|
17
|
-
it('returns livenessPath "health/live" and readinessPath "health/ready" when called with no arguments', () => {
|
|
18
|
-
const opts = asPaths(resolveHealthControllerOptions());
|
|
19
|
-
expect(opts.livenessPath).toBe('health/live');
|
|
20
|
-
expect(opts.readinessPath).toBe('health/ready');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('returns the same defaults when controller is explicitly undefined', () => {
|
|
24
|
-
const opts = asPaths(resolveHealthControllerOptions(undefined));
|
|
25
|
-
expect(opts.livenessPath).toBe('health/live');
|
|
26
|
-
expect(opts.readinessPath).toBe('health/ready');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('returns falsy when controller is false (signals "no controller")', () => {
|
|
30
|
-
expect(resolveHealthControllerOptions(false)).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('uses supplied livenessPath and readinessPath when provided', () => {
|
|
34
|
-
const opts = asPaths(
|
|
35
|
-
resolveHealthControllerOptions({
|
|
36
|
-
livenessPath: 'healthz',
|
|
37
|
-
readinessPath: 'readyz',
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
40
|
-
expect(opts.livenessPath).toBe('healthz');
|
|
41
|
-
expect(opts.readinessPath).toBe('readyz');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('fills missing liveness/readiness fields with defaults', () => {
|
|
45
|
-
const opts = asPaths(resolveHealthControllerOptions({}));
|
|
46
|
-
expect(opts.livenessPath).toBe('health/live');
|
|
47
|
-
expect(opts.readinessPath).toBe('health/ready');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('falls back to defaults when supplied paths are empty or whitespace-only', () => {
|
|
51
|
-
const empty = asPaths(resolveHealthControllerOptions({ livenessPath: '', readinessPath: '' }));
|
|
52
|
-
expect(empty.livenessPath).toBe('health/live');
|
|
53
|
-
expect(empty.readinessPath).toBe('health/ready');
|
|
54
|
-
|
|
55
|
-
const blank = asPaths(resolveHealthControllerOptions({ livenessPath: ' ', readinessPath: '\t' }));
|
|
56
|
-
expect(blank.livenessPath).toBe('health/live');
|
|
57
|
-
expect(blank.readinessPath).toBe('health/ready');
|
|
58
|
-
});
|
|
59
|
-
});
|
package/test/jest-nax.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"moduleFileExtensions": ["js", "json", "ts", "d.ts"],
|
|
3
|
-
"rootDir": "../",
|
|
4
|
-
"testEnvironment": "node",
|
|
5
|
-
"testMatch": ["**/.nax/**/*.test.ts"],
|
|
6
|
-
"transform": {
|
|
7
|
-
"^.+\\.(t)s$": [
|
|
8
|
-
"ts-jest",
|
|
9
|
-
{
|
|
10
|
-
"diagnostics": true,
|
|
11
|
-
"tsconfig": {
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"emitDecoratorMetadata": true,
|
|
14
|
-
"experimentalDecorators": true
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
"collectCoverageFrom": [
|
|
20
|
-
"lib/**/*.ts",
|
|
21
|
-
"!lib/**/*.spec.ts",
|
|
22
|
-
"!lib/**/*.d.ts",
|
|
23
|
-
"!**/node_modules/**"
|
|
24
|
-
],
|
|
25
|
-
"forceExit": true,
|
|
26
|
-
"maxWorkers": 1
|
|
27
|
-
}
|
package/test/jest-test.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"moduleFileExtensions": [
|
|
3
|
-
"js",
|
|
4
|
-
"json",
|
|
5
|
-
"ts",
|
|
6
|
-
"d.ts"
|
|
7
|
-
],
|
|
8
|
-
"rootDir": "../",
|
|
9
|
-
"testEnvironment": "node",
|
|
10
|
-
"testRegex": ".spec.ts$",
|
|
11
|
-
"transform": {
|
|
12
|
-
"^.+\\.(t)s$": [
|
|
13
|
-
"ts-jest",
|
|
14
|
-
{
|
|
15
|
-
"diagnostics": true
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
"collectCoverageFrom": [
|
|
20
|
-
"lib/**/*.ts",
|
|
21
|
-
"!lib/**/*.spec.ts",
|
|
22
|
-
"!lib/**/*.d.ts",
|
|
23
|
-
"!lib/**/index.ts",
|
|
24
|
-
"!lib/**/*.interface.ts",
|
|
25
|
-
"!**/node_modules/**"
|
|
26
|
-
],
|
|
27
|
-
"coverageProvider": "v8"
|
|
28
|
-
}
|