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

Upgrade query-string to v8.1.0 | Add Wrapper function for queryString.parse() #1794

Merged
merged 10 commits into from
Sep 16, 2023

Conversation

anshgoyalevil
Copy link
Member

Which problem is this PR solving?

Description of the changes

How was this change tested?

  • locally

Checklist

@@ -20,6 +20,7 @@ import prefixUrl from '../../utils/prefix-url';
import { MAX_LENGTH } from '../DeepDependencies/Graph/DdgNodeContent/constants';

import { SearchQuery } from '../../types/search';
import parseQuery from '../../utils/parseQuery.test';
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 we importing test module into prod module?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that way we won't have to worry about its code coverage. Changing it back to normal .ts file

return result;
}

parseQuery.wrapper = parseQuery;
Copy link
Member

Choose a reason for hiding this comment

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

what is the purpose of wrapper?

Copy link
Member Author

@anshgoyalevil anshgoyalevil Sep 15, 2023

Choose a reason for hiding this comment

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

This needed to be done because the way jest works is, it needs an object out of which it could spyOn the function.

So, something like jest.spyOn(func) won't work. Instead, it has to be jest.spyOn(obj.func) notation.

Thus, the wrapper thing is to make it work with jest. I tried the former approach also, without wrapper, but it didn't work with jest.

@codecov
Copy link

codecov bot commented Sep 15, 2023

@@ -51,6 +51,7 @@
"src/reducers/trace.js",
"src/selectors/dependencies.js",
"src/utils/configure-store.js",
"src/utils/parseQuery.ts",
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? Don't we pick up *ts files for linting automatically? If we don't it's a very sad state - linting should be on by default.

Copy link
Member Author

@anshgoyalevil anshgoyalevil Sep 15, 2023

Choose a reason for hiding this comment

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

Not actually. We aren't picking up *ts files automatically. We are doing it for *.tsx files.

Without this rule:
image

Copy link
Member

Choose a reason for hiding this comment

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

let's rename the file to tsx then, for now. I think we need to fix this separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member Author

Choose a reason for hiding this comment

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

Though, it can also be configured in tsconfig.json

{
    "extends": "../../tsconfig",
-   "include": ["src/**/*.tsx", "typings"]
+  "include": ["src/**/*.tsx", "src/**/*.ts", "typings"]
}

return result;
}

parseQuery.wrapper = parseQuery;
Copy link
Member

Choose a reason for hiding this comment

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

what is the point of this .wrapper? Can't we just export the function?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can export is without .wrapper also. But, then it won't work with jest.spyOn

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! Found a better workaround 🚀

Signed-off-by: Ansh Goyal <[email protected]>
Signed-off-by: Ansh Goyal <[email protected]>
[key: string]: string | null | (string | null)[];
}

function parseQuery(query: string, options?: ParseOptions): { [key: string]: string | string[] } {
Copy link
Member

@yurishkuro yurishkuro Sep 15, 2023

Choose a reason for hiding this comment

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

  1. can we throw in a unit test to maintain coverage?
  2. under what conditions does this return a plain array? An HTTP query string is fundamentally a dictionary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we can have a unit test for it. Adding it in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 🚀

@yurishkuro yurishkuro merged commit 2be7da6 into jaegertracing:main Sep 16, 2023
@anshgoyalevil anshgoyalevil deleted the qs-upgrade branch September 18, 2023 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants