nestlens 0.4.0 → 0.4.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/dist/__tests__/watchers/query/typeorm-integration.spec.d.ts +2 -0
- package/dist/__tests__/watchers/query/typeorm-integration.spec.d.ts.map +1 -0
- package/dist/__tests__/watchers/query/typeorm-integration.spec.js +100 -0
- package/dist/__tests__/watchers/query/typeorm-integration.spec.js.map +1 -0
- package/dist/__tests__/watchers/query/types.spec.js +48 -263
- package/dist/__tests__/watchers/query/types.spec.js.map +1 -1
- package/dist/__tests__/watchers/query.watcher.spec.js +173 -522
- package/dist/__tests__/watchers/query.watcher.spec.js.map +1 -1
- package/dist/dashboard/public/assets/{BatchesPage-DmqbLFCs.js → BatchesPage-DrFl64wj.js} +1 -1
- package/dist/dashboard/public/assets/{CachePage-CfA-UrdM.js → CachePage-C57Pkxm0.js} +1 -1
- package/dist/dashboard/public/assets/{ClickableBadge-CW4jdcpl.js → ClickableBadge-BNUq-FXI.js} +1 -1
- package/dist/dashboard/public/assets/{CommandsPage-DJ1ZxHj8.js → CommandsPage-BdD-ojDk.js} +1 -1
- package/dist/dashboard/public/assets/{DashboardPage-BnnZ3TMF.js → DashboardPage-DCophLiw.js} +1 -1
- package/dist/dashboard/public/assets/{DumpsPage-fshG-ETf.js → DumpsPage-DtXeYPpQ.js} +1 -1
- package/dist/dashboard/public/assets/{EntryDetailPage-Cf7K34er.js → EntryDetailPage-qlWzdnXs.js} +1 -1
- package/dist/dashboard/public/assets/{EventsPage-DiPB0Sfy.js → EventsPage-BHpLjHZj.js} +1 -1
- package/dist/dashboard/public/assets/{ExceptionsPage-BoauuDFu.js → ExceptionsPage-Ww3jIO29.js} +1 -1
- package/dist/dashboard/public/assets/{GatesPage-CB0kqyp_.js → GatesPage-beRehq6b.js} +1 -1
- package/dist/dashboard/public/assets/{GraphQLPage-_inMfKh4.js → GraphQLPage-BZt0nDmS.js} +1 -1
- package/dist/dashboard/public/assets/{HttpClientPage-5vVzz7TU.js → HttpClientPage-Dac8U41f.js} +1 -1
- package/dist/dashboard/public/assets/{JobsPage-CHYjmhlh.js → JobsPage-zLQH5Skv.js} +1 -1
- package/dist/dashboard/public/assets/{LogsPage-z4yYJ1qQ.js → LogsPage-Dj7YEZlz.js} +1 -1
- package/dist/dashboard/public/assets/{MailPage-DQ2PuRS9.js → MailPage-C45lv85q.js} +1 -1
- package/dist/dashboard/public/assets/{ModelsPage-PBBI9K5M.js → ModelsPage-CveFVTw3.js} +1 -1
- package/dist/dashboard/public/assets/{NotificationsPage-CjleWNhr.js → NotificationsPage-CVAGh1SG.js} +1 -1
- package/dist/dashboard/public/assets/{PageHeader-QBzFo308.js → PageHeader-BhUyZtbe.js} +1 -1
- package/dist/dashboard/public/assets/{QueriesPage-Cpi1b2Mz.js → QueriesPage-BMpvUeTX.js} +1 -1
- package/dist/dashboard/public/assets/{RedisPage-C7vFV3r4.js → RedisPage-FPrKgNrc.js} +1 -1
- package/dist/dashboard/public/assets/{RequestsPage-B9-Qq2vH.js → RequestsPage-6JVqr7xE.js} +1 -1
- package/dist/dashboard/public/assets/{SchedulePage-BXPldddV.js → SchedulePage-DOt6jqTT.js} +1 -1
- package/dist/dashboard/public/assets/{ViewsPage-COo7BNBc.js → ViewsPage-RG6Ze2rn.js} +1 -1
- package/dist/dashboard/public/assets/{calendar-WMtbNas7.js → calendar-CEjtgImi.js} +1 -1
- package/dist/dashboard/public/assets/{circle-check-big-U-4nHjTQ.js → circle-check-big-BnRBDUDo.js} +1 -1
- package/dist/dashboard/public/assets/{eye-Bc29awES.js → eye-tfj-u8EL.js} +1 -1
- package/dist/dashboard/public/assets/{index-C8he4ZUV.js → index-OMQZjJAo.js} +2 -2
- package/dist/dashboard/public/assets/{types-BYamMo0R.js → types-Cubd9hBF.js} +1 -1
- package/dist/dashboard/public/assets/{zap-BxD9CCmf.js → zap-Bh7DgMLC.js} +1 -1
- package/dist/dashboard/public/index.html +1 -1
- package/dist/nestlens.module.d.ts.map +1 -1
- package/dist/nestlens.module.js +1 -0
- package/dist/nestlens.module.js.map +1 -1
- package/dist/watchers/query/index.d.ts +2 -0
- package/dist/watchers/query/index.d.ts.map +1 -1
- package/dist/watchers/query/index.js +2 -0
- package/dist/watchers/query/index.js.map +1 -1
- package/dist/watchers/query/query.watcher.d.ts +12 -8
- package/dist/watchers/query/query.watcher.d.ts.map +1 -1
- package/dist/watchers/query/query.watcher.js +80 -78
- package/dist/watchers/query/query.watcher.js.map +1 -1
- package/dist/watchers/query/typeorm-logger.d.ts +21 -0
- package/dist/watchers/query/typeorm-logger.d.ts.map +1 -0
- package/dist/watchers/query/typeorm-logger.js +53 -0
- package/dist/watchers/query/typeorm-logger.js.map +1 -0
- package/dist/watchers/query/typeorm-subscriber.d.ts +20 -0
- package/dist/watchers/query/typeorm-subscriber.d.ts.map +1 -0
- package/dist/watchers/query/typeorm-subscriber.js +34 -0
- package/dist/watchers/query/typeorm-subscriber.js.map +1 -0
- package/dist/watchers/query/types.d.ts +50 -29
- package/dist/watchers/query/types.d.ts.map +1 -1
- package/dist/watchers/query/types.js +21 -16
- package/dist/watchers/query/types.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm-integration.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/watchers/query/typeorm-integration.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
/**
|
|
16
|
+
* QueryWatcher integration test — exercises the real TypeORM 0.3.x runtime
|
|
17
|
+
* with `better-sqlite3` to prove that queries are actually captured end to
|
|
18
|
+
* end. This is the regression guard for issue #5: the previous watcher
|
|
19
|
+
* silently no-op'd here because it relied on `getDataSources()` and a fake
|
|
20
|
+
* `Driver.afterQuery` hook, neither of which exist in TypeORM 0.3.x.
|
|
21
|
+
*/
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
const testing_1 = require("@nestjs/testing");
|
|
24
|
+
const typeorm_1 = require("typeorm");
|
|
25
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
26
|
+
const typeorm_3 = require("typeorm");
|
|
27
|
+
const nestlens_module_1 = require("../../../nestlens.module");
|
|
28
|
+
const collector_service_1 = require("../../../core/collector.service");
|
|
29
|
+
const storage_1 = require("../../../core/storage");
|
|
30
|
+
let IntegrationUser = class IntegrationUser {
|
|
31
|
+
};
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
34
|
+
__metadata("design:type", Number)
|
|
35
|
+
], IntegrationUser.prototype, "id", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, typeorm_1.Column)(),
|
|
38
|
+
__metadata("design:type", String)
|
|
39
|
+
], IntegrationUser.prototype, "name", void 0);
|
|
40
|
+
IntegrationUser = __decorate([
|
|
41
|
+
(0, typeorm_1.Entity)()
|
|
42
|
+
], IntegrationUser);
|
|
43
|
+
let IntegrationAppModule = class IntegrationAppModule {
|
|
44
|
+
constructor(users) {
|
|
45
|
+
this.users = users;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
IntegrationAppModule = __decorate([
|
|
49
|
+
(0, common_1.Module)({
|
|
50
|
+
imports: [
|
|
51
|
+
nestlens_module_1.NestLensModule.forRoot({
|
|
52
|
+
enabled: true,
|
|
53
|
+
watchers: { query: { enabled: true, slowThreshold: 0 } },
|
|
54
|
+
}),
|
|
55
|
+
typeorm_2.TypeOrmModule.forRoot({
|
|
56
|
+
type: 'better-sqlite3',
|
|
57
|
+
database: ':memory:',
|
|
58
|
+
entities: [IntegrationUser],
|
|
59
|
+
synchronize: true,
|
|
60
|
+
}),
|
|
61
|
+
typeorm_2.TypeOrmModule.forFeature([IntegrationUser]),
|
|
62
|
+
],
|
|
63
|
+
}),
|
|
64
|
+
__param(0, (0, typeorm_2.InjectRepository)(IntegrationUser)),
|
|
65
|
+
__metadata("design:paramtypes", [typeorm_3.Repository])
|
|
66
|
+
], IntegrationAppModule);
|
|
67
|
+
describe('QueryWatcher (TypeORM integration)', () => {
|
|
68
|
+
let moduleRef;
|
|
69
|
+
let app;
|
|
70
|
+
let storage;
|
|
71
|
+
beforeAll(async () => {
|
|
72
|
+
moduleRef = await testing_1.Test.createTestingModule({
|
|
73
|
+
imports: [IntegrationAppModule],
|
|
74
|
+
}).compile();
|
|
75
|
+
await moduleRef.init();
|
|
76
|
+
app = moduleRef.get(IntegrationAppModule);
|
|
77
|
+
storage = moduleRef.get(storage_1.STORAGE);
|
|
78
|
+
});
|
|
79
|
+
afterAll(async () => {
|
|
80
|
+
if (moduleRef) {
|
|
81
|
+
await moduleRef.close();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
it('captures INSERT and SELECT queries end-to-end', async () => {
|
|
85
|
+
const collector = moduleRef.get(collector_service_1.CollectorService);
|
|
86
|
+
await app.users.save({ name: 'Wasim' });
|
|
87
|
+
await app.users.find();
|
|
88
|
+
if (typeof collector.flush === 'function') {
|
|
89
|
+
await collector.flush();
|
|
90
|
+
}
|
|
91
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
92
|
+
const entries = (await storage.find({ type: 'query' }));
|
|
93
|
+
const sources = new Set(entries.map((e) => e.payload.source));
|
|
94
|
+
expect(sources.has('typeorm')).toBe(true);
|
|
95
|
+
const joined = entries.map((e) => e.payload.query).join(' | ');
|
|
96
|
+
expect(joined).toMatch(/INSERT INTO\s+"?integration_user"?/i);
|
|
97
|
+
expect(joined).toMatch(/SELECT[\s\S]*integration_user/i);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=typeorm-integration.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm-integration.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/watchers/query/typeorm-integration.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,2CAAwC;AACxC,6CAAsD;AACtD,qCAAiE;AACjE,6CAAkE;AAClE,qCAAqC;AACrC,8DAA0D;AAC1D,uEAAmE;AACnE,mDAAgD;AAGhD,IAAM,eAAe,GAArB,MAAM,eAAe;CAMpB,CAAA;AAJC;IADC,IAAA,gCAAsB,GAAE;;2CACb;AAGZ;IADC,IAAA,gBAAM,GAAE;;6CACK;AALV,eAAe;IADpB,IAAA,gBAAM,GAAE;GACH,eAAe,CAMpB;AAED,IAeM,oBAAoB,GAf1B,MAeM,oBAAoB;IACxB,YAEkB,KAAkC;QAAlC,UAAK,GAAL,KAAK,CAA6B;IACjD,CAAC;CACL,CAAA;AALK,oBAAoB;IAfzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,gCAAc,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,EAA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,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YAC1C,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QAExD,MAAM,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAEpD,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9D,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE1C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC;QAC9D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,291 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const types_1 = require("../../../watchers/query/types");
|
|
4
|
-
describe('Query
|
|
5
|
-
describe('
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
driver: { afterQuery: jest.fn() },
|
|
12
|
-
initialize: jest.fn().mockResolvedValue({}),
|
|
13
|
-
};
|
|
14
|
-
// Act
|
|
15
|
-
const result = (0, types_1.isTypeORMDataSource)(validDataSource);
|
|
16
|
-
// Assert
|
|
17
|
-
expect(result).toBe(true);
|
|
4
|
+
describe('Query type guards and module helpers', () => {
|
|
5
|
+
describe('isLikelyTypeORMDataSource', () => {
|
|
6
|
+
const makeFakeDs = (overrides = {}) => ({
|
|
7
|
+
constructor: { name: 'DataSource' },
|
|
8
|
+
options: { type: 'better-sqlite3' },
|
|
9
|
+
subscribers: [],
|
|
10
|
+
...overrides,
|
|
18
11
|
});
|
|
19
|
-
it('
|
|
20
|
-
|
|
21
|
-
const uninitializedDataSource = {
|
|
22
|
-
isInitialized: false,
|
|
23
|
-
options: { type: 'mysql' },
|
|
24
|
-
driver: {},
|
|
25
|
-
initialize: jest.fn(),
|
|
26
|
-
};
|
|
27
|
-
// Act
|
|
28
|
-
const result = (0, types_1.isTypeORMDataSource)(uninitializedDataSource);
|
|
29
|
-
// Assert
|
|
30
|
-
expect(result).toBe(true);
|
|
12
|
+
it('accepts an object that looks like a TypeORM DataSource', () => {
|
|
13
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(makeFakeDs())).toBe(true);
|
|
31
14
|
});
|
|
32
|
-
it('
|
|
33
|
-
|
|
34
|
-
const result = (0, types_1.isTypeORMDataSource)(null);
|
|
35
|
-
// Assert
|
|
36
|
-
expect(result).toBe(false);
|
|
15
|
+
it('accepts an object whose constructor is named Connection (legacy alias)', () => {
|
|
16
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(makeFakeDs({ constructor: { name: 'Connection' } }))).toBe(true);
|
|
37
17
|
});
|
|
38
|
-
it('
|
|
39
|
-
|
|
40
|
-
const result = (0, types_1.isTypeORMDataSource)(undefined);
|
|
41
|
-
// Assert
|
|
42
|
-
expect(result).toBe(false);
|
|
18
|
+
it('rejects an object with the wrong constructor name', () => {
|
|
19
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(makeFakeDs({ constructor: { name: 'SomethingElse' } }))).toBe(false);
|
|
43
20
|
});
|
|
44
|
-
it('
|
|
45
|
-
|
|
46
|
-
expect((0, types_1.isTypeORMDataSource)('string')).toBe(false);
|
|
47
|
-
expect((0, types_1.isTypeORMDataSource)(123)).toBe(false);
|
|
48
|
-
expect((0, types_1.isTypeORMDataSource)(true)).toBe(false);
|
|
21
|
+
it('rejects an object missing subscribers array', () => {
|
|
22
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(makeFakeDs({ subscribers: undefined }))).toBe(false);
|
|
49
23
|
});
|
|
50
|
-
it('
|
|
51
|
-
|
|
52
|
-
const result = (0, types_1.isTypeORMDataSource)({});
|
|
53
|
-
// Assert
|
|
54
|
-
expect(result).toBe(false);
|
|
24
|
+
it('rejects an object missing options', () => {
|
|
25
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(makeFakeDs({ options: undefined }))).toBe(false);
|
|
55
26
|
});
|
|
56
|
-
it('
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// Act
|
|
63
|
-
const result = (0, types_1.isTypeORMDataSource)(invalidObj);
|
|
64
|
-
// Assert
|
|
65
|
-
expect(result).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
it('should return false for object missing options', () => {
|
|
68
|
-
// Arrange
|
|
69
|
-
const invalidObj = {
|
|
70
|
-
isInitialized: true,
|
|
71
|
-
driver: {},
|
|
72
|
-
};
|
|
73
|
-
// Act
|
|
74
|
-
const result = (0, types_1.isTypeORMDataSource)(invalidObj);
|
|
75
|
-
// Assert
|
|
76
|
-
expect(result).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
it('should return false for object missing driver', () => {
|
|
79
|
-
// Arrange
|
|
80
|
-
const invalidObj = {
|
|
81
|
-
isInitialized: true,
|
|
82
|
-
options: { type: 'postgres' },
|
|
83
|
-
};
|
|
84
|
-
// Act
|
|
85
|
-
const result = (0, types_1.isTypeORMDataSource)(invalidObj);
|
|
86
|
-
// Assert
|
|
87
|
-
expect(result).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
it('should return false when isInitialized is not a boolean', () => {
|
|
90
|
-
// Arrange
|
|
91
|
-
const invalidObj = {
|
|
92
|
-
isInitialized: 'true',
|
|
93
|
-
options: { type: 'postgres' },
|
|
94
|
-
driver: {},
|
|
95
|
-
};
|
|
96
|
-
// Act
|
|
97
|
-
const result = (0, types_1.isTypeORMDataSource)(invalidObj);
|
|
98
|
-
// Assert
|
|
99
|
-
expect(result).toBe(false);
|
|
100
|
-
});
|
|
101
|
-
it('should return true for DataSource with minimal valid structure', () => {
|
|
102
|
-
// Arrange
|
|
103
|
-
const minimalDataSource = {
|
|
104
|
-
isInitialized: false,
|
|
105
|
-
options: {},
|
|
106
|
-
driver: {},
|
|
107
|
-
};
|
|
108
|
-
// Act
|
|
109
|
-
const result = (0, types_1.isTypeORMDataSource)(minimalDataSource);
|
|
110
|
-
// Assert
|
|
111
|
-
expect(result).toBe(true);
|
|
27
|
+
it('rejects null, undefined and primitives', () => {
|
|
28
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(null)).toBe(false);
|
|
29
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(undefined)).toBe(false);
|
|
30
|
+
expect((0, types_1.isLikelyTypeORMDataSource)('ds')).toBe(false);
|
|
31
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(42)).toBe(false);
|
|
32
|
+
expect((0, types_1.isLikelyTypeORMDataSource)(true)).toBe(false);
|
|
112
33
|
});
|
|
113
34
|
});
|
|
114
35
|
describe('isPrismaClient', () => {
|
|
115
|
-
it('
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
$on: jest.fn(),
|
|
119
|
-
};
|
|
120
|
-
// Act
|
|
121
|
-
const result = (0, types_1.isPrismaClient)(validClient);
|
|
122
|
-
// Assert
|
|
123
|
-
expect(result).toBe(true);
|
|
124
|
-
});
|
|
125
|
-
it('should return true for valid PrismaClient with $use', () => {
|
|
126
|
-
// Arrange
|
|
127
|
-
const validClient = {
|
|
128
|
-
$use: jest.fn(),
|
|
129
|
-
};
|
|
130
|
-
// Act
|
|
131
|
-
const result = (0, types_1.isPrismaClient)(validClient);
|
|
132
|
-
// Assert
|
|
133
|
-
expect(result).toBe(true);
|
|
134
|
-
});
|
|
135
|
-
it('should return true for valid PrismaClient with both $on and $use', () => {
|
|
136
|
-
// Arrange
|
|
137
|
-
const validClient = {
|
|
138
|
-
$on: jest.fn(),
|
|
139
|
-
$use: jest.fn(),
|
|
140
|
-
};
|
|
141
|
-
// Act
|
|
142
|
-
const result = (0, types_1.isPrismaClient)(validClient);
|
|
143
|
-
// Assert
|
|
144
|
-
expect(result).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
it('should return false for null', () => {
|
|
147
|
-
// Act
|
|
148
|
-
const result = (0, types_1.isPrismaClient)(null);
|
|
149
|
-
// Assert
|
|
150
|
-
expect(result).toBe(false);
|
|
151
|
-
});
|
|
152
|
-
it('should return false for undefined', () => {
|
|
153
|
-
// Act
|
|
154
|
-
const result = (0, types_1.isPrismaClient)(undefined);
|
|
155
|
-
// Assert
|
|
156
|
-
expect(result).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
it('should return false for primitive values', () => {
|
|
159
|
-
// Act & Assert
|
|
160
|
-
expect((0, types_1.isPrismaClient)('string')).toBe(false);
|
|
161
|
-
expect((0, types_1.isPrismaClient)(123)).toBe(false);
|
|
162
|
-
expect((0, types_1.isPrismaClient)(true)).toBe(false);
|
|
163
|
-
});
|
|
164
|
-
it('should return false for empty object', () => {
|
|
165
|
-
// Act
|
|
166
|
-
const result = (0, types_1.isPrismaClient)({});
|
|
167
|
-
// Assert
|
|
168
|
-
expect(result).toBe(false);
|
|
36
|
+
it('returns true when $on is a function', () => {
|
|
37
|
+
const client = { $on: jest.fn() };
|
|
38
|
+
expect((0, types_1.isPrismaClient)(client)).toBe(true);
|
|
169
39
|
});
|
|
170
|
-
it('
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
$on: 'not a function',
|
|
174
|
-
};
|
|
175
|
-
// Act
|
|
176
|
-
const result = (0, types_1.isPrismaClient)(invalidClient);
|
|
177
|
-
// Assert
|
|
178
|
-
expect(result).toBe(false);
|
|
40
|
+
it('returns true when $use is a function', () => {
|
|
41
|
+
const client = { $use: jest.fn() };
|
|
42
|
+
expect((0, types_1.isPrismaClient)(client)).toBe(true);
|
|
179
43
|
});
|
|
180
|
-
it('
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
$use: 'not a function',
|
|
184
|
-
};
|
|
185
|
-
// Act
|
|
186
|
-
const result = (0, types_1.isPrismaClient)(invalidClient);
|
|
187
|
-
// Assert
|
|
188
|
-
expect(result).toBe(false);
|
|
44
|
+
it('returns false when neither hook is present', () => {
|
|
45
|
+
expect((0, types_1.isPrismaClient)({})).toBe(false);
|
|
46
|
+
expect((0, types_1.isPrismaClient)({ $on: 'no' })).toBe(false);
|
|
189
47
|
});
|
|
190
|
-
it('
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
expect(result).toBe(false);
|
|
195
|
-
});
|
|
196
|
-
it('should return true for object with additional properties and valid $on', () => {
|
|
197
|
-
// Arrange
|
|
198
|
-
const clientWithExtras = {
|
|
199
|
-
$on: jest.fn(),
|
|
200
|
-
user: {},
|
|
201
|
-
post: {},
|
|
202
|
-
$connect: jest.fn(),
|
|
203
|
-
};
|
|
204
|
-
// Act
|
|
205
|
-
const result = (0, types_1.isPrismaClient)(clientWithExtras);
|
|
206
|
-
// Assert
|
|
207
|
-
expect(result).toBe(true);
|
|
48
|
+
it('returns false for null, undefined and arrays', () => {
|
|
49
|
+
expect((0, types_1.isPrismaClient)(null)).toBe(false);
|
|
50
|
+
expect((0, types_1.isPrismaClient)(undefined)).toBe(false);
|
|
51
|
+
expect((0, types_1.isPrismaClient)([])).toBe(false);
|
|
208
52
|
});
|
|
209
53
|
});
|
|
210
54
|
describe('tryRequire', () => {
|
|
211
|
-
it('
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
expect(result).not.toBeNull();
|
|
216
|
-
expect(result).toHaveProperty('join');
|
|
217
|
-
expect(result).toHaveProperty('resolve');
|
|
218
|
-
});
|
|
219
|
-
it('should return null when module does not exist', () => {
|
|
220
|
-
// Act
|
|
221
|
-
const result = (0, types_1.tryRequire)('non-existent-module-xyz-123');
|
|
222
|
-
// Assert
|
|
223
|
-
expect(result).toBeNull();
|
|
224
|
-
});
|
|
225
|
-
it('should return null for invalid module name', () => {
|
|
226
|
-
// Act
|
|
227
|
-
const result = (0, types_1.tryRequire)('@invalid/non-existent-package');
|
|
228
|
-
// Assert
|
|
229
|
-
expect(result).toBeNull();
|
|
55
|
+
it('returns the resolved module when present', () => {
|
|
56
|
+
const path = (0, types_1.tryRequire)('path');
|
|
57
|
+
expect(path).not.toBeNull();
|
|
58
|
+
expect(typeof path?.join).toBe('function');
|
|
230
59
|
});
|
|
231
|
-
it('
|
|
232
|
-
|
|
233
|
-
const result = (0, types_1.tryRequire)('fs');
|
|
234
|
-
// Assert
|
|
235
|
-
expect(result).not.toBeNull();
|
|
236
|
-
expect(result).toHaveProperty('readFileSync');
|
|
237
|
-
expect(result).toHaveProperty('writeFileSync');
|
|
238
|
-
});
|
|
239
|
-
it('should return crypto module correctly', () => {
|
|
240
|
-
// Act
|
|
241
|
-
const result = (0, types_1.tryRequire)('crypto');
|
|
242
|
-
// Assert
|
|
243
|
-
expect(result).not.toBeNull();
|
|
244
|
-
expect(result).toHaveProperty('createHash');
|
|
60
|
+
it('returns null when the module cannot be resolved', () => {
|
|
61
|
+
expect((0, types_1.tryRequire)('definitely-not-a-real-module-xyz')).toBeNull();
|
|
245
62
|
});
|
|
246
63
|
});
|
|
247
64
|
describe('isModuleAvailable', () => {
|
|
248
|
-
it('
|
|
249
|
-
// Act & Assert
|
|
250
|
-
expect((0, types_1.isModuleAvailable)('path')).toBe(true);
|
|
65
|
+
it('returns true for built-in Node modules', () => {
|
|
251
66
|
expect((0, types_1.isModuleAvailable)('fs')).toBe(true);
|
|
252
|
-
expect((0, types_1.isModuleAvailable)('
|
|
253
|
-
expect((0, types_1.isModuleAvailable)('http')).toBe(true);
|
|
254
|
-
});
|
|
255
|
-
it('should return true for installed npm packages', () => {
|
|
256
|
-
// Act - Jest should be installed in the project
|
|
257
|
-
const result = (0, types_1.isModuleAvailable)('jest');
|
|
258
|
-
// Assert
|
|
259
|
-
expect(result).toBe(true);
|
|
260
|
-
});
|
|
261
|
-
it('should return false for non-existent modules', () => {
|
|
262
|
-
// Act
|
|
263
|
-
const result = (0, types_1.isModuleAvailable)('non-existent-module-xyz-456');
|
|
264
|
-
// Assert
|
|
265
|
-
expect(result).toBe(false);
|
|
266
|
-
});
|
|
267
|
-
it('should return false for invalid scoped packages', () => {
|
|
268
|
-
// Act
|
|
269
|
-
const result = (0, types_1.isModuleAvailable)('@non-existent-scope/non-existent-package');
|
|
270
|
-
// Assert
|
|
271
|
-
expect(result).toBe(false);
|
|
272
|
-
});
|
|
273
|
-
it('should return true for installed scoped packages', () => {
|
|
274
|
-
// Act - @nestjs/common should be installed
|
|
275
|
-
const result = (0, types_1.isModuleAvailable)('@nestjs/common');
|
|
276
|
-
// Assert
|
|
277
|
-
expect(result).toBe(true);
|
|
67
|
+
expect((0, types_1.isModuleAvailable)('path')).toBe(true);
|
|
278
68
|
});
|
|
279
|
-
it('
|
|
280
|
-
|
|
281
|
-
expect((0, types_1.isModuleAvailable)('')).toBe(true);
|
|
282
|
-
expect((0, types_1.isModuleAvailable)('.')).toBe(true);
|
|
69
|
+
it('returns true for installed packages', () => {
|
|
70
|
+
expect((0, types_1.isModuleAvailable)('@nestjs/common')).toBe(true);
|
|
283
71
|
});
|
|
284
|
-
it('
|
|
285
|
-
|
|
286
|
-
const result = (0, types_1.isModuleAvailable)('typescript');
|
|
287
|
-
// Assert
|
|
288
|
-
expect(result).toBe(true);
|
|
72
|
+
it('returns false for unknown modules', () => {
|
|
73
|
+
expect((0, types_1.isModuleAvailable)('definitely-not-a-real-module-xyz')).toBe(false);
|
|
289
74
|
});
|
|
290
75
|
});
|
|
291
76
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/watchers/query/types.spec.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"types.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/watchers/query/types.spec.ts"],"names":[],"mappings":";;AAAA,yDAMuC;AAEvC,QAAQ,CAAC,sCAAsC,EAAE,GAAG,EAAE;IACpD,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACzC,MAAM,UAAU,GAAG,CAAC,YAAqC,EAAE,EAAW,EAAE,CAAC,CAAC;YACxE,WAAW,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE;YACnC,OAAO,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;YACnC,WAAW,EAAE,EAAE;YACf,GAAG,SAAS;SACb,CAAC,CAAC;QAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;YAChE,MAAM,CAAC,IAAA,iCAAyB,EAAC,UAAU,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;YAChF,MAAM,CAAC,IAAA,iCAAyB,EAAC,UAAU,CAAC,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CACzF,IAAI,CACL,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;YAC3D,MAAM,CACJ,IAAA,iCAAyB,EAAC,UAAU,CAAC,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC,CAClF,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6CAA6C,EAAE,GA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