Skip to content

Commit

Permalink
build: fix lints (apache#289)
Browse files Browse the repository at this point in the history
* build: remove no-test-callback override

* fix: no-callback auto-fix

* fix: lint issues import/extension
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 26, 2021
1 parent aabbb3d commit 6ae0511
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"private": true,
"scripts": {
"build": "yarn babel && yarn type:dts && yarn build:assets",
"build-one": "nimbus babel --clean",
"babel": "yarn babel:cjs && yarn babel:esm",
"babel:cjs": "nimbus babel --clean --workspaces=\"@superset-ui/!(demo|generator-superset)\"",
"babel:esm": "nimbus babel --clean --workspaces=\"@superset-ui/!(demo|generator-superset)\" --esm",
Expand Down Expand Up @@ -131,11 +130,9 @@
"rules": {
"import/no-extraneous-dependencies": "off",
"promise/param-names": "off",
"import/extensions": "off",
"jest/require-to-throw-message": "off",
"jest/no-test-return-statement": "off",
"jest/no-expect-resolves": "off",
"jest/no-test-callback": "off"
"jest/no-expect-resolves": "off"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,85 +79,99 @@ describe('ChartDataProvider', () => {
});

describe('ChartClient.loadDatasource', () => {
it('does not method if loadDatasource is false', done => {
expect.assertions(1);
setup({ loadDatasource: false });
setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(0);
done();
}, 0);
it('does not method if loadDatasource is false', () => {
return new Promise(done => {
expect.assertions(1);
setup({ loadDatasource: false });
setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(0);
done();
}, 0);
});
});

it('calls method on mount if loadDatasource is true', done => {
expect.assertions(2);
setup({ loadDatasource: true });
setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(1);
expect(mockLoadDatasource.mock.calls[0][0]).toEqual(props.formData!.datasource);
done();
}, 0);
it('calls method on mount if loadDatasource is true', () => {
return new Promise(done => {
expect.assertions(2);
setup({ loadDatasource: true });
setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(1);
expect(mockLoadDatasource.mock.calls[0][0]).toEqual(props.formData!.datasource);
done();
}, 0);
});
});

it('should pass datasourceRequestOptions to ChartClient.loadDatasource', done => {
expect.assertions(2);
const options = { host: 'override' };
setup({ loadDatasource: true, datasourceRequestOptions: options });
setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(1);
expect(mockLoadDatasource.mock.calls[0][1]).toEqual(options);
done();
}, 0);
it('should pass datasourceRequestOptions to ChartClient.loadDatasource', () => {
return new Promise(done => {
expect.assertions(2);
const options = { host: 'override' };
setup({ loadDatasource: true, datasourceRequestOptions: options });
setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(1);
expect(mockLoadDatasource.mock.calls[0][1]).toEqual(options);
done();
}, 0);
});
});

it('calls ChartClient.loadDatasource if loadDatasource is true and formData or sliceId change', done => {
expect.assertions(3);
const newDatasource = 'test';
const wrapper = setup({ loadDatasource: true });
wrapper.setProps({ formData: { datasource: newDatasource }, sliceId: undefined });

setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(2);
expect(mockLoadDatasource.mock.calls[0][0]).toEqual(props.formData!.datasource);
expect(mockLoadDatasource.mock.calls[1][0]).toEqual(newDatasource);
done();
}, 0);
it('calls ChartClient.loadDatasource if loadDatasource is true and formData or sliceId change', () => {
return new Promise(done => {
expect.assertions(3);
const newDatasource = 'test';
const wrapper = setup({ loadDatasource: true });
wrapper.setProps({ formData: { datasource: newDatasource }, sliceId: undefined });

setTimeout(() => {
expect(mockLoadDatasource.mock.calls).toHaveLength(2);
expect(mockLoadDatasource.mock.calls[0][0]).toEqual(props.formData!.datasource);
expect(mockLoadDatasource.mock.calls[1][0]).toEqual(newDatasource);
done();
}, 0);
});
});
});

describe('ChartClient.loadQueryData', () => {
it('calls method on mount', done => {
expect.assertions(2);
setup();
setTimeout(() => {
expect(mockLoadQueryData.mock.calls).toHaveLength(1);
expect(mockLoadQueryData.mock.calls[0][0]).toEqual(props.formData);
done();
}, 0);
it('calls method on mount', () => {
return new Promise(done => {
expect.assertions(2);
setup();
setTimeout(() => {
expect(mockLoadQueryData.mock.calls).toHaveLength(1);
expect(mockLoadQueryData.mock.calls[0][0]).toEqual(props.formData);
done();
}, 0);
});
});

it('should pass queryDataRequestOptions to ChartClient.loadQueryData', done => {
expect.assertions(2);
const options = { host: 'override' };
setup({ queryRequestOptions: options });
setTimeout(() => {
expect(mockLoadQueryData.mock.calls).toHaveLength(1);
expect(mockLoadQueryData.mock.calls[0][1]).toEqual(options);
done();
}, 0);
it('should pass queryDataRequestOptions to ChartClient.loadQueryData', () => {
return new Promise(done => {
expect.assertions(2);
const options = { host: 'override' };
setup({ queryRequestOptions: options });
setTimeout(() => {
expect(mockLoadQueryData.mock.calls).toHaveLength(1);
expect(mockLoadQueryData.mock.calls[0][1]).toEqual(options);
done();
}, 0);
});
});

it('calls ChartClient.loadQueryData when formData or sliceId change', done => {
expect.assertions(3);
const newFormData = { key: 'test' };
const wrapper = setup();
wrapper.setProps({ formData: newFormData, sliceId: undefined });

setTimeout(() => {
expect(mockLoadQueryData.mock.calls).toHaveLength(2);
expect(mockLoadQueryData.mock.calls[0][0]).toEqual(props.formData);
expect(mockLoadQueryData.mock.calls[1][0]).toEqual(newFormData);
done();
}, 0);
it('calls ChartClient.loadQueryData when formData or sliceId change', () => {
return new Promise(done => {
expect.assertions(3);
const newFormData = { key: 'test' };
const wrapper = setup();
wrapper.setProps({ formData: newFormData, sliceId: undefined });

setTimeout(() => {
expect(mockLoadQueryData.mock.calls).toHaveLength(2);
expect(mockLoadQueryData.mock.calls[0][0]).toEqual(props.formData);
expect(mockLoadQueryData.mock.calls[1][0]).toEqual(newFormData);
done();
}, 0);
});
});
});

Expand All @@ -171,100 +185,112 @@ describe('ChartDataProvider', () => {
expect(children.mock.calls[0][0]).toEqual({ loading: true });
});

it('calls children({ payload }) when loaded', done => {
expect.assertions(2);
const children = jest.fn();
setup({ children, loadDatasource: true });

setTimeout(() => {
expect(children.mock.calls).toHaveLength(2);
expect(children.mock.calls[1][0]).toEqual({
payload: {
formData: props.formData,
datasource: props.formData!.datasource,
queryData: props.formData,
},
});
done();
}, 0);
it('calls children({ payload }) when loaded', () => {
return new Promise(done => {
expect.assertions(2);
const children = jest.fn();
setup({ children, loadDatasource: true });

setTimeout(() => {
expect(children.mock.calls).toHaveLength(2);
expect(children.mock.calls[1][0]).toEqual({
payload: {
formData: props.formData,
datasource: props.formData!.datasource,
queryData: props.formData,
},
});
done();
}, 0);
});
});

it('calls children({ error }) upon request error', done => {
expect.assertions(2);
const children = jest.fn();
mockLoadFormData = jest.fn(() => Promise.reject(new Error('error')));
it('calls children({ error }) upon request error', () => {
return new Promise(done => {
expect.assertions(2);
const children = jest.fn();
mockLoadFormData = jest.fn(() => Promise.reject(new Error('error')));

setup({ children });
setup({ children });

setTimeout(() => {
expect(children.mock.calls).toHaveLength(2); // loading + error
expect(children.mock.calls[1][0]).toEqual({ error: new Error('error') });
done();
}, 0);
setTimeout(() => {
expect(children.mock.calls).toHaveLength(2); // loading + error
expect(children.mock.calls[1][0]).toEqual({ error: new Error('error') });
done();
}, 0);
});
});

it('calls children({ error }) upon JS error', done => {
expect.assertions(2);
const children = jest.fn();
it('calls children({ error }) upon JS error', () => {
return new Promise(done => {
expect.assertions(2);
const children = jest.fn();

mockLoadFormData = jest.fn(() => {
throw new Error('non-async error');
});
mockLoadFormData = jest.fn(() => {
throw new Error('non-async error');
});

setup({ children });
setup({ children });

setTimeout(() => {
expect(children.mock.calls).toHaveLength(2); // loading + error
expect(children.mock.calls[1][0]).toEqual({ error: new Error('non-async error') });
done();
}, 0);
setTimeout(() => {
expect(children.mock.calls).toHaveLength(2); // loading + error
expect(children.mock.calls[1][0]).toEqual({ error: new Error('non-async error') });
done();
}, 0);
});
});
});

describe('callbacks', () => {
it('calls onLoad(payload) when loaded', done => {
expect.assertions(2);
const onLoaded = jest.fn();
setup({ onLoaded, loadDatasource: true });

setTimeout(() => {
expect(onLoaded.mock.calls).toHaveLength(1);
expect(onLoaded.mock.calls[0][0]).toEqual({
formData: props.formData,
datasource: props.formData!.datasource,
queryData: props.formData,
});
done();
}, 0);
it('calls onLoad(payload) when loaded', () => {
return new Promise(done => {
expect.assertions(2);
const onLoaded = jest.fn();
setup({ onLoaded, loadDatasource: true });

setTimeout(() => {
expect(onLoaded.mock.calls).toHaveLength(1);
expect(onLoaded.mock.calls[0][0]).toEqual({
formData: props.formData,
datasource: props.formData!.datasource,
queryData: props.formData,
});
done();
}, 0);
});
});

it('calls onError(error) upon request error', done => {
expect.assertions(2);
const onError = jest.fn();
mockLoadFormData = jest.fn(() => Promise.reject(new Error('error')));

setup({ onError });
setTimeout(() => {
expect(onError.mock.calls).toHaveLength(1);
expect(onError.mock.calls[0][0]).toEqual(new Error('error'));
done();
}, 0);
it('calls onError(error) upon request error', () => {
return new Promise(done => {
expect.assertions(2);
const onError = jest.fn();
mockLoadFormData = jest.fn(() => Promise.reject(new Error('error')));

setup({ onError });
setTimeout(() => {
expect(onError.mock.calls).toHaveLength(1);
expect(onError.mock.calls[0][0]).toEqual(new Error('error'));
done();
}, 0);
});
});

it('calls onError(error) upon JS error', done => {
expect.assertions(2);
const onError = jest.fn();
it('calls onError(error) upon JS error', () => {
return new Promise(done => {
expect.assertions(2);
const onError = jest.fn();

mockLoadFormData = jest.fn(() => {
throw new Error('non-async error');
});
mockLoadFormData = jest.fn(() => {
throw new Error('non-async error');
});

setup({ onError });
setTimeout(() => {
expect(onError.mock.calls).toHaveLength(1);
expect(onError.mock.calls[0][0]).toEqual(new Error('non-async error'));
done();
}, 0);
setup({ onError });
setTimeout(() => {
expect(onError.mock.calls).toHaveLength(1);
expect(onError.mock.calls[0][0]).toEqual(new Error('non-async error'));
done();
}, 0);
});
});
});
});
Loading

0 comments on commit 6ae0511

Please sign in to comment.