| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
CI: https://ci.nodejs.org/job/node-test-pull-request/8061/ |
Sorry, something went wrong.
There was a problem hiding this comment.
Rubber stamp LGTM. This definitely makes texts like HTTP messages easier to read..
Sorry, something went wrong.
There was a problem hiding this comment.
.trim()?
Sorry, something went wrong.
There was a problem hiding this comment.
On this stage, the replacing concerns the whole string, including interpolated variables, so I try to be extra careful here. i.e. to remove only two auxiliary spaces (which were framing line breaks before the reducing).
Sorry, something went wrong.
There was a problem hiding this comment.
If I am reading correctly strings[0].match(/\n+( +)/) should work as well?
Sorry, something went wrong.
There was a problem hiding this comment.
In case there are no indents — yes if I get it right, but maybe with * this returns earlier, without using the fallbacks || [] and = ''
Sorry, something went wrong.
There was a problem hiding this comment.
@joyeecheung would fail for (badly formated) literals like:
const tagged = tagLF`
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
${process.versions}
</body>
</html>
`;would give firstIndent === undefined
Sorry, something went wrong.
There was a problem hiding this comment.
Great idea 👍
soft suggestion I tagged with [suggestion]
And I'm only rubber stamping test/parallel/test-promises-unhandled-rejections.js
Sorry, something went wrong.
There was a problem hiding this comment.
IMHO looks better 👍
Sorry, something went wrong.
There was a problem hiding this comment.
Can you revert this file? it'll conflict with #13003
Sorry, something went wrong.
There was a problem hiding this comment.
OK.
Sorry, something went wrong.
There was a problem hiding this comment.
I'm rubber stamping this file...
IMHO you're mixing adding the new tags with refactoring.
(Could move to another PR or a different commit)
Sorry, something went wrong.
There was a problem hiding this comment.
I have only reformatted the first string arguments in each function, nothing more. GitHub diff just goes astray here, sorry.
Sorry, something went wrong.
There was a problem hiding this comment.
I'll take a look locally.
Sorry, something went wrong.
There was a problem hiding this comment.
why no indent?
Sorry, something went wrong.
There was a problem hiding this comment.
I will fix, thank you.
Sorry, something went wrong.
There was a problem hiding this comment.
I have recalled why: see the long line without a break in the previous variant, this is the only way to preserve it.
Sorry, something went wrong.
There was a problem hiding this comment.
[suggestion] I know you don't like to change too much, but I would go
const keepLF = '\n';
const fileName = path.join(common.tmpDir, '.node_repl_history');
const sameHistoryFilePaths = wrap`
${keepLF}
The old repl history file has the same name and location as the new one i.e.,
${fileName} and is empty.${keepLF}
Using it as is.${keepLF}
${keepLF}
`;maybe even add export.keepLF = '\n' to common
Sorry, something went wrong.
There was a problem hiding this comment.
I am afraid this would be complicated enough to scare out all other reviewers :)
Sorry, something went wrong.
There was a problem hiding this comment.
Next PR suggestion: A tag with JSON.stringify for j{} variables?
Sorry, something went wrong.
There was a problem hiding this comment.
Or with util.inspect() :)
Sorry, something went wrong.
There was a problem hiding this comment.
[suggestion] maybe even rename tagHTTP
Sorry, something went wrong.
There was a problem hiding this comment.
There were other cases in the tests. And potentially can be others (Windows stuff etc).
Sorry, something went wrong.
There was a problem hiding this comment.
[suggestion] for better readability:
console.error(exports.tagUnwrap`
Looks like we're in a FreeBSD Jail.
Please provide your default interface address as LOCALHOST
or expect some tests to fail.
`);
Sorry, something went wrong.
There was a problem hiding this comment.
move all consts out of the functions. no need to redefine on each invocation.
could be:
const TAG_CONSTANTS = {
tagGlueBreaks: /\n */g,
tagUnwrapBreaks: /(\n *)+/g,
tagUnwarpTrimmer: /^ | $/g,
...
Sorry, something went wrong.
There was a problem hiding this comment.
I would prefer to keep the functions self-sufficient for better modularity while they are not used in libs critical for performance.
Sorry, something went wrong.
There was a problem hiding this comment.
I won't block on this, but you might find out you can reuse some, or other coders might reuse, also gives them better names.
Sorry, something went wrong.
There was a problem hiding this comment.
I also remember that common module is considered too bloated, so I am afraid to pollute it with more global variables.
Sorry, something went wrong.
There was a problem hiding this comment.
@joyeecheung would fail for (badly formated) literals like:
const tagged = tagLF`
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
${process.versions}
</body>
</html>
`;would give firstIndent === undefined
Sorry, something went wrong.
There was a problem hiding this comment.
[Suggestion]
IMHO go stricter, i.e. new RegExp(\n {${firstIndent.length}}, 'g');
example:
const literlaHTML = tagLF`
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script>
var x = [1,2,3].map(functor, seed)
.filter(predicate)
.reduce(functor, '');
<script>
<title></title>
</head>
<body>
${process.versions}
</body>
</html>
`;
Sorry, something went wrong.
There was a problem hiding this comment.
I would prefer to ignore such misindentation cases in favor of these cases:
{
const tagged = tagLF`
<!doctype html>
<html>
...
</html>
`;
}NB: indentation before the last backtick is less than the first indentation. With your variant, it will be preserved with the trailing line break.
Sorry, something went wrong.
There was a problem hiding this comment.
BTW, these misindented fragments can be wrapped in ${''} and they will be untouched.
Sorry, something went wrong.
|
Read your comments 👍 on all but #13016 (comment), think again, but it's your call. |
Sorry, something went wrong.
|
I've added a bit more explanations in the doc (including intro note) and addressed some requests. CI: https://ci.nodejs.org/job/node-test-pull-request/8070/ |
Sorry, something went wrong.
Start to alleviate multiline template literals manipulations.
|
I've replaced tagLF and tagCRLF by the tagLFy and tagCRLFy to make them more verbal. |
Sorry, something went wrong.
|
@refack I mean https://en.oxforddictionaries.com/definition/-fy Does it make sense? |
Sorry, something went wrong.
I'm just making faces |
Sorry, something went wrong.
|
cc @nodejs/collaborators : this PR extends test common library and adds 4 new functions to many places of many tests. Does anybody object to landing? |
Sorry, something went wrong.
|
I am 👍 with the change, but 👎 on the amount of breakage that might introduce. I already had to backport a PR from master to v7 and soon v6, because of changes in the test harness. |
Sorry, something went wrong.
|
We keep adding more and more stuff to common.js and I honestly don't like this very much. It increases the cognitive load required to write tests. Tests should ideally only use an assertion library imho. That said, I have no objections to these changes. |
Sorry, something went wrong.
|
@mcollina It is a pity how the backporting burden prevents us from lightening other burdens, but it seems we should respect this burden as we respect gravitation. @lpinca I understand and I recall the recent attempts to slim down the common. But the help from these functions seems to surpass its cognitive load for me. However, this is too personal (I have been using some of them for a while), so I do not insist. It seems we have sound (yet soft) objections against the both commits: the fist makes common more bloated, the second brings too much churn. So if there is no strong "pro" from many collaborators I shall abstain to land. |
Sorry, something went wrong.
|
I'm in favor of this change, but only if it is backported asap to v6. Otherwise it creates too much churn. |
Sorry, something went wrong.
|
@mcollina I can do a backport PR for v6 after landing if this is not backported cleanly. How much asap this should be made? |
Sorry, something went wrong.
|
cc @nodejs/lts for that answer. |
Sorry, something went wrong.
@lpinca I agree that it is very important to lower the barrier (cognitive or other) for writing tests! But IMHO in this specific case the trade-off of cognitive load while writing code is cognitive load while reading/fixing code. There are good examples that definatly make the code much more readable, like here, and here @vsemozhetbyt will these tags benefit /benchmarks/? |
Sorry, something went wrong.
I have not checked yet, I just want to see if this can be accepted for tests. But I planned to try to apply for benchmarks as well. |
Sorry, something went wrong.
|
As for tradeoffs... For writing, the load is eased by optionality of using these functions. For reading, the load is increased by the "what the ... this tag*`` means" surprise effects :) |
Sorry, something went wrong.
|
@refack I'm a bit unconvinced by your second example. {
data: tagCRLFy`
POST / HTTP/1.0
Connection: keep-alive
`
}is actually harder for me to grok than {
data: 'POST / HTTP/1.0\r\n' +
'Connection: keep-alive\r\n' +
'\r\n'
}Anyway, to reiterate, I have nothing against these changes. I'm fine if this gets merged. |
Sorry, something went wrong.
fair enough... |
Sorry, something went wrong.
To follow up on #13016 (comment) IMHO since HTTP will probably be the main use case for this one, we could add (in following PR) a #{HTTP_SECTION_END} symbol. |
Sorry, something went wrong.
There was a problem hiding this comment.
I think I'm -1 on these changes for two reasons.
Sorry, something went wrong.
|
@vsemozhetbyt :] I definitely appreciate the effort put in |
Sorry, something went wrong.
|
A couple thoughts:
|
Sorry, something went wrong.
|
Well, it seems this is a too controversial proposition. So I better close for now to not distract more collaborators anymore. Thank you for all the feedback and time. I hope this was not completely in vain) |
Sorry, something went wrong.
|
IMHO the most controversial was tagGlue, but tagCRLFy (that should be named tagHTTPfy) and tagLFy have some very good uses. So maybe don't try to cover everything and focus on the really good ones:
|
Sorry, something went wrong.
|
@refack I shall ponder on this. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Checklist
Affected core subsystem(s)
test
Multiline template literals in ES6 make long strings handling easier in code. However, there are many annoying nits that prevent this option from using in many cases: code block indentation adds unwanted spaces to these strings, leading and trailing backticks break alignment or add unwanted leading and trailing line breaks.
This PR proposes 4 helper functions to mitigate these difficulties:
You can see examples in the proposed doc fragments.
This PR also demonstrates the applying these functions to many test fragments.
All these functions leave interpolated variables untouched, only literal parts are processed. In most cases, these functions get multiline strings with leading and trailing line breaks: this allows to divide code noise (backticks etc) and pure data. These leading and trailing line breaks are stripped by the tag functions. This should be taken into account: if the result needs a line break in the very end, an additional line break should be added (beware, for example, HTTP raw code — see samples in the second commit).
I understand that this is a big PR and mostly based on personal taste. So see it as a strawman and feel free to reject without thorough explanations.
Though the diff seems huge, the changes are mostly trivial, concern multiline blocks formatting and are easy to skim.