Skip to content

Commit 0063a53

Browse files
Nataly Shritsaddaleax
authored andcommitted
test: replace indexOf with includes and startsWith
PR-URL: nodejs#13852 Refs: nodejs#12586 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]>
1 parent fa65362 commit 0063a53

22 files changed

+40
-43
lines changed

test/addons/repl-domain-abort/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dInput._read = function _read(size) {
5454
};
5555

5656
dOutput._write = function _write(chunk, encoding, cb) {
57-
if (chunk.toString().indexOf('cb_ran') === 0)
57+
if (chunk.toString().startsWith('cb_ran'))
5858
cb_ran = true;
5959
cb();
6060
};

test/disabled/test-sendfd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pipeReadStream.on('data', function(data) {
9393
var rd = JSON.parse(d);
9494

9595
assert.strictEqual(rd.pid, cpp);
96-
assert.strictEqual(seenOrdinals.indexOf(rd.ord), -1);
96+
assert.strictEqual(seenOrdinals.includes(rd.ord), false)
9797

9898
seenOrdinals.unshift(rd.ord);
9999
});

test/doctool/test-doctool-html.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ testData.forEach((item) => {
117117
const actual = output.replace(spaces, '');
118118
// Assert that the input stripped of all whitespace contains the
119119
// expected list
120-
assert.notStrictEqual(actual.indexOf(expected), -1);
120+
assert(actual.includes(expected));
121121

122122
// Testing the insertion of Google Analytics script when
123123
// an analytics id is provided. Should not be present by default
124124
if (includeAnalytics) {
125-
assert.notStrictEqual(actual.indexOf('google-analytics.com'), -1,
126-
'Google Analytics script was not present');
125+
assert(actual.includes('google-analytics.com'),
126+
'Google Analytics script was not present');
127127
} else {
128-
assert.strictEqual(actual.indexOf('google-analytics.com'), -1,
128+
assert.strictEqual(actual.includes('google-analytics.com'), false,
129129
'Google Analytics script was present');
130130
}
131131
}));

test/internet/test-dns-any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const checkers = {
6060
assert.ok(Array.isArray(r.entries));
6161
assert.ok(r.entries.length > 0);
6262
r.entries.forEach((txt) => {
63-
assert.strictEqual(txt.indexOf('v=spf1'), 0);
63+
assert(txt.startsWith('v=spf1'));
6464
});
6565
assert.strictEqual(r.type, 'TXT');
6666
},

test/internet/test-dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ TEST(function test_resolveTxt(done) {
366366
assert.ifError(err);
367367
assert.strictEqual(records.length, 1);
368368
assert.ok(util.isArray(records[0]));
369-
assert.strictEqual(records[0][0].indexOf('v=spf1'), 0);
369+
assert(records[0][0].startsWith('v=spf1'));
370370
done();
371371
});
372372

test/parallel/test-buffer-write.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ encodings
3030
const len = Buffer.byteLength('foo', encoding);
3131
assert.strictEqual(buf.write('foo', 0, len, encoding), len);
3232

33-
if (encoding.indexOf('-') !== -1)
33+
if (encoding.includes('-'))
3434
encoding = encoding.replace('-', '');
3535

3636
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));

test/parallel/test-child-process-exec-cwd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ if (common.isWindows) {
3636

3737
exec(pwdcommand, {cwd: dir}, common.mustCall(function(err, stdout, stderr) {
3838
assert.ifError(err);
39-
assert.strictEqual(stdout.indexOf(dir), 0);
39+
assert(stdout.startsWith(dir));
4040
}));

test/parallel/test-console.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
137137
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
138138
strings.shift());
139139
assert.ok(strings.shift().includes('foo: [Object]'));
140-
assert.strictEqual(-1, strings.shift().indexOf('baz'));
140+
assert.strictEqual(strings.shift().includes('baz'), false);
141141
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
142142
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
143143
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim()));

test/parallel/test-dgram-error-message-address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ socket_ipv6.on('listening', common.mustNotCall());
4747
socket_ipv6.on('error', common.mustCall(function(e) {
4848
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
4949
const allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
50-
assert.notStrictEqual(allowed.indexOf(e.code), -1);
50+
assert(allowed.includes(e.code));
5151
assert.strictEqual(e.port, undefined);
5252
assert.strictEqual(e.message, `bind ${e.code} 111::1`);
5353
assert.strictEqual(e.address, '111::1');

test/parallel/test-domain-top-level-error-handler-throw.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ if (process.argv[2] === 'child') {
3737
});
3838

3939
child.on('close', function onChildClosed() {
40-
assert.notStrictEqual(
41-
stderrOutput.indexOf(domainErrHandlerExMessage),
42-
-1
43-
);
44-
assert.strictEqual(stderrOutput.indexOf(internalExMessage), -1);
40+
assert(stderrOutput.includes(domainErrHandlerExMessage));
41+
assert.strictEqual(stderrOutput.includes(internalExMessage), false);
4542
});
4643

4744
child.on('exit', function onChildExited(exitCode, signal) {

0 commit comments

Comments
 (0)