chore: add type checking in package tests directory (#19320)
This commit is contained in:
parent
54c521ba77
commit
b0397beb8e
|
|
@ -28,6 +28,7 @@ const ADHOC_COLUMN: AdhocColumn = {
|
|||
hasCustomLabel: true,
|
||||
label: 'Adhoc column',
|
||||
sqlExpression: 'case when 1 = 1 then 1 else 2 end',
|
||||
expressionType: 'SQL',
|
||||
};
|
||||
const COLUMN_META: ColumnMeta = {
|
||||
column_name: 'my_col',
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@
|
|||
"@types/math-expression-evaluator": "^1.2.1",
|
||||
"@types/rison": "0.0.6",
|
||||
"@types/seedrandom": "^2.4.28",
|
||||
"@types/tinycolor2": "^1.4.3",
|
||||
"@types/fetch-mock": "^7.3.3",
|
||||
"@types/enzyme": "^3.10.5",
|
||||
"@types/prop-types": "^15.7.2",
|
||||
|
|
@ -71,6 +70,8 @@
|
|||
"@emotion/styled": "^11.3.0",
|
||||
"@types/react": "*",
|
||||
"@types/react-loadable": "*",
|
||||
"@types/tinycolor2": "*",
|
||||
"tinycolor2": "*",
|
||||
"react": "^16.13.1",
|
||||
"react-loadable": "^5.5.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ export type QueryFormColumn = PhysicalColumn | AdhocColumn;
|
|||
* Order query results by columns.
|
||||
* Format: [metric/column, is_ascending].
|
||||
*/
|
||||
export type QueryFormOrderBy = [QueryFormColumn | QueryFormMetric, boolean];
|
||||
export type QueryFormOrderBy =
|
||||
| [QueryFormColumn | QueryFormMetric | {}, boolean]
|
||||
| [];
|
||||
|
||||
export interface FormDataResidual {
|
||||
[key: string]: any;
|
||||
|
|
@ -201,7 +203,7 @@ export interface SqlaFormData extends BaseFormData {
|
|||
* Form data for Druid datasources.
|
||||
*/
|
||||
export interface DruidFormData extends BaseFormData {
|
||||
granularity: string;
|
||||
granularity?: string;
|
||||
having_druid?: string;
|
||||
druid_time_origin?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ describe('ChartDataProvider', () => {
|
|||
setup({ loadDatasource: false });
|
||||
setTimeout(() => {
|
||||
expect(mockLoadDatasource.mock.calls).toHaveLength(0);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ describe('ChartDataProvider', () => {
|
|||
expect(mockLoadDatasource.mock.calls[0][0]).toEqual(
|
||||
props.formData.datasource,
|
||||
);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ describe('ChartDataProvider', () => {
|
|||
setTimeout(() => {
|
||||
expect(mockLoadDatasource.mock.calls).toHaveLength(1);
|
||||
expect(mockLoadDatasource.mock.calls[0][1]).toEqual(options);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ describe('ChartDataProvider', () => {
|
|||
props.formData.datasource,
|
||||
);
|
||||
expect(mockLoadDatasource.mock.calls[1][0]).toEqual(newDatasource);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
|
@ -177,7 +177,7 @@ describe('ChartDataProvider', () => {
|
|||
setTimeout(() => {
|
||||
expect(mockLoadQueryData.mock.calls).toHaveLength(1);
|
||||
expect(mockLoadQueryData.mock.calls[0][0]).toEqual(props.formData);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ describe('ChartDataProvider', () => {
|
|||
setTimeout(() => {
|
||||
expect(mockLoadQueryData.mock.calls).toHaveLength(1);
|
||||
expect(mockLoadQueryData.mock.calls[0][1]).toEqual(options);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ describe('ChartDataProvider', () => {
|
|||
expect(mockLoadQueryData.mock.calls).toHaveLength(2);
|
||||
expect(mockLoadQueryData.mock.calls[0][0]).toEqual(props.formData);
|
||||
expect(mockLoadQueryData.mock.calls[1][0]).toEqual(newFormData);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
|
@ -234,7 +234,7 @@ describe('ChartDataProvider', () => {
|
|||
queriesData: [props.formData],
|
||||
},
|
||||
});
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ describe('ChartDataProvider', () => {
|
|||
expect(children.mock.calls[1][0]).toEqual({
|
||||
error: new Error('error'),
|
||||
});
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -271,7 +271,7 @@ describe('ChartDataProvider', () => {
|
|||
expect(children.mock.calls[1][0]).toEqual({
|
||||
error: new Error('non-async error'),
|
||||
});
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
|
@ -290,7 +290,7 @@ describe('ChartDataProvider', () => {
|
|||
datasource: props.formData.datasource,
|
||||
queriesData: [props.formData],
|
||||
});
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -304,7 +304,7 @@ describe('ChartDataProvider', () => {
|
|||
setTimeout(() => {
|
||||
expect(onError.mock.calls).toHaveLength(1);
|
||||
expect(onError.mock.calls[0][0]).toEqual(new Error('error'));
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
|
||||
|
|
@ -323,7 +323,7 @@ describe('ChartDataProvider', () => {
|
|||
expect(onError.mock.calls[0][0]).toEqual(
|
||||
new Error('non-async error'),
|
||||
);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ describe('createLoadableRenderer', () => {
|
|||
expect(render).not.toHaveBeenCalled();
|
||||
expect(onRenderSuccess).not.toHaveBeenCalled();
|
||||
expect(onRenderFailure).toHaveBeenCalledTimes(1);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 10);
|
||||
}));
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ describe('createLoadableRenderer', () => {
|
|||
expect(loadChartFailure).toHaveBeenCalledTimes(1);
|
||||
setTimeout(() => {
|
||||
expect(render).not.toHaveBeenCalled();
|
||||
done();
|
||||
done(undefined);
|
||||
}, 10);
|
||||
}));
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ describe('createLoadableRenderer', () => {
|
|||
setTimeout(() => {
|
||||
// but rendered after the component is loaded.
|
||||
expect(wrapper.find(TestComponent)).toHaveLength(1);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 10);
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ describe('reactify(renderFn)', () => {
|
|||
expect(renderFn).toHaveBeenCalledTimes(2);
|
||||
expect(wrapper.html()).toEqual('<div id="test"><b>def</b></div>');
|
||||
wrapper.unmount();
|
||||
done();
|
||||
done(undefined);
|
||||
}, 20);
|
||||
}));
|
||||
describe('displayName', () => {
|
||||
|
|
@ -140,7 +140,7 @@ describe('reactify(renderFn)', () => {
|
|||
setTimeout(() => {
|
||||
wrapper.unmount();
|
||||
expect(willUnmountCb).toHaveBeenCalledTimes(1);
|
||||
done();
|
||||
done(undefined);
|
||||
}, 20);
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ describe('callApi()', () => {
|
|||
|
||||
await callApi(mockRequest);
|
||||
const calls = fetchMock.calls(mockGetUrl);
|
||||
const fetchParams = calls[0][1];
|
||||
const fetchParams = calls[0][1] as RequestInit;
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(fetchParams.mode).toBe(mockRequest.mode);
|
||||
expect(fetchParams.cache).toBe(mockRequest.cache);
|
||||
|
|
@ -118,7 +118,7 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPostUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
|
||||
const fetchParams = calls[0][1];
|
||||
const fetchParams = calls[0][1] as RequestInit;
|
||||
const body = fetchParams.body as FormData;
|
||||
|
||||
Object.entries(postPayload).forEach(([key, value]) => {
|
||||
|
|
@ -135,7 +135,7 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPostUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
|
||||
const fetchParams = calls[0][1];
|
||||
const fetchParams = calls[0][1] as RequestInit;
|
||||
const body = fetchParams.body as FormData;
|
||||
expect(body.get('key')).toBe(JSON.stringify(postPayload.key));
|
||||
expect(body.get('noValue')).toBeNull();
|
||||
|
|
@ -166,10 +166,10 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPostUrl);
|
||||
expect(calls).toHaveLength(3);
|
||||
|
||||
const stringified = calls[0][1].body as FormData;
|
||||
const unstringified = calls[1][1].body as FormData;
|
||||
const stringified = (calls[0][1] as RequestInit).body as FormData;
|
||||
const unstringified = (calls[1][1] as RequestInit).body as FormData;
|
||||
const jsonRequestBody = JSON.parse(
|
||||
calls[2][1].body as string,
|
||||
(calls[2][1] as RequestInit).body as string,
|
||||
) as JsonObject;
|
||||
|
||||
Object.entries(postPayload).forEach(([key, value]) => {
|
||||
|
|
@ -189,7 +189,7 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPutUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
|
||||
const fetchParams = calls[0][1];
|
||||
const fetchParams = calls[0][1] as RequestInit;
|
||||
const body = fetchParams.body as FormData;
|
||||
|
||||
Object.entries(postPayload).forEach(([key, value]) => {
|
||||
|
|
@ -206,7 +206,7 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPutUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
|
||||
const fetchParams = calls[0][1];
|
||||
const fetchParams = calls[0][1] as RequestInit;
|
||||
const body = fetchParams.body as FormData;
|
||||
expect(body.get('key')).toBe(JSON.stringify(postPayload.key));
|
||||
expect(body.get('noValue')).toBeNull();
|
||||
|
|
@ -236,8 +236,8 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPutUrl);
|
||||
expect(calls).toHaveLength(2);
|
||||
|
||||
const stringified = calls[0][1].body as FormData;
|
||||
const unstringified = calls[1][1].body as FormData;
|
||||
const stringified = (calls[0][1] as RequestInit).body as FormData;
|
||||
const unstringified = (calls[1][1] as RequestInit).body as FormData;
|
||||
|
||||
Object.entries(postPayload).forEach(([key, value]) => {
|
||||
expect(stringified.get(key)).toBe(JSON.stringify(value));
|
||||
|
|
@ -255,7 +255,7 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPatchUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
|
||||
const fetchParams = calls[0][1];
|
||||
const fetchParams = calls[0][1] as RequestInit;
|
||||
const body = fetchParams.body as FormData;
|
||||
|
||||
Object.entries(postPayload).forEach(([key, value]) => {
|
||||
|
|
@ -272,7 +272,7 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPatchUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
|
||||
const fetchParams = calls[0][1];
|
||||
const fetchParams = calls[0][1] as RequestInit;
|
||||
const body = fetchParams.body as FormData;
|
||||
expect(body.get('key')).toBe(JSON.stringify(postPayload.key));
|
||||
expect(body.get('noValue')).toBeNull();
|
||||
|
|
@ -302,8 +302,8 @@ describe('callApi()', () => {
|
|||
const calls = fetchMock.calls(mockPatchUrl);
|
||||
expect(calls).toHaveLength(2);
|
||||
|
||||
const stringified = calls[0][1].body as FormData;
|
||||
const unstringified = calls[1][1].body as FormData;
|
||||
const stringified = (calls[0][1] as RequestInit).body as FormData;
|
||||
const unstringified = (calls[1][1] as RequestInit).body as FormData;
|
||||
|
||||
Object.entries(postPayload).forEach(([key, value]) => {
|
||||
expect(stringified.get(key)).toBe(JSON.stringify(value));
|
||||
|
|
@ -366,7 +366,7 @@ describe('callApi()', () => {
|
|||
url: mockCacheUrl,
|
||||
method: 'GET',
|
||||
});
|
||||
const fetchParams = calls[1][1];
|
||||
const fetchParams = calls[1][1] as RequestInit;
|
||||
expect(calls).toHaveLength(2);
|
||||
// second call should not have If-None-Match header
|
||||
expect(fetchParams.headers).toBeUndefined();
|
||||
|
|
@ -386,7 +386,7 @@ describe('callApi()', () => {
|
|||
|
||||
// second call sends the Etag in the If-None-Match header
|
||||
await callApi({ url: mockCacheUrl, method: 'GET' });
|
||||
const fetchParams = calls[1][1];
|
||||
const fetchParams = calls[1][1] as RequestInit;
|
||||
const headers = { 'If-None-Match': 'etag' };
|
||||
expect(calls).toHaveLength(2);
|
||||
expect(fetchParams.headers).toEqual(
|
||||
|
|
@ -591,7 +591,7 @@ describe('callApi()', () => {
|
|||
method: 'POST',
|
||||
postPayload: payload,
|
||||
});
|
||||
expect(fetchMock.lastOptions().body).toBe(payload);
|
||||
expect(fetchMock.lastOptions()?.body).toBe(payload);
|
||||
});
|
||||
|
||||
it('should ignore "null" postPayload string', async () => {
|
||||
|
|
@ -602,6 +602,6 @@ describe('callApi()', () => {
|
|||
method: 'POST',
|
||||
postPayload: 'null',
|
||||
});
|
||||
expect(fetchMock.lastOptions().body).toBeUndefined();
|
||||
expect(fetchMock.lastOptions()?.body).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ describe('makeApi()', () => {
|
|||
|
||||
const expected = new FormData();
|
||||
expected.append('request', JSON.stringify('test'));
|
||||
const received = fetchMock.lastOptions().body as FormData;
|
||||
const received = fetchMock.lastOptions()?.body as FormData;
|
||||
|
||||
expect(received).toBeInstanceOf(FormData);
|
||||
expect(received.get('request')).toEqual(expected.get('request'));
|
||||
|
|
|
|||
|
|
@ -227,6 +227,7 @@ describe('buildQueryObject', () => {
|
|||
name: 'My Formula',
|
||||
opacity: AnnotationOpacity.Low,
|
||||
show: true,
|
||||
showLabel: false,
|
||||
style: AnnotationStyle.Solid,
|
||||
value: '10*sin(x)',
|
||||
width: 1,
|
||||
|
|
@ -235,6 +236,7 @@ describe('buildQueryObject', () => {
|
|||
annotationType: AnnotationType.Interval,
|
||||
color: null,
|
||||
show: false,
|
||||
showLabel: false,
|
||||
name: 'My Interval',
|
||||
sourceType: AnnotationSourceType.Native,
|
||||
style: AnnotationStyle.Dashed,
|
||||
|
|
@ -253,6 +255,7 @@ describe('buildQueryObject', () => {
|
|||
},
|
||||
sourceType: AnnotationSourceType.Table,
|
||||
show: false,
|
||||
showLabel: false,
|
||||
timeColumn: 'ds',
|
||||
style: AnnotationStyle.Dashed,
|
||||
value: 1,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ describe('getColumnLabel', () => {
|
|||
getColumnLabel({
|
||||
sqlExpression: "case when 1 then 'a' else 'b' end",
|
||||
label: 'my col',
|
||||
expressionType: 'SQL',
|
||||
}),
|
||||
).toEqual('my col');
|
||||
});
|
||||
|
|
@ -36,6 +37,7 @@ describe('getColumnLabel', () => {
|
|||
expect(
|
||||
getColumnLabel({
|
||||
sqlExpression: "case when 1 then 'a' else 'b' end",
|
||||
expressionType: 'SQL',
|
||||
}),
|
||||
).toEqual("case when 1 then 'a' else 'b' end");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ describe('normalizeOrderBy', () => {
|
|||
datasource: '5__table',
|
||||
viz_type: 'table',
|
||||
time_range: '1 year ago : 2013',
|
||||
// @ts-ignore
|
||||
orderby: [['count(*)', 'true']],
|
||||
};
|
||||
expect(normalizeOrderBy(query)).not.toHaveProperty('orderby');
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ describe('overrideExtraFormData', () => {
|
|||
time_grain_sqla: 'PT1H',
|
||||
},
|
||||
},
|
||||
{ time_grain_sqla: 'PT2H' },
|
||||
{ time_grain_sqla: 'P1D' },
|
||||
),
|
||||
).toEqual({
|
||||
granularity: 'something',
|
||||
|
|
@ -102,7 +102,7 @@ describe('overrideExtraFormData', () => {
|
|||
datasource: 'table_1',
|
||||
time_range: '100 years ago',
|
||||
extras: {
|
||||
time_grain_sqla: 'PT2H',
|
||||
time_grain_sqla: 'P1D',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ const CUM_RULE: PostProcessingCum = {
|
|||
options: {
|
||||
columns: ['foo'],
|
||||
operator: 'min',
|
||||
is_pivot_df: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -134,7 +133,6 @@ const RESAMPLE_RULE: PostProcessingResample = {
|
|||
method: 'method',
|
||||
rule: 'rule',
|
||||
fill_value: null,
|
||||
time_column: 'foo',
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -145,7 +143,6 @@ const ROLLING_RULE: PostProcessingRolling = {
|
|||
window: 12,
|
||||
min_periods: 12,
|
||||
columns: ['foo', 'bar'],
|
||||
is_pivot_df: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -62,12 +62,16 @@
|
|||
/* Completeness */
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": [
|
||||
"./packages/generator-superset/test/**/*"
|
||||
],
|
||||
"include": [
|
||||
"./src/**/*",
|
||||
"./spec/**/*",
|
||||
"./packages/*/src/**/*",
|
||||
"./packages/*/types/**/*",
|
||||
"./plugins/*/src/**/*",
|
||||
"./plugins/*/types/**/*"
|
||||
"./plugins/*/types/**/*",
|
||||
"./packages/*/test/**/*"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue