From c8b59b79c3bf921beccb902be8cfec8ccbd41423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Fri, 19 Mar 2021 13:10:03 +0100 Subject: [PATCH] Chore: Fix strict errors, down to 340 (#32109) * Chore: reduces misc reducerTester strict issues * Chore: fixes various strict errors in reducer tests for ElasticSearch * Chore: lowers errors in AzureMonitor DataSource tests --- .../containers/SoloPanelPage.test.tsx | 4 +- .../app/features/explore/state/query.test.ts | 2 +- .../variables/inspect/reducer.test.ts | 4 +- .../cloudwatch/specs/datasource.test.ts | 8 +- .../state/reducer.test.ts | 6 +- .../state/reducer.test.ts | 21 +-- .../state/reducer.test.ts | 10 +- .../state/reducer.test.ts | 25 +-- .../components/QueryEditor/state.test.ts | 12 +- .../azure_monitor_datasource.test.ts | 164 ++++++++---------- public/test/core/redux/reducerTester.ts | 18 +- scripts/ci-check-strict.sh | 2 +- 12 files changed, 129 insertions(+), 147 deletions(-) diff --git a/public/app/features/dashboard/containers/SoloPanelPage.test.tsx b/public/app/features/dashboard/containers/SoloPanelPage.test.tsx index b3a648704ad..184f283419e 100644 --- a/public/app/features/dashboard/containers/SoloPanelPage.test.tsx +++ b/public/app/features/dashboard/containers/SoloPanelPage.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; -import { SoloPanelPage, Props } from './SoloPanelPage'; +import { Props, SoloPanelPage } from './SoloPanelPage'; import { Props as DashboardPanelProps } from '../dashgrid/DashboardPanel'; import { DashboardModel } from '../state'; import { DashboardRoutes } from 'app/types'; @@ -82,7 +82,7 @@ function soloPanelPageScenario(description: string, scenarioFn: (ctx: ScenarioCo ctx.dashboard = props.dashboard; let { rerender } = render(); // prop updates will be submitted by rerendering the same component with different props - ctx.rerender = (newProps: Partial) => { + ctx.rerender = (newProps?: Partial) => { Object.assign(props, newProps); rerender(); }; diff --git a/public/app/features/explore/state/query.test.ts b/public/app/features/explore/state/query.test.ts index 28751d05697..99b90a35404 100644 --- a/public/app/features/explore/state/query.test.ts +++ b/public/app/features/explore/state/query.test.ts @@ -114,7 +114,7 @@ describe('running queries', () => { describe('reducer', () => { describe('scanning', () => { it('should start scanning', () => { - const initialState = { + const initialState: ExploreItemState = { ...makeExplorePaneState(), scanning: false, }; diff --git a/public/app/features/variables/inspect/reducer.test.ts b/public/app/features/variables/inspect/reducer.test.ts index 974b30eedcc..e7d8c763d1a 100644 --- a/public/app/features/variables/inspect/reducer.test.ts +++ b/public/app/features/variables/inspect/reducer.test.ts @@ -1,12 +1,12 @@ import { reducerTester } from '../../../../test/core/redux/reducerTester'; -import { initialVariableInspectState, initInspect, variableInspectReducer } from './reducer'; +import { initialVariableInspectState, initInspect, variableInspectReducer, VariableInspectState } from './reducer'; import { textboxBuilder } from '../shared/testing/builders'; describe('variableInspectReducer', () => { describe('when initInspect is dispatched', () => { it('then state should be correct', () => { const variable = textboxBuilder().withId('text').withName('text').build(); - reducerTester() + reducerTester() .givenReducer(variableInspectReducer, { ...initialVariableInspectState }) .whenActionIsDispatched( initInspect({ diff --git a/public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts b/public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts index afc8ba357be..9c0111e5e6d 100644 --- a/public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts +++ b/public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts @@ -2,6 +2,7 @@ import { interval, of, throwError } from 'rxjs'; import { DataFrame, DataQueryErrorType, + DataQueryRequest, DataQueryResponse, DataSourceInstanceSettings, dateMath, @@ -16,6 +17,7 @@ import { CloudWatchLogsQuery, CloudWatchLogsQueryStatus, CloudWatchMetricsQuery, + CloudWatchQuery, LogAction, } from '../types'; import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__ @@ -301,7 +303,7 @@ describe('CloudWatchDatasource', () => { it('should call the replace method on provided log groups', () => { const { ds } = getTestContext(); - const replaceSpy = jest.spyOn(ds, 'replace').mockImplementation((target: string) => target); + const replaceSpy = jest.spyOn(ds, 'replace').mockImplementation((target?: string) => target ?? ''); ds.makeLogActionRequest('StartQuery', [ { queryString: 'test query string', @@ -425,7 +427,7 @@ describe('CloudWatchDatasource', () => { it.each(['pNN.NN', 'p9', 'p99.', 'p99.999'])('should cancel query for invalid extended statistics (%s)', (stat) => { const { ds } = getTestContext({ response }); - const query = { + const query: DataQueryRequest = ({ range: defaultTimeRange, rangeRaw: { from: 1483228800, to: 1483232400 }, targets: [ @@ -442,7 +444,7 @@ describe('CloudWatchDatasource', () => { period: '60s', }, ], - }; + } as unknown) as DataQueryRequest; expect(ds.query.bind(ds, query)).toThrow(/Invalid extended statistics/); }); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/FiltersSettingsEditor/state/reducer.test.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/FiltersSettingsEditor/state/reducer.test.ts index 0d68450812d..4e63765bae1 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/FiltersSettingsEditor/state/reducer.test.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/FiltersSettingsEditor/state/reducer.test.ts @@ -5,7 +5,7 @@ import { reducer } from './reducer'; describe('Filters Bucket Aggregation Settings Reducer', () => { it('Should correctly add new filter', () => { - reducerTester() + reducerTester() .givenReducer(reducer, []) .whenActionIsDispatched(addFilter()) .thenStatePredicateShouldEqual((state: Filter[]) => state.length === 1); @@ -22,7 +22,7 @@ describe('Filters Bucket Aggregation Settings Reducer', () => { query: '*', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstFilter, secondFilter]) .whenActionIsDispatched(removeFilter(0)) .thenStateShouldEqual([secondFilter]); @@ -44,7 +44,7 @@ describe('Filters Bucket Aggregation Settings Reducer', () => { query: 'Changed query', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstFilter, secondFilter]) .whenActionIsDispatched(changeFilter(1, expectedSecondFilter)) .thenStateShouldEqual([firstFilter, expectedSecondFilter]); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts index 34dcd0db280..b9e5554ea07 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts @@ -12,6 +12,7 @@ import { } from './actions'; import { reducer } from './reducer'; import { initQuery } from '../../state'; +import { ElasticsearchQuery } from 'app/plugins/datasource/elasticsearch/types'; describe('Bucket Aggregations Reducer', () => { it('Should correctly add new aggregations', () => { @@ -27,7 +28,7 @@ describe('Bucket Aggregations Reducer', () => { settings: bucketAggregationConfig['terms'].defaultSettings, }; - reducerTester() + reducerTester() .givenReducer(reducer, []) .whenActionIsDispatched(addBucketAggregation(firstAggregation.id)) .thenStateShouldEqual([firstAggregation]) @@ -46,7 +47,7 @@ describe('Bucket Aggregations Reducer', () => { type: 'date_histogram', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(removeBucketAggregation(firstAggregation.id)) .thenStateShouldEqual([secondAggregation]); @@ -68,7 +69,7 @@ describe('Bucket Aggregations Reducer', () => { settings: bucketAggregationConfig['histogram'].defaultSettings, }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(changeBucketAggregationType(secondAggregation.id, expectedSecondAggregation.type)) .thenStateShouldEqual([firstAggregation, expectedSecondAggregation]); @@ -89,7 +90,7 @@ describe('Bucket Aggregations Reducer', () => { field: 'new field', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(changeBucketAggregationField(secondAggregation.id, expectedSecondAggregation.field)) .thenStateShouldEqual([firstAggregation, expectedSecondAggregation]); @@ -104,17 +105,17 @@ describe('Bucket Aggregations Reducer', () => { }, ]; - reducerTester() + reducerTester() .givenReducer(reducer, initialState) // If the new metric aggregation is `isSingleMetric` we should remove all bucket aggregations. .whenActionIsDispatched(changeMetricType('Some id', 'raw_data')) - .thenStatePredicateShouldEqual((newState: BucketAggregation[]) => newState.length === 0) + .thenStatePredicateShouldEqual((newState) => newState?.length === 0) // Switching back to another aggregation that is NOT `isSingleMetric` should bring back a bucket aggregation .whenActionIsDispatched(changeMetricType('Some id', 'max')) - .thenStatePredicateShouldEqual((newState: BucketAggregation[]) => newState.length === 1) + .thenStatePredicateShouldEqual((newState) => newState?.length === 1) // When none of the above is true state shouldn't change. .whenActionIsDispatched(changeMetricType('Some id', 'min')) - .thenStatePredicateShouldEqual((newState: BucketAggregation[]) => newState.length === 1); + .thenStatePredicateShouldEqual((newState) => newState?.length === 1); }); }); @@ -135,7 +136,7 @@ describe('Bucket Aggregations Reducer', () => { min_doc_count: '1', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched( changeBucketAggregationSetting(firstAggregation, 'min_doc_count', expectedSettings.min_doc_count!) @@ -144,7 +145,7 @@ describe('Bucket Aggregations Reducer', () => { }); it('Should correctly initialize first Bucket Aggregation', () => { - reducerTester() + reducerTester() .givenReducer(reducer, []) .whenActionIsDispatched(initQuery()) .thenStateShouldEqual([defaultBucketAgg('2')]); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/BucketScriptSettingsEditor/state/reducer.test.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/BucketScriptSettingsEditor/state/reducer.test.ts index bb1c99f5c49..d30c83d98fc 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/BucketScriptSettingsEditor/state/reducer.test.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/BucketScriptSettingsEditor/state/reducer.test.ts @@ -15,7 +15,7 @@ describe('BucketScript Settings Reducer', () => { pipelineAgg: '', }; - reducerTester() + reducerTester() .givenReducer(reducer, []) .whenActionIsDispatched(addPipelineVariable()) .thenStateShouldEqual([expectedPipelineVar]); @@ -32,7 +32,7 @@ describe('BucketScript Settings Reducer', () => { pipelineAgg: '', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstVar, secondVar]) .whenActionIsDispatched(removePipelineVariable(0)) .thenStateShouldEqual([secondVar]); @@ -54,7 +54,7 @@ describe('BucketScript Settings Reducer', () => { name: 'new name', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstVar, secondVar]) .whenActionIsDispatched(renamePipelineVariable(expectedSecondVar.name, 1)) .thenStateShouldEqual([firstVar, expectedSecondVar]); @@ -76,7 +76,7 @@ describe('BucketScript Settings Reducer', () => { pipelineAgg: 'some new agg', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstVar, secondVar]) .whenActionIsDispatched(changePipelineVariableMetric(expectedSecondVar.pipelineAgg, 1)) .thenStateShouldEqual([firstVar, expectedSecondVar]); @@ -94,7 +94,7 @@ describe('BucketScript Settings Reducer', () => { }, ]; - reducerTester() + reducerTester() .givenReducer(reducer, initialState) .whenActionIsDispatched({ type: 'THIS ACTION SHOULD NOT HAVE ANY EFFECT IN THIS REDUCER' }) .thenStateShouldEqual(initialState); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts index 293c03efb87..fb763e05ff8 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts @@ -14,6 +14,7 @@ import { Derivative, ExtendedStats, MetricAggregation } from '../aggregations'; import { defaultMetricAgg } from '../../../../query_def'; import { metricAggregationConfig } from '../utils'; import { initQuery } from '../../state'; +import { ElasticsearchQuery } from 'app/plugins/datasource/elasticsearch/types'; describe('Metric Aggregations Reducer', () => { it('should correctly add new aggregations', () => { @@ -26,7 +27,7 @@ describe('Metric Aggregations Reducer', () => { type: 'count', }; - reducerTester() + reducerTester() .givenReducer(reducer, []) .whenActionIsDispatched(addMetric(firstAggregation.id)) .thenStateShouldEqual([firstAggregation]) @@ -45,7 +46,7 @@ describe('Metric Aggregations Reducer', () => { type: 'count', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(removeMetric(firstAggregation.id)) .thenStateShouldEqual([secondAggregation]); @@ -54,7 +55,7 @@ describe('Metric Aggregations Reducer', () => { it('Should insert a default aggregation when the last one is removed', () => { const initialState: MetricAggregation[] = [{ id: '2', type: 'avg' }]; - reducerTester() + reducerTester() .givenReducer(reducer, initialState) .whenActionIsDispatched(removeMetric(initialState[0].id)) .thenStateShouldEqual([defaultMetricAgg()]); @@ -74,7 +75,7 @@ describe('Metric Aggregations Reducer', () => { const expectedSecondAggregation: MetricAggregation = { ...secondAggregation, type: 'avg' }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(changeMetricType(secondAggregation.id, expectedSecondAggregation.type)) .thenStateShouldEqual([firstAggregation, { ...secondAggregation, type: expectedSecondAggregation.type }]); @@ -96,7 +97,7 @@ describe('Metric Aggregations Reducer', () => { ...metricAggregationConfig['raw_data'].defaults, }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(changeMetricType(secondAggregation.id, expectedAggregation.type)) .thenStateShouldEqual([expectedAggregation]); @@ -124,7 +125,7 @@ describe('Metric Aggregations Reducer', () => { field: 'new field', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) // When changing a a pipelineAggregation field we set both pipelineAgg and field .whenActionIsDispatched(changeMetricField(secondAggregation.id, expectedSecondAggregation.field)) @@ -145,7 +146,7 @@ describe('Metric Aggregations Reducer', () => { type: 'count', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(toggleMetricVisibility(firstAggregation.id)) .thenStateShouldEqual([{ ...firstAggregation, hide: true }, secondAggregation]) @@ -170,7 +171,7 @@ describe('Metric Aggregations Reducer', () => { unit: 'Changed unit', }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(changeMetricSetting(firstAggregation, 'unit', expectedSettings.unit!)) .thenStateShouldEqual([{ ...firstAggregation, settings: expectedSettings }, secondAggregation]); @@ -193,7 +194,7 @@ describe('Metric Aggregations Reducer', () => { avg: false, }; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(changeMetricMeta(firstAggregation, 'avg', expectedMeta.avg!)) .thenStateShouldEqual([{ ...firstAggregation, meta: expectedMeta }, secondAggregation]); @@ -211,7 +212,7 @@ describe('Metric Aggregations Reducer', () => { const expectedHide: typeof firstAggregation['hide'] = false; - reducerTester() + reducerTester() .givenReducer(reducer, [firstAggregation, secondAggregation]) .whenActionIsDispatched(changeMetricAttribute(firstAggregation, 'hide', expectedHide)) .thenStateShouldEqual([{ ...firstAggregation, hide: expectedHide }, secondAggregation]); @@ -225,14 +226,14 @@ describe('Metric Aggregations Reducer', () => { }, ]; - reducerTester() + reducerTester() .givenReducer(reducer, initialState) .whenActionIsDispatched({ type: 'THIS ACTION SHOULD NOT HAVE ANY EFFECT IN THIS REDUCER' }) .thenStateShouldEqual(initialState); }); it('Should correctly initialize first Metric Aggregation', () => { - reducerTester() + reducerTester() .givenReducer(reducer, []) .whenActionIsDispatched(initQuery()) .thenStateShouldEqual([defaultMetricAgg('1')]); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/state.test.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/state.test.ts index ada6bdd2c7b..6cb0b041b4e 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/state.test.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/state.test.ts @@ -7,7 +7,7 @@ describe('Query Reducer', () => { it('Should maintain the previous `query` if present', () => { const initialQuery: ElasticsearchQuery['query'] = 'Some lucene query'; - reducerTester() + reducerTester() .givenReducer(queryReducer, initialQuery) .whenActionIsDispatched(initQuery()) .thenStateShouldEqual(initialQuery); @@ -17,7 +17,7 @@ describe('Query Reducer', () => { const initialQuery: ElasticsearchQuery['query'] = undefined; const expectedQuery = ''; - reducerTester() + reducerTester() .givenReducer(queryReducer, initialQuery) .whenActionIsDispatched(initQuery()) .thenStateShouldEqual(expectedQuery); @@ -27,7 +27,7 @@ describe('Query Reducer', () => { it('Should correctly set `query`', () => { const expectedQuery: ElasticsearchQuery['query'] = 'Some lucene query'; - reducerTester() + reducerTester() .givenReducer(queryReducer, '') .whenActionIsDispatched(changeQuery(expectedQuery)) .thenStateShouldEqual(expectedQuery); @@ -36,7 +36,7 @@ describe('Query Reducer', () => { it('Should not change state with other action types', () => { const initialState: ElasticsearchQuery['query'] = 'Some lucene query'; - reducerTester() + reducerTester() .givenReducer(queryReducer, initialState) .whenActionIsDispatched({ type: 'THIS ACTION SHOULD NOT HAVE ANY EFFECT IN THIS REDUCER' }) .thenStateShouldEqual(initialState); @@ -47,7 +47,7 @@ describe('Alias Pattern Reducer', () => { it('Should correctly set `alias`', () => { const expectedAlias: ElasticsearchQuery['alias'] = 'Some alias pattern'; - reducerTester() + reducerTester() .givenReducer(aliasPatternReducer, '') .whenActionIsDispatched(changeAliasPattern(expectedAlias)) .thenStateShouldEqual(expectedAlias); @@ -56,7 +56,7 @@ describe('Alias Pattern Reducer', () => { it('Should not change state with other action types', () => { const initialState: ElasticsearchQuery['alias'] = 'Some alias pattern'; - reducerTester() + reducerTester() .givenReducer(aliasPatternReducer, initialState) .whenActionIsDispatched({ type: 'THIS ACTION SHOULD NOT HAVE ANY EFFECT IN THIS REDUCER' }) .thenStateShouldEqual(initialState); diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts index fe98c6dab68..23dc1a772e1 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts @@ -102,14 +102,13 @@ describe('AzureMonitorDatasource', () => { datasourceRequestMock.mockImplementation(() => Promise.resolve(response)); }); - it('should return a list of subscriptions', () => { - return ctx.ds.metricFindQuery('subscriptions()').then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toBe(2); - expect(results[0].text).toBe('Primary'); - expect(results[0].value).toBe('sub1'); - expect(results[1].text).toBe('Secondary'); - expect(results[1].value).toBe('sub2'); - }); + it('should return a list of subscriptions', async () => { + const results = await ctx.ds.metricFindQuery('subscriptions()'); + expect(results.length).toBe(2); + expect(results[0].text).toBe('Primary'); + expect(results[0].value).toBe('sub1'); + expect(results[1].text).toBe('Secondary'); + expect(results[1].value).toBe('sub2'); }); }); @@ -126,14 +125,13 @@ describe('AzureMonitorDatasource', () => { datasourceRequestMock.mockImplementation(() => Promise.resolve(response)); }); - it('should return a list of resource groups', () => { - return ctx.ds.metricFindQuery('ResourceGroups()').then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toBe(2); - expect(results[0].text).toBe('grp1'); - expect(results[0].value).toBe('grp1'); - expect(results[1].text).toBe('grp2'); - expect(results[1].value).toBe('grp2'); - }); + it('should return a list of resource groups', async () => { + const results = await ctx.ds.metricFindQuery('ResourceGroups()'); + expect(results.length).toBe(2); + expect(results[0].text).toBe('grp1'); + expect(results[0].value).toBe('grp1'); + expect(results[1].text).toBe('grp2'); + expect(results[1].value).toBe('grp2'); }); }); @@ -153,16 +151,13 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of resource groups', () => { - return ctx.ds - .metricFindQuery('ResourceGroups(11112222-eeee-4949-9b2d-9106972f9123)') - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toBe(2); - expect(results[0].text).toBe('grp1'); - expect(results[0].value).toBe('grp1'); - expect(results[1].text).toBe('grp2'); - expect(results[1].value).toBe('grp2'); - }); + it('should return a list of resource groups', async () => { + const results = await ctx.ds.metricFindQuery('ResourceGroups(11112222-eeee-4949-9b2d-9106972f9123)'); + expect(results.length).toBe(2); + expect(results[0].text).toBe('grp1'); + expect(results[0].value).toBe('grp1'); + expect(results[1].text).toBe('grp2'); + expect(results[1].value).toBe('grp2'); }); }); @@ -189,14 +184,11 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of namespaces', () => { - return ctx.ds - .metricFindQuery('Namespaces(nodesapp)') - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toEqual(1); - expect(results[0].text).toEqual('Microsoft.Network/networkInterfaces'); - expect(results[0].value).toEqual('Microsoft.Network/networkInterfaces'); - }); + it('should return a list of namespaces', async () => { + const results = await ctx.ds.metricFindQuery('Namespaces(nodesapp)'); + expect(results.length).toEqual(1); + expect(results[0].text).toEqual('Microsoft.Network/networkInterfaces'); + expect(results[0].value).toEqual('Microsoft.Network/networkInterfaces'); }); }); @@ -223,14 +215,11 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of namespaces', () => { - return ctx.ds - .metricFindQuery('namespaces(11112222-eeee-4949-9b2d-9106972f9123, nodesapp)') - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toEqual(1); - expect(results[0].text).toEqual('Microsoft.Network/networkInterfaces'); - expect(results[0].value).toEqual('Microsoft.Network/networkInterfaces'); - }); + it('should return a list of namespaces', async () => { + const results = await ctx.ds.metricFindQuery('namespaces(11112222-eeee-4949-9b2d-9106972f9123, nodesapp)'); + expect(results.length).toEqual(1); + expect(results[0].text).toEqual('Microsoft.Network/networkInterfaces'); + expect(results[0].value).toEqual('Microsoft.Network/networkInterfaces'); }); }); @@ -261,14 +250,11 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of resource names', () => { - return ctx.ds - .metricFindQuery('resourceNames(nodeapp, microsoft.insights/components )') - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toEqual(1); - expect(results[0].text).toEqual('nodeapp'); - expect(results[0].value).toEqual('nodeapp'); - }); + it('should return a list of resource names', async () => { + const results = await ctx.ds.metricFindQuery('resourceNames(nodeapp, microsoft.insights/components )'); + expect(results.length).toEqual(1); + expect(results[0].text).toEqual('nodeapp'); + expect(results[0].value).toEqual('nodeapp'); }); }); @@ -347,17 +333,16 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of metric names', () => { - return ctx.ds - .metricFindQuery('Metricnames(nodeapp, microsoft.insights/components, rn, default)') - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toEqual(2); - expect(results[0].text).toEqual('Percentage CPU'); - expect(results[0].value).toEqual('Percentage CPU'); + it('should return a list of metric names', async () => { + const results = await ctx.ds.metricFindQuery( + 'Metricnames(nodeapp, microsoft.insights/components, rn, default)' + ); + expect(results.length).toEqual(2); + expect(results[0].text).toEqual('Percentage CPU'); + expect(results[0].value).toEqual('Percentage CPU'); - expect(results[1].text).toEqual('Used capacity'); - expect(results[1].value).toEqual('UsedCapacity'); - }); + expect(results[1].text).toEqual('Used capacity'); + expect(results[1].value).toEqual('UsedCapacity'); }); }); @@ -396,19 +381,16 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of metric names', () => { - return ctx.ds - .metricFindQuery( - 'Metricnames(11112222-eeee-4949-9b2d-9106972f9123, nodeapp, microsoft.insights/components, rn, default)' - ) - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toEqual(2); - expect(results[0].text).toEqual('Percentage CPU'); - expect(results[0].value).toEqual('Percentage CPU'); + it('should return a list of metric names', async () => { + const results = await ctx.ds.metricFindQuery( + 'Metricnames(11112222-eeee-4949-9b2d-9106972f9123, nodeapp, microsoft.insights/components, rn, default)' + ); + expect(results.length).toEqual(2); + expect(results[0].text).toEqual('Percentage CPU'); + expect(results[0].value).toEqual('Percentage CPU'); - expect(results[1].text).toEqual('Used capacity'); - expect(results[1].value).toEqual('UsedCapacity'); - }); + expect(results[1].text).toEqual('Used capacity'); + expect(results[1].value).toEqual('UsedCapacity'); }); }); @@ -446,17 +428,14 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of metric names', () => { - return ctx.ds - .metricFindQuery('Metricnamespace(nodeapp, Microsoft.Compute/virtualMachines, rn)') - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toEqual(2); - expect(results[0].text).toEqual('Microsoft.Compute-virtualMachines'); - expect(results[0].value).toEqual('Microsoft.Compute/virtualMachines'); + it('should return a list of metric names', async () => { + const results = await ctx.ds.metricFindQuery('Metricnamespace(nodeapp, Microsoft.Compute/virtualMachines, rn)'); + expect(results.length).toEqual(2); + expect(results[0].text).toEqual('Microsoft.Compute-virtualMachines'); + expect(results[0].value).toEqual('Microsoft.Compute/virtualMachines'); - expect(results[1].text).toEqual('Telegraf-mem'); - expect(results[1].value).toEqual('Telegraf/mem'); - }); + expect(results[1].text).toEqual('Telegraf-mem'); + expect(results[1].value).toEqual('Telegraf/mem'); }); }); @@ -494,19 +473,16 @@ describe('AzureMonitorDatasource', () => { }); }); - it('should return a list of metric namespaces', () => { - return ctx.ds - .metricFindQuery( - 'Metricnamespace(11112222-eeee-4949-9b2d-9106972f9123, nodeapp, Microsoft.Compute/virtualMachines, rn)' - ) - .then((results: Array<{ text: string; value: string }>) => { - expect(results.length).toEqual(2); - expect(results[0].text).toEqual('Microsoft.Compute-virtualMachines'); - expect(results[0].value).toEqual('Microsoft.Compute/virtualMachines'); + it('should return a list of metric namespaces', async () => { + const results = await ctx.ds.metricFindQuery( + 'Metricnamespace(11112222-eeee-4949-9b2d-9106972f9123, nodeapp, Microsoft.Compute/virtualMachines, rn)' + ); + expect(results.length).toEqual(2); + expect(results[0].text).toEqual('Microsoft.Compute-virtualMachines'); + expect(results[0].value).toEqual('Microsoft.Compute/virtualMachines'); - expect(results[1].text).toEqual('Telegraf-mem'); - expect(results[1].value).toEqual('Telegraf/mem'); - }); + expect(results[1].text).toEqual('Telegraf-mem'); + expect(results[1].value).toEqual('Telegraf/mem'); }); }); }); diff --git a/public/test/core/redux/reducerTester.ts b/public/test/core/redux/reducerTester.ts index a64b6099565..728a4aa9869 100644 --- a/public/test/core/redux/reducerTester.ts +++ b/public/test/core/redux/reducerTester.ts @@ -1,10 +1,12 @@ -import { Reducer } from 'redux'; -import { PayloadAction, Action } from '@reduxjs/toolkit'; +import { Action } from 'redux'; +import { AnyAction } from '@reduxjs/toolkit'; import { cloneDeep } from 'lodash'; +type GrafanaReducer = (state: S, action: A) => S; + export interface Given { givenReducer: ( - reducer: Reducer | Action>, + reducer: GrafanaReducer, state: State, showDebugOutput?: boolean, disableDeepFreeze?: boolean @@ -12,13 +14,13 @@ export interface Given { } export interface When { - whenActionIsDispatched: (action: PayloadAction | Action) => Then; + whenActionIsDispatched: (action: AnyAction) => Then; } export interface Then { thenStateShouldEqual: (state: State) => When; thenStatePredicateShouldEqual: (predicate: (resultingState: State) => boolean) => When; - whenActionIsDispatched: (action: PayloadAction | Action) => Then; + whenActionIsDispatched: (action: AnyAction) => Then; } interface ObjectType extends Object { @@ -56,13 +58,13 @@ export const deepFreeze = (obj: T): T => { interface ReducerTester extends Given, When, Then {} export const reducerTester = (): Given => { - let reducerUnderTest: Reducer>; + let reducerUnderTest: GrafanaReducer; let resultingState: State; let initialState: State; let showDebugOutput = false; const givenReducer = ( - reducer: Reducer>, + reducer: GrafanaReducer, state: State, debug = false, disableDeepFreeze = false @@ -77,7 +79,7 @@ export const reducerTester = (): Given => { return instance; }; - const whenActionIsDispatched = (action: PayloadAction): Then => { + const whenActionIsDispatched = (action: AnyAction): Then => { resultingState = reducerUnderTest(resultingState || initialState, action); return instance; diff --git a/scripts/ci-check-strict.sh b/scripts/ci-check-strict.sh index bef8fc7bd9a..4c718787def 100755 --- a/scripts/ci-check-strict.sh +++ b/scripts/ci-check-strict.sh @@ -3,7 +3,7 @@ set -e echo -e "Collecting code stats (typescript errors & more)" -ERROR_COUNT_LIMIT=416 +ERROR_COUNT_LIMIT=340 ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strict true | grep -oP 'Found \K(\d+)')" if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then