-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Issues with the dedent string tag used for testing #1202
Comments
@Cito I think you right, only a handful of tests contains escape symbols so they can be changed to: dedent(String.raw `tes\t de\fault`) This form is more explicit and less confusing.
It's very easy to add tab support so I think it should be added even though this function only used in tests and they are indented only with spaces. |
Right, I would also prefer the And yes, adding tab support is probably as easy as changing the regex in the first line of Do you want me to create a PR that changes this behavior of dedent, i.e. returns the normal "cooked" string instead of the raw string and supports tabs as well? I would then also add a unit test for the |
I'm for it 👍 |
Ok. See PR #1203 for the discussed changes and unit tests. |
GraphQL.js has a ES6 string tag helper function under
jsutils/dedent
that removes indentation from strings so that the unit tests can look nicer.One undocumented side effect of the
dedent
function however confused me when reading some of the tests: The tag also adds escape sequences to the dedented string. Take for example this test:The output actually contains escape sequences, like
"tes\\t de\\fault"
, but the test looks likes as if it expects the output to be a non-escaped string.The reason for this is that the
dedent
tag accessesstring.raw
instead ofstring
.I'm not sure whether this is intended or not. If it is, then it should at least be documented in
jsutils/dedent
, because having such a side effect is not what you expect from a function called "dedent". It should also be documented that the function only looks at spaces, it does not dedent tab-based indentation.If you me know whether you prefer fixing the documentation or fixing the behavior, I can create a PR.
The text was updated successfully, but these errors were encountered: