Skip to content

Commit

Permalink
Make checker for grafana happy by not calling console.log() (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekacnet authored Sep 28, 2024
1 parent db7e35f commit 5c3980a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/CubismPanelHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ export const zoomCallbackGen = (
): cubism.zoomCallback => {
const f = (start: number, end: number, selection: cubism.d3Selection) => {
if (options.links.length === 0) {
console.log("Can't do any zoom, there is no links to zoom to");
log_debug("Can't do any zoom, there is no links to zoom to");
return;
}
log_debug(`Doing a zoom from point ${start} to point ${end}`);

if (options.links.length > 1) {
console.log('There is more than one link, linked to this graph, will pick the first one');
log_debug('There is more than one link, linked to this graph, will pick the first one');
}
let link = options.links[0].url;
isString(link);
Expand Down
5 changes: 3 additions & 2 deletions src/misc_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ export function enableDebug(): void {
export function log_debug(message?: any, ...optionalParams: any[]): void {
// Set it to true to enable debugging
if (debug) {
let destination = console;
if (optionalParams.length > 0) {
return console.log(message, optionalParams.join(' '));
return destination.log(message, optionalParams.join(' '));
} else {
return console.log(message);
return destination.log(message);
}
}
}
3 changes: 3 additions & 0 deletions src/tests/CubismPanelHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as cubism from 'cubism-es';

import { DashboardLink, DashboardLinkType } from '@grafana/schema';
import { dateTime, toDataFrame, LoadingState, PanelData } from '@grafana/data';
import { enableDebug } from 'misc_utils';

const getValidSerie = (width: number, seed: number, span: number) => {
const timestamp = 1598919367000;
Expand Down Expand Up @@ -532,6 +533,7 @@ describe('zoomCallbackGen', () => {
const l = options.links[0];
options.links.push(l);
const zoomCallback = zoomCallbackGen(context, data, options);
enableDebug();
const oldFunc = console.log;
console.log = jest.fn();
const mockSelection = getSelection();
Expand All @@ -550,6 +552,7 @@ describe('zoomCallbackGen', () => {
it('should log a message if there are no links to zoom to', () => {
options = createMockOptions();
const zoomCallback = zoomCallbackGen(context, data, options);
enableDebug();
const oldFunc = console.log;
console.log = jest.fn();

Expand Down

0 comments on commit 5c3980a

Please sign in to comment.