Skip to content

refactor: cleanup test for api-client #4420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 4, 2022
Merged

Conversation

atomrc
Copy link
Contributor

@atomrc atomrc commented Oct 4, 2022

This removes the dependencies to webpack/karma related process that are slowing down quite a lot.
We need generate a pristine tsc compiled library that doesn't require building for a browser.

@atomrc atomrc marked this pull request as ready for review October 4, 2022 15:03
Comment on lines +284 to +287
jest.spyOn(client.api.auth, 'postLogout').mockReturnValue(Promise.reject(testError));
jest.spyOn(client, 'disconnect').mockReturnValue();
jest.spyOn(client['accessTokenStore'], 'delete').mockReturnValue(Promise.resolve(undefined));
jest.spyOn(client['logger'], 'warn').mockReturnValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe makes sense to destructure spyOn from jest just to have a few less characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't have strong opinion on this, I'd like to keep it this way. I don't think character count is a very useful metrics

Comment on lines +296 to +299
jest.spyOn(client.api.auth, 'postLogout');
jest.spyOn(client, 'disconnect').mockReturnValue();
jest.spyOn(client['accessTokenStore'], 'delete').mockReturnValue(Promise.resolve(undefined));
jest.spyOn(client['logger'], 'warn').mockReturnValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const websocketClient = new WebSocketClient('url', fakeHttpClient);
const onOpenSpy = spyOn<any>(websocketClient, 'onOpen').and.callThrough();
const websocketClient = new WebSocketClient('ws://url', fakeHttpClient);
const onOpenSpy = jest.spyOn(websocketClient as any, 'onOpen');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe destructuring makes sense in this file also since its called many times. also wondering about all these as any blocks if they can be improved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they sadly cannot be improved easily since the test is relying on mocking private methods :/
This would be too much of a hustle trying to fix this, so I'm restoring to the original behavior

@atomrc atomrc merged commit 90a7917 into main Oct 4, 2022
@atomrc atomrc deleted the refactor/cleanup-api-client branch October 4, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants