Skip to content
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

feat: remove is-promise library #2080

Merged
merged 3 commits into from
Jan 2, 2024
Merged

Conversation

EshaanAgg
Copy link
Contributor

@EshaanAgg EshaanAgg commented Jan 2, 2024

Which problem is this PR solving?

Fixes #2074

Description of the changes

  • Removed the is-promise library
  • Added the type assertions wherever necessary
  • Removed the redundant tests
  • Made use of the native Promise.allSettled function (as described in a comment)

There seems to be an unrelated test in date.test.js that fails after these changes. I have fixed the test with what I think the intended testing was supposed to do. Would appreciate a review on the same!

How was this change tested?

  • Running the test suite locally

Checklist

@EshaanAgg EshaanAgg requested a review from a team as a code owner January 2, 2024 09:51
@EshaanAgg EshaanAgg requested review from jkowall and removed request for a team January 2, 2024 09:51
Copy link

codecov bot commented Jan 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cdd251b) 96.57% compared to head (8258c5c) 96.56%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2080      +/-   ##
==========================================
- Coverage   96.57%   96.56%   -0.02%     
==========================================
  Files         254      254              
  Lines        7626     7620       -6     
  Branches     1986     1986              
==========================================
- Hits         7365     7358       -7     
- Misses        261      262       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

it('@JAEGER_API/FETCH_TRACE should return the promise', () => {
const { payload } = jaegerApiActions.fetchTrace(id);
expect(isPromise(payload)).toBeTruthy();
});
Copy link
Member

Choose a reason for hiding this comment

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

Why are these tests removed? What is replacing them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are unnecessary tests. Each of these fetchXYZ functions is essentially createAction wrapper for different JSON files accessed via the get JSON function. Since the getJSON function returns a promise, the results of these calls are guaranteed to be PromiseLike. I removed these tests as they are essentially type-checking, which should be TypeScript's job.

Copy link
Member

Choose a reason for hiding this comment

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

they are essentially type-checking, which should be TypeScript's job.

how is that type-checking achieved given that the source file in question is not in TS, but JS?

Also

Each of these fetchXYZ functions is essentially createAction wrapper

That's an implementation detail of those functions, but the tests were enforcing the public API. Implementations may change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, my bad. I completely missed the .js extension. If we have to enforce the public API of these functions, then it would best to keep checking if we have a promise returned. I will revert the tests.

Comment on lines -178 to -192
describe('allSettled', () => {
it('validate responses', async () => {
const res = await jaegerApiActions.allSettled([
Promise.resolve(1),
// eslint-disable-next-line prefer-promise-reject-errors
Promise.reject(2),
Promise.resolve(3),
]);

expect(res).toEqual([
{ status: 'fulfilled', value: 1 },
{ status: 'rejected', reason: 2 },
{ status: 'fulfilled', value: 3 },
]);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this test as we have now deprecated the custom implementation of allSettled for the builtin Promise.allSettled.

Signed-off-by: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com>
Signed-off-by: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com>
Signed-off-by: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com>
@EshaanAgg
Copy link
Contributor Author

EshaanAgg commented Jan 2, 2024

I have reverted the tests testing the public API and removed the is-promise library in favor of a simple custom implementation that checks the supplied object must be PromiseLike, that is, have a then and catch function. I have removed the analogous tests for the readJsonFile function as the file is in TS, and we can use explicit return type assertions to ensure the same.

@yurishkuro
Copy link
Member

Have you considered converting packages/jaeger-ui/src/actions/jaeger-api.js to Typescript?

@EshaanAgg
Copy link
Contributor Author

I tried to do so but later decided to avoid doing it for two reasons:

  • We would have to go back to our custom implementation of allSettled
    When changing the file to TS and using allSettled, we get the following TS error, asking us to increase the compiler to a more later one. Do you think this can lead to breaking changes?
Property 'allSettled' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. ts(2550)
  • Loose types
    Even after flipping to TS, due to the nature of the redux-actions library, we get not very concrete types like the following:
const fetchAllServiceMetrics: ActionFunction<Action<any>, undefined, undefined, undefined, undefined>
const fetchDeepDependencyGraph: ActionFunctionAny<ActionMeta<any, {
    query: any;
}>>
const fetchServices: ActionFunction<Action<any>, undefined, undefined, undefined, undefined>

I don't think these types enforce the PromiseLike interface that you had earlier mentioned, thus making the exercise moot.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

Thanks!

@yurishkuro yurishkuro added the changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements label Jan 2, 2024
@yurishkuro yurishkuro merged commit 911ccf5 into jaegertracing:main Jan 2, 2024
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: remove the is-promise library
2 participants