Skip to content

Commit e9d4a67

Browse files
Merge pull request #3956 from RedisInsight/be/feature/api-packages-jest
update jest
2 parents da11fe4 + bf36292 commit e9d4a67

33 files changed

+1112
-1703
lines changed

redisinsight/api/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
"resolutions": {
4343
"nanoid": "^3.1.31",
4444
"word-wrap": "1.2.4",
45+
"jest/**/micromatch": "^4.0.8",
46+
"ts-loader/micromatch": "^4.0.8",
4547
"mocha/minimatch": "^3.0.5",
4648
"@nestjs/platform-socket.io/socket.io": "^4.8.0",
4749
"**/semver": "^7.5.2",
@@ -120,7 +122,7 @@
120122
"eslint-plugin-import": "^2.20.1",
121123
"eslint-plugin-sonarjs": "^0.9.1",
122124
"ioredis-mock": "^8.2.2",
123-
"jest": "^26.6.3",
125+
"jest": "^29.7.0",
124126
"jest-when": "^3.2.1",
125127
"joi": "^17.4.0",
126128
"mocha": "^8.4.0",
@@ -132,7 +134,7 @@
132134
"rimraf": "^3.0.2",
133135
"socket.io-mock": "^1.3.2",
134136
"supertest": "^4.0.2",
135-
"ts-jest": "^26.1.0",
137+
"ts-jest": "^29.2.5",
136138
"ts-loader": "^6.2.1",
137139
"ts-mocha": "^8.0.0",
138140
"ts-node": "^9.1.1",
@@ -164,8 +166,7 @@
164166
"moduleNameMapper": {
165167
"src/(.*)": "<rootDir>/$1",
166168
"apiSrc/(.*)": "<rootDir>/$1",
167-
"tests/(.*)": "<rootDir>/__tests__/$1",
168-
"axios": "axios/dist/node/axios.cjs"
169+
"tests/(.*)": "<rootDir>/__tests__/$1"
169170
}
170171
}
171172
}

redisinsight/api/src/__mocks__/bulk-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const mockCombinedStream = {
4848

4949
export const mockBulkActionOverviewMatcher = {
5050
...mockBulkActionOverview,
51-
duration: jasmine.any(Number),
51+
duration: expect.any(Number),
5252
};
5353

5454
export const mockBulkActionFilter = new BulkActionFilter();

redisinsight/api/src/modules/ai/query/ai-query.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('AiQueryService', () => {
5757
clientSocket.disconnect();
5858
serverSocket.disconnect();
5959
wsServer.close();
60-
httpServer.stop();
60+
httpServer?.stop?.();
6161
});
6262

6363
beforeEach(async () => {

redisinsight/api/src/modules/ai/query/repositories/local.ai-query.message.repository.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ describe('LocalAiQueryAuthProvider', () => {
5151

5252
encryptionService.decrypt.mockImplementation((value) => value);
5353
when(encryptionService.decrypt)
54-
.calledWith(mockAiQueryHumanMessageEntity.content, jasmine.anything())
54+
.calledWith(mockAiQueryHumanMessageEntity.content, expect.anything())
5555
.mockResolvedValue(mockAiQueryHumanMessage.content)
56-
.calledWith(mockAiQueryAiResponseEntity.content, jasmine.anything())
56+
.calledWith(mockAiQueryAiResponseEntity.content, expect.anything())
5757
.mockResolvedValue(mockAiQueryAiResponse.content)
58-
.calledWith(mockAiQueryAiResponseEntity.steps, jasmine.anything())
58+
.calledWith(mockAiQueryAiResponseEntity.steps, expect.anything())
5959
.mockResolvedValue(JSON.stringify(mockAiQueryAiResponse.steps));
6060

6161
encryptionService.encrypt.mockImplementation((value) => value);
6262
when(encryptionService.encrypt)
63-
.calledWith(mockAiQueryHumanMessage.content, jasmine.anything())
63+
.calledWith(mockAiQueryHumanMessage.content, expect.anything())
6464
.mockResolvedValue(mockAiQueryHumanMessageEntity.content)
65-
.calledWith(mockAiQueryAiResponse.content, jasmine.anything())
65+
.calledWith(mockAiQueryAiResponse.content, expect.anything())
6666
.mockResolvedValue(mockAiQueryAiResponseEntity.content)
67-
.calledWith(JSON.stringify(mockAiQueryAiResponse.steps), jasmine.anything())
67+
.calledWith(JSON.stringify(mockAiQueryAiResponse.steps), expect.anything())
6868
.mockResolvedValue(mockAiQueryAiResponseEntity.steps);
6969
});
7070

redisinsight/api/src/modules/autodiscovery/autodiscovery.service.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
import { SettingsService } from 'src/modules/settings/settings.service';
1414
import { AutodiscoveryService } from 'src/modules/autodiscovery/autodiscovery.service';
1515
import { DatabaseService } from 'src/modules/database/database.service';
16-
import { mocked } from 'ts-jest/utils';
1716
import config, { Config } from 'src/utils/config';
1817
import { RedisClientFactory } from 'src/modules/redis/redis.client.factory';
1918
import { ConstantsProvider } from 'src/modules/constants/providers/constants.provider';
@@ -84,7 +83,7 @@ describe('AutodiscoveryService', () => {
8483
databaseService = module.get(DatabaseService);
8584
redisClientFactory = module.get(RedisClientFactory);
8685

87-
mocked(utils.convertRedisInfoReplyToObject).mockReturnValue({
86+
(utils.convertRedisInfoReplyToObject as jest.Mock).mockReturnValue({
8887
server: {
8988
redis_mode: 'standalone',
9089
},
@@ -155,7 +154,7 @@ describe('AutodiscoveryService', () => {
155154
let addRedisDatabaseSpy;
156155

157156
beforeEach(async () => {
158-
mocked(getAvailableEndpoints).mockResolvedValue([]);
157+
(getAvailableEndpoints as jest.Mock).mockResolvedValue([]);
159158
addRedisDatabaseSpy = jest.spyOn(service as any, 'addRedisDatabase');
160159
addRedisDatabaseSpy.mockResolvedValue(null);
161160
});
@@ -167,7 +166,8 @@ describe('AutodiscoveryService', () => {
167166
});
168167

169168
it('should should call addRedisDatabase 2 times', async () => {
170-
mocked(getAvailableEndpoints).mockResolvedValueOnce([mockAutodiscoveryEndpoint, mockAutodiscoveryEndpoint]);
169+
(getAvailableEndpoints as jest.Mock)
170+
.mockResolvedValueOnce([mockAutodiscoveryEndpoint, mockAutodiscoveryEndpoint]);
171171
await service['discoverDatabases'](mockSessionMetadata);
172172

173173
expect(addRedisDatabaseSpy).toHaveBeenCalledTimes(2);
@@ -193,7 +193,7 @@ describe('AutodiscoveryService', () => {
193193
});
194194

195195
it('should not create database if redis_mode is not standalone', async () => {
196-
mocked(utils.convertRedisInfoReplyToObject).mockReturnValueOnce({
196+
(utils.convertRedisInfoReplyToObject as jest.Mock).mockReturnValueOnce({
197197
server: {
198198
redis_mode: 'cluster',
199199
},

redisinsight/api/src/modules/autodiscovery/utils/autodiscovery.util.spec.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
import * as os from 'os';
55
import * as ch from 'child_process';
66
import * as net from 'net';
7-
import { mocked } from 'ts-jest/utils';
87
import * as events from 'events';
98
import * as stream from 'stream';
109
import { ChildProcess } from 'child_process';
@@ -39,17 +38,17 @@ describe('getSpawnArgs', () => {
3938
const getSpawnArgsTests = [
4039
{
4140
name: 'Linux',
42-
before: () => mocked(os.type).mockReturnValue('Linux'),
41+
before: () => (os.type as jest.Mock).mockReturnValue('Linux'),
4342
output: ['netstat', ['-anpt']],
4443
},
4544
{
4645
name: 'Darwin',
47-
before: () => mocked(os.type).mockReturnValue('Darwin'),
46+
before: () => (os.type as jest.Mock).mockReturnValue('Darwin'),
4847
output: ['netstat', ['-anvp', 'tcp']],
4948
},
5049
{
5150
name: 'Windows_NT',
52-
before: () => mocked(os.type).mockReturnValue('Windows_NT'),
51+
before: () => (os.type as jest.Mock).mockReturnValue('Windows_NT'),
5352
output: ['netstat.exe', ['-a', '-n', '-o']],
5453
},
5554
];
@@ -67,8 +66,8 @@ describe('getSpawnArgs', () => {
6766

6867
describe('getRunningProcesses', () => {
6968
beforeEach(() => {
70-
mocked(os.type).mockReturnValue('Linux');
71-
mocked(ch.spawn).mockReturnValue(mockChildProcess);
69+
(os.type as jest.Mock).mockReturnValue('Linux');
70+
(ch.spawn as jest.Mock).mockReturnValue(mockChildProcess);
7271
});
7372
const getRunningProcessesTests = [
7473
{
@@ -94,7 +93,7 @@ describe('getRunningProcesses', () => {
9493
});
9594

9695
it('Should throw an error for unsupported platform', async () => {
97-
mocked(os.type).mockReturnValueOnce('custom_os');
96+
(os.type as jest.Mock).mockReturnValueOnce('custom_os');
9897

9998
try {
10099
await autodiscoveryUtility.getRunningProcesses();
@@ -172,7 +171,7 @@ describe('getTCPEndpoints', () => {
172171

173172
describe('testEndpoint', () => {
174173
beforeEach(() => {
175-
mocked(net.createConnection).mockReturnValue(mockSocket);
174+
(net.createConnection as jest.Mock).mockReturnValue(mockSocket);
176175
});
177176
const testEndpointTests = [
178177
{
@@ -224,7 +223,7 @@ describe('getAvailableEndpoints', () => {
224223
beforeEach(() => {
225224
const getRunningProcessesSpy = jest.spyOn(autodiscoveryUtility, 'getRunningProcesses');
226225
getRunningProcessesSpy.mockResolvedValue(['']);
227-
mocked(net.createConnection).mockReturnValue(mockSocket);
226+
(net.createConnection as jest.Mock).mockReturnValue(mockSocket);
228227
});
229228
const getAvailableEndpointsTests = [
230229
{

redisinsight/api/src/modules/browser/keys/scanner/strategies/cluster.scanner.strategy.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,16 +776,16 @@ describe('Cluster Scanner Strategy', () => {
776776
beforeEach(() => {
777777
when(mockClusterRedisClient.sendPipeline)
778778
.calledWith([
779-
jasmine.arrayContaining([BrowserToolKeysCommands.Ttl]),
780-
jasmine.arrayContaining(['memory', 'usage']),
781-
jasmine.arrayContaining([BrowserToolKeysCommands.Type]),
779+
expect.arrayContaining([BrowserToolKeysCommands.Ttl]),
780+
expect.arrayContaining(['memory', 'usage']),
781+
expect.arrayContaining([BrowserToolKeysCommands.Type]),
782782
],
783783
{ replyEncoding: 'utf8' })
784784
.mockResolvedValue([[null, -1], [null, 50], [null, 'string']]);
785785
when(mockClusterRedisClient.sendPipeline)
786786
.calledWith([
787-
jasmine.arrayContaining([BrowserToolKeysCommands.Ttl]),
788-
jasmine.arrayContaining(['memory', 'usage']),
787+
expect.arrayContaining([BrowserToolKeysCommands.Ttl]),
788+
expect.arrayContaining(['memory', 'usage']),
789789
],
790790
{ replyEncoding: 'utf8' })
791791
.mockResolvedValue([[null, 999], [null, 555]]);

redisinsight/api/src/modules/bulk-actions/bulk-import.service.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ describe('BulkImportService', () => {
162162
spy.mockResolvedValue(mockSummary);
163163
expect(await service.import(mockClientMetadata, mockReadableStream)).toEqual({
164164
...mockImportResult,
165-
duration: jasmine.anything(),
165+
duration: expect.anything(),
166166
});
167167
expect(analytics.sendActionSucceed).toHaveBeenCalledWith({
168168
...mockImportResult,
169-
duration: jasmine.anything(),
169+
duration: expect.anything(),
170170
});
171171
});
172172

@@ -185,7 +185,7 @@ describe('BulkImportService', () => {
185185
failed: 0,
186186
errors: [],
187187
},
188-
duration: jasmine.anything(),
188+
duration: expect.anything(),
189189
});
190190
});
191191

@@ -204,7 +204,7 @@ describe('BulkImportService', () => {
204204
failed: 0,
205205
errors: [],
206206
},
207-
duration: jasmine.anything(),
207+
duration: expect.anything(),
208208
});
209209
});
210210

@@ -225,7 +225,7 @@ describe('BulkImportService', () => {
225225
failed: 2,
226226
errors: [],
227227
},
228-
duration: jasmine.anything(),
228+
duration: expect.anything(),
229229
});
230230
expect(mockStandaloneRedisClient.disconnect).toHaveBeenCalled();
231231
});

redisinsight/api/src/modules/certificate/repositories/local.ca-certificate.repository.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('LocalCaCertificateRepository', () => {
5757
repository.save.mockResolvedValue(mockCaCertificateEntity);
5858
repository.create.mockReturnValue(mockCaCertificate); // not entity since it happens before encryption
5959

60-
when(encryptionService.decrypt).calledWith(mockCaCertificateCertificateEncrypted, jasmine.anything())
60+
when(encryptionService.decrypt).calledWith(mockCaCertificateCertificateEncrypted, expect.anything())
6161
.mockResolvedValue(mockCaCertificateCertificatePlain);
6262
when(encryptionService.encrypt).calledWith(mockCaCertificateCertificatePlain)
6363
.mockResolvedValue({

redisinsight/api/src/modules/certificate/repositories/local.client-certificate.repository.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ describe('LocalClientCertificateRepository', () => {
6565
repository.create.mockReturnValue(mockClientCertificate); // not an entity since create happens before encryption
6666

6767
when(encryptionService.decrypt)
68-
.calledWith(mockClientCertificateCertificateEncrypted, jasmine.anything())
68+
.calledWith(mockClientCertificateCertificateEncrypted, expect.anything())
6969
.mockResolvedValue(mockClientCertificateCertificatePlain)
70-
.calledWith(mockClientCertificateKeyEncrypted, jasmine.anything())
70+
.calledWith(mockClientCertificateKeyEncrypted, expect.anything())
7171
.mockResolvedValue(mockClientCertificateKeyPlain);
7272
when(encryptionService.encrypt)
7373
.calledWith(mockClientCertificateCertificatePlain)

0 commit comments

Comments
 (0)