diff --git a/test/inspector/test-inspector.js b/test/inspector/test-inspector.js index 08c0938c87e832..ae4cfc65b20419 100644 --- a/test/inspector/test-inspector.js +++ b/test/inspector/test-inspector.js @@ -34,7 +34,7 @@ function checkBadPath(err, response) { function expectMainScriptSource(result) { const expected = helper.mainScriptSource(); const source = result['scriptSource']; - assert(source && (source.indexOf(expected) >= 0), + assert(source && (source.includes(expected)), 'Script source is wrong: ' + source); } diff --git a/test/parallel/test-child-process-default-options.js b/test/parallel/test-child-process-default-options.js index 37e7ea7494670e..8b5f469ea258d5 100644 --- a/test/parallel/test-child-process-default-options.js +++ b/test/parallel/test-child-process-default-options.js @@ -23,6 +23,6 @@ child.stdout.on('data', function(chunk) { }); process.on('exit', function() { - assert.ok(response.indexOf('HELLO=WORLD') >= 0, + assert.ok(response.includes('HELLO=WORLD'), 'spawn did not use process.env as default'); }); diff --git a/test/parallel/test-child-process-env.js b/test/parallel/test-child-process-env.js index ad41f978e21768..d780050e2b6012 100644 --- a/test/parallel/test-child-process-env.js +++ b/test/parallel/test-child-process-env.js @@ -29,6 +29,6 @@ child.stdout.on('data', function(chunk) { }); process.on('exit', function() { - assert.ok(response.indexOf('HELLO=WORLD') >= 0); - assert.ok(response.indexOf('FOO=BAR') >= 0); + assert.ok(response.includes('HELLO=WORLD')); + assert.ok(response.includes('FOO=BAR')); }); diff --git a/test/parallel/test-child-process-exec-env.js b/test/parallel/test-child-process-exec-env.js index 6af3bea2113a89..99fd2447ccc277 100644 --- a/test/parallel/test-child-process-exec-env.js +++ b/test/parallel/test-child-process-exec-env.js @@ -35,5 +35,5 @@ process.on('exit', function() { console.log('response: ', response); assert.strictEqual(1, success_count); assert.strictEqual(0, error_count); - assert.ok(response.indexOf('HELLO=WORLD') >= 0); + assert.ok(response.includes('HELLO=WORLD')); }); diff --git a/test/parallel/test-child-process-spawnsync-input.js b/test/parallel/test-child-process-spawnsync-input.js index 1bda3d5dcf9da2..5e1de1c616cc7b 100644 --- a/test/parallel/test-child-process-spawnsync-input.js +++ b/test/parallel/test-child-process-spawnsync-input.js @@ -31,7 +31,7 @@ function verifyBufOutput(ret) { assert.deepStrictEqual(ret.stderr, msgErrBuf); } -if (process.argv.indexOf('spawnchild') !== -1) { +if (process.argv.includes('spawnchild')) { switch (process.argv[3]) { case '1': ret = spawnSync(process.execPath, args, { stdio: 'inherit' }); diff --git a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js index d2de9b2a448cf9..cce6af84a22dde 100644 --- a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js +++ b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js @@ -17,7 +17,7 @@ const RAN_UNCAUGHT_EXCEPTION_HANDLER_EXIT_CODE = 42; if (process.argv[2] === 'child') { process.on('uncaughtException', common.mustCall(function onUncaught() { - if (process.execArgv.indexOf('--abort-on-uncaught-exception') !== -1) { + if (process.execArgv.includes('--abort-on-uncaught-exception')) { // When passing --abort-on-uncaught-exception to the child process, // we want to make sure that this handler (the process' uncaughtException // event handler) wasn't called. Unfortunately we can't parse the child diff --git a/test/parallel/test-domain-with-abort-on-uncaught-exception.js b/test/parallel/test-domain-with-abort-on-uncaught-exception.js index 0da8f1368f7c98..db530fbccb814b 100644 --- a/test/parallel/test-domain-with-abort-on-uncaught-exception.js +++ b/test/parallel/test-domain-with-abort-on-uncaught-exception.js @@ -43,11 +43,11 @@ if (process.argv[2] === 'child') { d.on('error', function(err) { // Swallowing the error on purpose if 'throwInDomainErrHandler' is not // set - if (process.argv.indexOf('throwInDomainErrHandler') !== -1) { + if (process.argv.includes('throwInDomainErrHandler')) { // If useTryCatch is set, wrap the throw in a try/catch block. // This is to make sure that a caught exception does not trigger // an abort. - if (process.argv.indexOf('useTryCatch') !== -1) { + if (process.argv.includes('useTryCatch')) { try { throw new Error(domainErrHandlerExMessage); } catch (e) { diff --git a/test/parallel/test-error-reporting.js b/test/parallel/test-error-reporting.js index fa7332a67a482b..8ab612b9be2641 100644 --- a/test/parallel/test-error-reporting.js +++ b/test/parallel/test-error-reporting.js @@ -15,7 +15,7 @@ function errExec(script, callback) { assert.ok(stderr.split('\n').length > 2); // Assert the script is mentioned in error output. - assert.ok(stderr.indexOf(script) >= 0); + assert.ok(stderr.includes(script)); // Proxy the args for more tests. callback(err, stdout, stderr); diff --git a/test/parallel/test-fs-error-messages.js b/test/parallel/test-fs-error-messages.js index f2ea85531bf463..0ed68ceb06fdbf 100644 --- a/test/parallel/test-fs-error-messages.js +++ b/test/parallel/test-fs-error-messages.js @@ -13,66 +13,66 @@ const existingDir2 = path.join(common.fixturesDir, 'keys'); fs.stat(fn, function(err) { assert.strictEqual(fn, err.path); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.lstat(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.readlink(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.link(fn, 'foo', function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.link(existingFile, existingFile2, function(err) { - assert.ok(0 <= err.message.indexOf(existingFile)); - assert.ok(0 <= err.message.indexOf(existingFile2)); + assert.ok(err.message.includes(existingFile)); + assert.ok(err.message.includes(existingFile2)); }); fs.symlink(existingFile, existingFile2, function(err) { - assert.ok(0 <= err.message.indexOf(existingFile)); - assert.ok(0 <= err.message.indexOf(existingFile2)); + assert.ok(err.message.includes(existingFile)); + assert.ok(err.message.includes(existingFile2)); }); fs.unlink(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.rename(fn, 'foo', function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.rename(existingDir, existingDir2, function(err) { - assert.ok(0 <= err.message.indexOf(existingDir)); - assert.ok(0 <= err.message.indexOf(existingDir2)); + assert.ok(err.message.includes(existingDir)); + assert.ok(err.message.includes(existingDir2)); }); fs.rmdir(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.mkdir(existingFile, 0o666, function(err) { - assert.ok(0 <= err.message.indexOf(existingFile)); + assert.ok(err.message.includes(existingFile)); }); fs.rmdir(existingFile, function(err) { - assert.ok(0 <= err.message.indexOf(existingFile)); + assert.ok(err.message.includes(existingFile)); }); fs.chmod(fn, 0o666, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.open(fn, 'r', 0o666, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); fs.readFile(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); }); // Sync @@ -85,7 +85,7 @@ try { fs.statSync(fn); } catch (err) { errors.push('stat'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -93,7 +93,7 @@ try { fs.mkdirSync(existingFile, 0o666); } catch (err) { errors.push('mkdir'); - assert.ok(0 <= err.message.indexOf(existingFile)); + assert.ok(err.message.includes(existingFile)); } try { @@ -101,7 +101,7 @@ try { fs.chmodSync(fn, 0o666); } catch (err) { errors.push('chmod'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -109,7 +109,7 @@ try { fs.lstatSync(fn); } catch (err) { errors.push('lstat'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -117,7 +117,7 @@ try { fs.readlinkSync(fn); } catch (err) { errors.push('readlink'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -125,7 +125,7 @@ try { fs.linkSync(fn, 'foo'); } catch (err) { errors.push('link'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -133,8 +133,8 @@ try { fs.linkSync(existingFile, existingFile2); } catch (err) { errors.push('link'); - assert.ok(0 <= err.message.indexOf(existingFile)); - assert.ok(0 <= err.message.indexOf(existingFile2)); + assert.ok(err.message.includes(existingFile)); + assert.ok(err.message.includes(existingFile2)); } try { @@ -142,8 +142,8 @@ try { fs.symlinkSync(existingFile, existingFile2); } catch (err) { errors.push('symlink'); - assert.ok(0 <= err.message.indexOf(existingFile)); - assert.ok(0 <= err.message.indexOf(existingFile2)); + assert.ok(err.message.includes(existingFile)); + assert.ok(err.message.includes(existingFile2)); } try { @@ -151,7 +151,7 @@ try { fs.unlinkSync(fn); } catch (err) { errors.push('unlink'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -159,7 +159,7 @@ try { fs.rmdirSync(fn); } catch (err) { errors.push('rmdir'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -167,7 +167,7 @@ try { fs.rmdirSync(existingFile); } catch (err) { errors.push('rmdir'); - assert.ok(0 <= err.message.indexOf(existingFile)); + assert.ok(err.message.includes(existingFile)); } try { @@ -175,7 +175,7 @@ try { fs.openSync(fn, 'r'); } catch (err) { errors.push('opens'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -183,7 +183,7 @@ try { fs.renameSync(fn, 'foo'); } catch (err) { errors.push('rename'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } try { @@ -191,8 +191,8 @@ try { fs.renameSync(existingDir, existingDir2); } catch (err) { errors.push('rename'); - assert.ok(0 <= err.message.indexOf(existingDir)); - assert.ok(0 <= err.message.indexOf(existingDir2)); + assert.ok(err.message.includes(existingDir)); + assert.ok(err.message.includes(existingDir2)); } try { @@ -200,7 +200,7 @@ try { fs.readdirSync(fn); } catch (err) { errors.push('readdir'); - assert.ok(0 <= err.message.indexOf(fn)); + assert.ok(err.message.includes(fn)); } process.on('exit', function() { diff --git a/test/parallel/test-http-client-parse-error.js b/test/parallel/test-http-client-parse-error.js index e649f983a51626..77cd2cb193a680 100644 --- a/test/parallel/test-http-client-parse-error.js +++ b/test/parallel/test-http-client-parse-error.js @@ -26,7 +26,7 @@ net.createServer(function(c) { path: '/' }).on('error', function(e) { console.log('got error from client'); - assert.ok(e.message.indexOf('Parse Error') >= 0); + assert.ok(e.message.includes('Parse Error')); assert.strictEqual(e.code, 'HPE_INVALID_CONSTANT'); parseErrors++; }).end(); diff --git a/test/parallel/test-http-extra-response.js b/test/parallel/test-http-extra-response.js index 5e994134c2e2ad..2a57c3374757e6 100644 --- a/test/parallel/test-http-extra-response.js +++ b/test/parallel/test-http-extra-response.js @@ -28,7 +28,7 @@ const server = net.createServer(function(socket) { socket.on('data', function(chunk) { postBody += chunk; - if (postBody.indexOf('\r\n') > -1) { + if (postBody.includes('\r\n')) { socket.write(fullResponse); // omg, I wrote the response twice, what a terrible HTTP server I am. socket.end(fullResponse); diff --git a/test/parallel/test-http-get-pipeline-problem.js b/test/parallel/test-http-get-pipeline-problem.js index 56bfb33456dff7..69d6264acbb954 100644 --- a/test/parallel/test-http-get-pipeline-problem.js +++ b/test/parallel/test-http-get-pipeline-problem.js @@ -72,7 +72,7 @@ function checkFiles() { for (let i = 0; i < total; i++) { const fn = i + '.jpg'; - assert.ok(files.indexOf(fn) >= 0, "couldn't find '" + fn + "'"); + assert.ok(files.includes(fn), "couldn't find '" + fn + "'"); const stat = fs.statSync(common.tmpDir + '/' + fn); assert.strictEqual(image.length, stat.size, "size doesn't match on '" + fn + diff --git a/test/parallel/test-https-strict.js b/test/parallel/test-https-strict.js index d36b413021643f..9f417ce4914c3f 100644 --- a/test/parallel/test-https-strict.js +++ b/test/parallel/test-https-strict.js @@ -111,11 +111,11 @@ function makeReq(path, port, error, host, ca) { options.agent = agent0; } else { if (!Array.isArray(ca)) ca = [ca]; - if (-1 !== ca.indexOf(ca1) && -1 !== ca.indexOf(ca2)) { + if (ca.includes(ca1) && ca.includes(ca2)) { options.agent = agent3; - } else if (-1 !== ca.indexOf(ca1)) { + } else if (ca.includes(ca1)) { options.agent = agent1; - } else if (-1 !== ca.indexOf(ca2)) { + } else if (ca.includes(ca2)) { options.agent = agent2; } else { options.agent = agent0; diff --git a/test/parallel/test-intl.js b/test/parallel/test-intl.js index 3b56defe471af0..6bbe71ec147b42 100644 --- a/test/parallel/test-intl.js +++ b/test/parallel/test-intl.js @@ -16,7 +16,7 @@ const haveIntl = (global.Intl !== undefined); // Else, returns false function haveLocale(loc) { const locs = process.config.variables.icu_locales.split(','); - return locs.indexOf(loc) !== -1; + return locs.includes(loc); } if (!haveIntl) { diff --git a/test/parallel/test-listen-fd-detached-inherit.js b/test/parallel/test-listen-fd-detached-inherit.js index 36e4df28897383..f921ba0bbf8d6d 100644 --- a/test/parallel/test-listen-fd-detached-inherit.js +++ b/test/parallel/test-listen-fd-detached-inherit.js @@ -29,7 +29,7 @@ function test() { let json = ''; parent.stdout.on('data', function(c) { json += c.toString(); - if (json.indexOf('\n') !== -1) next(); + if (json.includes('\n')) next(); }); function next() { console.error('output from parent = %s', json); diff --git a/test/parallel/test-listen-fd-detached.js b/test/parallel/test-listen-fd-detached.js index ec9d039e96e3f2..de878726af5761 100644 --- a/test/parallel/test-listen-fd-detached.js +++ b/test/parallel/test-listen-fd-detached.js @@ -29,7 +29,7 @@ function test() { let json = ''; parent.stdout.on('data', function(c) { json += c.toString(); - if (json.indexOf('\n') !== -1) next(); + if (json.includes('\n')) next(); }); function next() { console.error('output from parent = %s', json); diff --git a/test/parallel/test-module-globalpaths-nodepath.js b/test/parallel/test-module-globalpaths-nodepath.js index a4781d27a7a9c6..6bb55d3d8465d9 100644 --- a/test/parallel/test-module-globalpaths-nodepath.js +++ b/test/parallel/test-module-globalpaths-nodepath.js @@ -19,8 +19,8 @@ if (common.isWindows) { mod._initPaths(); -assert.ok(mod.globalPaths.indexOf(partA) !== -1); -assert.ok(mod.globalPaths.indexOf(partB) !== -1); -assert.ok(mod.globalPaths.indexOf(partC) === -1); +assert.ok(mod.globalPaths.includes(partA)); +assert.ok(mod.globalPaths.includes(partB)); +assert.ok(!mod.globalPaths.includes(partC)); assert.ok(Array.isArray(mod.globalPaths)); diff --git a/test/parallel/test-net-eaddrinuse.js b/test/parallel/test-net-eaddrinuse.js index cf4293e8230875..9c30f933108d6f 100644 --- a/test/parallel/test-net-eaddrinuse.js +++ b/test/parallel/test-net-eaddrinuse.js @@ -9,7 +9,7 @@ const server2 = net.createServer(function(socket) { }); server1.listen(0, function() { server2.on('error', function(error) { - assert.strictEqual(true, error.message.indexOf('EADDRINUSE') >= 0); + assert.strictEqual(true, error.message.includes('EADDRINUSE')); server1.close(); }); server2.listen(this.address().port); diff --git a/test/parallel/test-process-getactivehandles.js b/test/parallel/test-process-getactivehandles.js index 8ceb2bcd2a32f7..2db3da3c563e6e 100644 --- a/test/parallel/test-process-getactivehandles.js +++ b/test/parallel/test-process-getactivehandles.js @@ -33,15 +33,15 @@ function checkAll() { const handles = process._getActiveHandles(); clients.forEach(function(item) { - assert.ok(handles.indexOf(item) > -1); + assert.ok(handles.includes(item)); item.destroy(); }); connections.forEach(function(item) { - assert.ok(handles.indexOf(item) > -1); + assert.ok(handles.includes(item)); item.end(); }); - assert.ok(handles.indexOf(server) > -1); + assert.ok(handles.includes(server)); server.close(); } diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 49ace9e68b45f4..5e3e9b7b663ba8 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -68,7 +68,7 @@ function error_test() { client_unix.expect : JSON.stringify(client_unix.expect))); - if (read_buffer.indexOf(prompt_unix) !== -1) { + if (read_buffer.includes(prompt_unix)) { // if it's an exact match, then don't do the regexp if (read_buffer !== client_unix.expect) { let expect = client_unix.expect; @@ -89,7 +89,7 @@ function error_test() { tcp_test(); } - } else if (read_buffer.indexOf(prompt_multiline) !== -1) { + } else if (read_buffer.includes(prompt_multiline)) { // Check that you meant to send a multiline test assert.strictEqual(prompt_multiline, client_unix.expect); read_buffer = ''; @@ -427,7 +427,7 @@ function tcp_test() { read_buffer += data.toString('ascii', 0, data.length); console.error('TCP data: ' + JSON.stringify(read_buffer) + ', expecting ' + JSON.stringify(client_tcp.expect)); - if (read_buffer.indexOf(prompt_tcp) !== -1) { + if (read_buffer.includes(prompt_tcp)) { assert.strictEqual(client_tcp.expect, read_buffer); console.error('match'); read_buffer = ''; @@ -497,7 +497,7 @@ function unix_test() { read_buffer += data.toString('ascii', 0, data.length); console.error('Unix data: ' + JSON.stringify(read_buffer) + ', expecting ' + JSON.stringify(client_unix.expect)); - if (read_buffer.indexOf(prompt_unix) !== -1) { + if (read_buffer.includes(prompt_unix)) { assert.strictEqual(client_unix.expect, read_buffer); console.error('match'); read_buffer = ''; diff --git a/test/parallel/test-stream-big-packet.js b/test/parallel/test-stream-big-packet.js index 8e5af3ea4ba342..72c4526973a9ad 100644 --- a/test/parallel/test-stream-big-packet.js +++ b/test/parallel/test-stream-big-packet.js @@ -22,7 +22,7 @@ util.inherits(TestStream, stream.Transform); TestStream.prototype._transform = function(chunk, encoding, done) { if (!passed) { // Char 'a' only exists in the last write - passed = chunk.toString().indexOf('a') >= 0; + passed = chunk.toString().includes('a'); } done(); };