Since v4 entered maintenance, do you think we can eliminate most of the 433 instances of indexOf from /test/*.js?
Note: The prefered alternative is assert.strictEqual(foo.includes(bar), true)
includes surrogate, or a real indexOf use:[ ] test.js (1 usage found)
[ ] init-hooks.js (2 usages found)
[ ] index.js (1 usage found)
[ ] test-sendfd.js (1 usage found)
[ ] test-doctool-html.js (3 usages found)
[ ] test-dns-any.js (1 usage found)
[ ] test-dns.js (1 usage found)
[ ] test-buffer-fakes.js (1 usage found)
[ ] test-tls-interleave.js (1 usage found)
[ ] test-dtrace-jsstack.js (3 usages found)
I have no strong opinions, +0.
(BTW, how about new ES6+ label for such issues and PRs?)
cc @nodejs/lts @nodejs/testing
(BTW, how about new ES6+ label for such issues and PRs?)
Since it's not a problem _with_ ES6, I think more like move-to-ES6+?
IMHO that should be done. Reasons: readability and [NaN].
Maybe a "good first contribution" or "code-and-lean" like #12376
Obviously doesn't make sense for the cases where you actually use the index, but otherwise SGTM.
@gibfahn see new desc
I'm not sure we should make these changes until v4 is officially no longer supported at all, just in case we make some improvements to tests and want to backport them.
BTW, v4 supports ''.includes() and ''.startsWith(), so maybe string cases can be addressed, if any.
@vsemozhetbyt I dunno, personally I'd rather just avoid it altogether (string or array) to avoid any confusion. startsWith() is fine though, since that's only available for strings and exists in v4.x.
+1 to what @mscdex said. Also I think .includes() is pretty fast but if we wait a bit longer it'l probably be on bar with .indexOf() with Ignition and TurboFan.
I'm not sure we should make these changes until v4 is officially no longer supported at all, just in case we make some improvements to tests and want to backport them.
From what I understand from what @MylesBorins wrote in https://github.com/nodejs/node/pull/12499#issuecomment-295839361, there will be __no__ backporting of __any__ improvements, just bug fixes. Those will probably come with new test-cases, that will need to be re-written to v4 anyway.
@refack I said improvements to tests, not feature additions to core that are backported. Sometimes tests themselves are refactored (e.g. what code and learn is doing now with adding common.mustCall() usage, replacing generic error checking, etc.) and those changes are backported.
@refack I said improvements to tests, not feature additions to core that are backported. Sometimes tests are refactored (e.g. what code and learn is doing now with adding
common.mustCall()usage, replacing generic error checking, etc.) and those changes are backported.
Since this is the first time a big version enters maintenance, I think you are raising an interesting issue that should be discussed in a wider context then this thread. spinning-off nodejs/LTS#203
@mscdex theoretically test improvements wouldn't be backported to maintenance branches:
Once a release moves into Maintenance mode, only critical bugs, critical security fixes, and documentation updates will be permitted.
Obviously in realistic terms some test changes may be backported, and how much that'll happen is actively being discussed in the LTS WG. However I don't think this change will be particularly disruptive as:
includes() will fail every time, so won't get into a v4.x release unnoticed.indexOf() for the includes())Also String .includes() already works in Node 4, it's just Array .includes() that doesn't, so instances of the former can definitely be replaced.
❯ node
> process.version
'v4.8.2'
> 'hi'.includes('h')
true
> ['h', 'i'].includes('h')
TypeError: ["h","i"].includes is not a function
If there are no objections could i do the swaps for all tests where "indexof" is being applied to strings?
@AbrahamFergie there already is #12604, but I'm not sure it's complete, or String exclusive.
If you want to help you could fetch the PR locally and see if it needs more work
I said improvements to tests, not feature additions to core that are backported. Sometimes tests themselves are refactored (e.g. what code and learn is doing now with adding common.mustCall() usage, replacing generic error checking, etc.) and those changes are backported.
@mscdex at the last LTS meeting it was agreed that those changes will continue to not be backported, so that shouldn't be an issue. (cc/ @nodejs/lts)
IMHO a good replacement for
assert.strictEqual(x.indexof(y), -1)
is
assert.strictEqual(x.includes(y), false)
It's more literal and I found it more readable.
Going to use to onboard people today - please update your PRs with the checklists.
Going to use to onboard people today - please update your PRs with the checklists.
I think we've converged on assert.strictEqual(foo.includes(bar), true);, Updating OP
Why assert.strictEqual instead of just assert?
Why assert.strictEqual instead of just assert?
Mostly for explicitness sake, but also:
assert.strictNotEqual(foo.indexOf(bar), -1)assert (and assert.ok) are not strictassert.strictEqual(foo.includes(bar), false)The fail message will be useless (only hint is the stacktrace) anyway 🤷♂️ at least until we add assert.includes
Sounds good to me
I'm working on this
Ill take the files under test\pummel
Hello @refack , could you please update a little bit the list? because I think that the current state is the following, but I would like your oppinion:
actually for the case in test/parallel/test-buffer-indexof I don't find anything to be replaced, should this issue be closed then?
cc @refack
This has already been backported to LTS, removing the label.
This is pretty outdated. We had all errors migrated and now there are a couple new files that contain indexOf that might be changed but it is likely that new ones will pop in if we do not have a eslint rule to prevent that.
I am closing this as resolved for now. If we get lots of those in, we can reopen the issue / create a new one.
Most helpful comment
I'm not sure we should make these changes until v4 is officially no longer supported at all, just in case we make some improvements to tests and want to backport them.