The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/packages/grafana-ui/src/utils/deprecationWarning.test.ts

34 lines
1.3 KiB

import { deprecationWarning } from './deprecationWarning';
test('It should not output deprecation warnings too often', () => {
let dateNowValue = 10000000;
const spyConsoleWarn = jest.spyOn(console, 'warn').mockImplementation();
const spyDateNow = jest.spyOn(global.Date, 'now').mockImplementation(() => dateNowValue);
// Make sure the mock works
expect(Date.now()).toEqual(dateNowValue);
expect(console.warn).toHaveBeenCalledTimes(0);
// Call the deprecation many times
deprecationWarning('file', 'oldName', 'newName');
deprecationWarning('file', 'oldName', 'newName');
deprecationWarning('file', 'oldName', 'newName');
deprecationWarning('file', 'oldName', 'newName');
deprecationWarning('file', 'oldName', 'newName');
expect(console.warn).toHaveBeenCalledTimes(1);
// Increment the time by 1min
dateNowValue += 60000;
deprecationWarning('file', 'oldName', 'newName');
deprecationWarning('file', 'oldName', 'newName');
expect(console.warn).toHaveBeenCalledTimes(2);
deprecationWarning('file2', 'oldName', 'newName');
deprecationWarning('file2', 'oldName', 'newName');
deprecationWarning('file2', 'oldName', 'newName');
expect(console.warn).toHaveBeenCalledTimes(3);
// or restoreMocks automatically?
spyConsoleWarn.mockRestore();
spyDateNow.mockRestore();
});