Skip to content

Commit 4b06184

Browse files
Fe/feature/ri 4876 optimize UI unit tests (#2678)
* #RI-4876 - Optimize ui unit tests --------- Co-authored-by: zalenskiSofteq <[email protected]>
1 parent 866d83c commit 4b06184

File tree

25 files changed

+931
-845
lines changed

25 files changed

+931
-845
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ jobs:
239239
- run:
240240
name: Unit tests UI
241241
command: |
242-
yarn test:cov --ci
242+
yarn test:cov --ci --silent
243243
- save_cache:
244244
<<: *uiDepsCacheKey
245245
paths:
File renamed without changes.

jest.config.js renamed to jest.config.cjs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const { TextDecoder, TextEncoder } = require('util')
2-
31
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
42
module.exports = {
5-
testURL: 'http://localhost/',
6-
runner: 'groups',
3+
testEnvironmentOptions: {
4+
url: 'http://localhost/'
5+
},
76
moduleNameMapper: {
87
'\\.(jpg|jpeg|png|ico|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
98
'<rootDir>/redisinsight/__mocks__/fileMock.js',
@@ -19,6 +18,8 @@ module.exports = {
1918
'unist-util-visit': '<rootDir>/redisinsight/__mocks__/unistUtilsVisit.js',
2019
'react-children-utilities': '<rootDir>/redisinsight/__mocks__/react-children-utilities.js',
2120
d3: '<rootDir>/node_modules/d3/dist/d3.min.js',
21+
'^uuid$': require.resolve('uuid'),
22+
msgpackr: require.resolve('msgpackr'),
2223
},
2324
setupFiles: [
2425
'<rootDir>/redisinsight/ui/src/setup-env.ts',
@@ -37,7 +38,8 @@ module.exports = {
3738
'tsx',
3839
'json',
3940
],
40-
testEnvironment: 'jsdom',
41+
testEnvironment: 'jest-environment-jsdom',
42+
// type: 'module',
4143
transformIgnorePatterns: [
4244
'node_modules/(?!(monaco-editor|react-monaco-editor)/)',
4345
],
@@ -63,8 +65,4 @@ module.exports = {
6365
// statements: 90,
6466
// },
6567
},
66-
globals: {
67-
TextDecoder,
68-
TextEncoder,
69-
},
7068
}

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"start:web:public": "cross-env PUBLIC_DEV=true NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./configs/webpack.config.web.dev.ts",
4343
"test": "jest ./redisinsight/ui -w 1",
4444
"test:watch": "jest ./redisinsight/ui --watch -w 1",
45-
"test:cov": "jest ./redisinsight/ui --coverage --runInBand",
45+
"test:cov": "jest ./redisinsight/ui --coverage --no-cache --forceExit -w 3",
4646
"test:cov:unit": "jest ./redisinsight/ui --group=-component --coverage -w 1",
4747
"test:cov:component": "jest ./redisinsight/ui --group=component --coverage -w 1",
4848
"type-check:ui": "tsc --project redisinsight/ui --noEmit"
@@ -143,6 +143,7 @@
143143
"@types/redux-mock-store": "^1.0.2",
144144
"@types/segment-analytics": "^0.0.34",
145145
"@types/supertest": "^2.0.8",
146+
"@types/text-encoding": "^0.0.37",
146147
"@types/uuid": "^8.3.4",
147148
"@types/webpack-bundle-analyzer": "^4.6.0",
148149
"@types/webpack-env": "^1.15.2",
@@ -188,15 +189,16 @@
188189
"identity-obj-proxy": "^3.0.0",
189190
"ioredis-mock": "^5.5.4",
190191
"ip": "^1.1.8",
191-
"jest": "^27.5.1",
192+
"jest": "^29.7.0",
193+
"jest-environment-jsdom": "^29.7.0",
192194
"jest-runner-groups": "^2.2.0",
193195
"jest-when": "^3.2.1",
194196
"license-checker": "^25.0.1",
195197
"lint-staged": "^10.2.11",
196198
"mini-css-extract-plugin": "2.7.2",
197199
"moment": "^2.29.3",
198200
"monaco-editor-webpack-plugin": "^6.0.0",
199-
"msw": "^0.45.0",
201+
"msw": "^1.3.2",
200202
"node-sass": "^8.0.0",
201203
"opencollective-postinstall": "^2.0.3",
202204
"react-hot-loader": "^4.13.0",
@@ -211,6 +213,7 @@
211213
"style-loader": "^2.0.0",
212214
"supertest": "^4.0.2",
213215
"terser-webpack-plugin": "^5.0.3",
216+
"text-encoding": "^0.7.0",
214217
"ts-jest": "27.1.5",
215218
"ts-loader": "^6.2.1",
216219
"ts-mockito": "^2.6.1",
@@ -291,5 +294,8 @@
291294
},
292295
"husky": {
293296
"hooks": {}
297+
},
298+
"browser": {
299+
"uuid": "./node_modules/uuid/dist/esm-browser/index.js"
294300
}
295301
}

redisinsight/__mocks__/rawproto.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const visit = jest.fn()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MOCK_TIMESTAMP = 1629128049027

redisinsight/ui/src/mocks/handlers/app/infoHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const APP_INFO_DATA_MOCK = {
1313

1414
const handlers: RestHandler[] = [
1515
// fetchServerInfo
16-
rest.get<DatabaseInstanceResponse[]>(getMswURL(ApiEndpoints.INFO), async (req, res, ctx) => res(
16+
rest.get<DatabaseInstanceResponse[]>(getMswURL(ApiEndpoints.INFO), async (_req, res, ctx) => res(
1717
ctx.status(200),
1818
ctx.json(APP_INFO_DATA_MOCK),
1919
))

redisinsight/ui/src/pages/triggeredFunctions/pages/Libraries/LibrariesPage.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
getTriggeredFunctionsLibrariesList,
77
triggeredFunctionsLibrariesSelector,
88
triggeredFunctionsAddLibrarySelector,
9-
setAddLibraryFormOpen,
109
} from 'uiSrc/slices/triggeredFunctions/triggeredFunctions'
1110
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
1211
import { TRIGGERED_FUNCTIONS_LIBRARIES_LIST_MOCKED_DATA } from 'uiSrc/mocks/data/triggeredFunctions'

redisinsight/ui/src/slices/tests/analytics/dbAnalysis.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,14 @@ describe('db analysis slice', () => {
377377
getDBAnalysis(),
378378
getDBAnalysisSuccess(data),
379379
loadDBAnalysisReports(),
380-
setSelectedAnalysisId(data.id)
380+
setSelectedAnalysisId(data.id),
381+
loadDBAnalysisReportsSuccess([
382+
{
383+
createdAt: mockAnalysis.createdAt,
384+
id: mockAnalysis.id,
385+
},
386+
mockHistoryReport,
387+
])
381388
]
382389

383390
expect(store.getActions()).toEqual(expectedActions)

redisinsight/ui/src/slices/tests/analytics/slowlog.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { apiService } from 'uiSrc/services'
55
import { setSlowLogUnits } from 'uiSrc/slices/app/context'
66
import { cleanup, mockedStore, initialStateDefault } from 'uiSrc/utils/test-utils'
77
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
8+
import { MOCK_TIMESTAMP } from 'uiSrc/mocks/data/dateNow'
89

910
import { SlowLog, SlowLogConfig } from 'apiSrc/modules/slow-log/models'
1011

@@ -27,7 +28,6 @@ import reducer, {
2728
slowLogSelector
2829
} from '../../analytics/slowlog'
2930

30-
const timestamp = 1629128049027
3131
let store: typeof mockedStore
3232
let dateNow: jest.SpyInstance<number>
3333

@@ -39,7 +39,7 @@ beforeEach(() => {
3939

4040
describe('slowLog slice', () => {
4141
beforeAll(() => {
42-
dateNow = jest.spyOn(Date, 'now').mockImplementation(() => timestamp)
42+
dateNow = jest.spyOn(Date, 'now').mockImplementation(() => MOCK_TIMESTAMP)
4343
})
4444

4545
afterAll(() => {
@@ -112,7 +112,7 @@ describe('slowLog slice', () => {
112112
...initialState,
113113
loading: false,
114114
data,
115-
lastRefreshTime: timestamp
115+
lastRefreshTime: MOCK_TIMESTAMP
116116
}
117117

118118
// Act

0 commit comments

Comments
 (0)