diff --git a/package.json b/package.json index 074030a1b9d..8c6e29fc051 100644 --- a/package.json +++ b/package.json @@ -190,6 +190,7 @@ "jest-date-mock": "1.0.8", "jest-junit": "13.0.0", "jest-matcher-utils": "27.5.0", + "jest-mock-console": "1.2.3", "lerna": "^4.0.0", "lint-staged": "12.3.3", "mini-css-extract-plugin": "2.5.3", diff --git a/public/app/features/live/centrifuge/LiveDataStream.test.ts b/public/app/features/live/centrifuge/LiveDataStream.test.ts index 3129d14e445..3ef7b4ec408 100644 --- a/public/app/features/live/centrifuge/LiveDataStream.test.ts +++ b/public/app/features/live/centrifuge/LiveDataStream.test.ts @@ -17,6 +17,7 @@ import { mapValues } from 'lodash'; import { StreamingFrameAction } from '@grafana/runtime'; import { isStreamingResponseData, StreamingResponseData, StreamingResponseDataType } from '../data/utils'; import { StreamingDataFrame } from '../data/StreamingDataFrame'; +import mockConsole, { RestoreConsole } from 'jest-mock-console'; type SubjectsInsteadOfObservables = { [key in keyof T]: T[key] extends Observable ? Subject : T[key]; @@ -119,6 +120,16 @@ const dummyErrorMessage = 'dummy-error'; describe('LiveDataStream', () => { jest.useFakeTimers(); + let restoreConsole: RestoreConsole | undefined; + + beforeEach(() => { + restoreConsole = mockConsole(); + }); + + afterEach(() => { + restoreConsole?.(); + }); + const expectValueCollectionState = ( valuesCollection: ValuesCollection, state: { errors: number; values: number; complete: boolean } diff --git a/public/app/features/live/live.test.ts b/public/app/features/live/live.test.ts index 490b7f9aa56..58355588a39 100644 --- a/public/app/features/live/live.test.ts +++ b/public/app/features/live/live.test.ts @@ -4,8 +4,11 @@ import { Subject } from 'rxjs'; import { DataQueryResponse, FieldType, LiveChannelScope } from '@grafana/data'; import { StreamingDataFrame } from './data/StreamingDataFrame'; import { StreamingResponseDataType } from './data/utils'; +import mockConsole, { RestoreConsole } from 'jest-mock-console'; describe('GrafanaLiveService', () => { + let restoreConsole: RestoreConsole | undefined; + const deps = { backendSrv: {}, centrifugeSrv: { @@ -25,6 +28,11 @@ describe('GrafanaLiveService', () => { beforeEach(() => { jest.clearAllMocks(); + restoreConsole = mockConsole(); + }); + + afterEach(() => { + restoreConsole?.(); }); it('should map response from Centrifuge Service to a streaming data frame', async () => { diff --git a/yarn.lock b/yarn.lock index f5aa18ed44a..d08e00918a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20258,6 +20258,7 @@ __metadata: jest-date-mock: 1.0.8 jest-junit: 13.0.0 jest-matcher-utils: 27.5.0 + jest-mock-console: 1.2.3 jquery: 3.6.0 json-source-map: 0.6.1 jsurl: ^0.1.5 @@ -23143,6 +23144,15 @@ __metadata: languageName: node linkType: hard +"jest-mock-console@npm:1.2.3": + version: 1.2.3 + resolution: "jest-mock-console@npm:1.2.3" + peerDependencies: + jest: ">= 22.4.2" + checksum: 16f449e309919309b87b6ffb7171ff1feccb628bac97c44aa59594951447833abaaac4957be4258e1c7ce3c54ef6e24cb1e2a7c310f7b8cbc6b598323819dc10 + languageName: node + linkType: hard + "jest-mock@npm:^24.0.0, jest-mock@npm:^24.9.0": version: 24.9.0 resolution: "jest-mock@npm:24.9.0"