Skip to content

Commit 49e7866

Browse files
Nataly ShritsMylesBorins
authored andcommitted
test: replace indexOf with includes and startsWith
PR-URL: #13852 Refs: #12586 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
1 parent 2eb926b commit 49e7866

20 files changed

+39
-43
lines changed

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

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

3535
dOutput._write = function _write(chunk, encoding, cb) {
36-
if (chunk.toString().indexOf('cb_ran') === 0)
36+
if (chunk.toString().startsWith('cb_ran'))
3737
cb_ran = true;
3838
cb();
3939
};

test/disabled/test-sendfd.js

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

7676
assert.strictEqual(rd.pid, cpp);
77-
assert.strictEqual(seenOrdinals.indexOf(rd.ord), -1);
77+
assert.strictEqual(seenOrdinals.includes(rd.ord), false)
7878

7979
seenOrdinals.unshift(rd.ord);
8080
});

test/doctool/test-doctool-html.js

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

111111
// Testing the insertion of Google Analytics script when
112112
// an analytics id is provided. Should not be present by default
113113
if (includeAnalytics) {
114-
assert.notStrictEqual(actual.indexOf('google-analytics.com'), -1,
115-
'Google Analytics script was not present');
114+
assert(actual.includes('google-analytics.com'),
115+
'Google Analytics script was not present');
116116
} else {
117-
assert.strictEqual(actual.indexOf('google-analytics.com'), -1,
117+
assert.strictEqual(actual.includes('google-analytics.com'), false,
118118
'Google Analytics script was present');
119119
}
120120
}));

test/internet/test-dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ TEST(function test_resolveTxt(done) {
360360
if (err) throw err;
361361
assert.strictEqual(records.length, 1);
362362
assert.ok(util.isArray(records[0]));
363-
assert.strictEqual(records[0][0].indexOf('v=spf1'), 0);
363+
assert(records[0][0].startsWith('v=spf1'));
364364
done();
365365
});
366366

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

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

1616
exec(pwdcommand, {cwd: dir}, common.mustCall(function(err, stdout, stderr) {
1717
assert.ifError(err);
18-
assert.strictEqual(stdout.indexOf(dir), 0);
18+
assert(stdout.startsWith(dir));
1919
}));

test/parallel/test-console.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
115115
strings.shift());
116116
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
117117
strings.shift());
118-
assert.notStrictEqual(-1, strings.shift().indexOf('foo: [Object]'));
119-
assert.strictEqual(-1, strings.shift().indexOf('baz'));
118+
assert.ok(strings.shift().includes('foo: [Object]'));
119+
assert.strictEqual(strings.shift().includes('baz'), false);
120120
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
121121
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
122122
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
@@ -26,7 +26,7 @@ socket_ipv6.on('listening', common.mustNotCall());
2626
socket_ipv6.on('error', common.mustCall(function(e) {
2727
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
2828
const allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
29-
assert.notStrictEqual(allowed.indexOf(e.code), -1);
29+
assert(allowed.includes(e.code));
3030
assert.strictEqual(e.port, undefined);
3131
assert.strictEqual(e.message, `bind ${e.code} 111::1`);
3232
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) {

test/parallel/test-domain-uncaught-exception.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ if (process.argv[2] === 'child') {
190190

191191
if (test.messagesReceived) {
192192
test.messagesReceived.forEach(function(receivedMessage) {
193-
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
193+
if (!test.expectedMessages.includes(receivedMessage)) {
194194
assert(false, `test ${test.fn.name} should not have sent message: ${
195195
receivedMessage} but did`);
196196
}

test/parallel/test-http-keepalive-maxsockets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const http = require('http');
77

88
const serverSockets = [];
99
const server = http.createServer(function(req, res) {
10-
if (serverSockets.indexOf(req.socket) === -1) {
10+
if (!serverSockets.includes(req.socket)) {
1111
serverSockets.push(req.socket);
1212
}
1313
res.end(req.url);

0 commit comments

Comments
 (0)