| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 13b1763 commit 7c4babf
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,6 @@ const dns = require('dns'); | |||
| 5 | 5 | const net = require('net'); | |
| 6 | 6 | const isIPv6 = net.isIPv6; | |
| 7 | 7 | ||
| 8 | - let expected = 0; | ||
| 9 | - let completed = 0; | ||
| 10 | 8 | let running = false; | |
| 11 | 9 | const queue = []; | |
| 12 | 10 | ||
@@ -17,7 +15,7 @@ if (!common.hasIPv6) { | |||
| 17 | 15 | ||
| 18 | 16 | function TEST(f) { | |
| 19 | 17 | function next() { | |
| 20 | - var f = queue.shift(); | ||
| 18 | + const f = queue.shift(); | ||
| 21 | 19 | if (f) { | |
| 22 | 20 | running = true; | |
| 23 | 21 | console.log(f.name); | |
@@ -27,11 +25,9 @@ function TEST(f) { | |||
| 27 | 25 | ||
| 28 | 26 | function done() { | |
| 29 | 27 | running = false; | |
| 30 | - completed++; | ||
| 31 | 28 | process.nextTick(next); | |
| 32 | 29 | } | |
| 33 | 30 | ||
| 34 | - expected++; | ||
| 35 | 31 | queue.push(f); | |
| 36 | 32 | ||
| 37 | 33 | if (!running) { | |
@@ -44,46 +40,46 @@ function checkWrap(req) { | |||
| 44 | 40 | } | |
| 45 | 41 | ||
| 46 | 42 | TEST(function test_resolve6(done) { | |
| 47 | - var req = dns.resolve6('ipv6.google.com', function(err, ips) { | ||
| 48 | - if (err) throw err; | ||
| 43 | + const req = dns.resolve6('ipv6.google.com', | ||
| 44 | + common.mustCall((err, ips) => { | ||
| 45 | + assert.ifError(err); | ||
| 49 | 46 | ||
| 50 | - assert.ok(ips.length > 0); | ||
| 47 | + assert.ok(ips.length > 0); | ||
| 51 | 48 | ||
| 52 | - for (var i = 0; i < ips.length; i++) { | ||
| 53 | - assert.ok(isIPv6(ips[i])); | ||
| 54 | - } | ||
| 49 | + for (let i = 0; i < ips.length; i++) | ||
| 50 | + assert.ok(isIPv6(ips[i])); | ||
| 55 | 51 | ||
| 56 | - done(); | ||
| 57 | - }); | ||
| 52 | + done(); | ||
| 53 | + })); | ||
| 58 | 54 | ||
| 59 | 55 | checkWrap(req); | |
| 60 | 56 | }); | |
| 61 | 57 | ||
| 62 | 58 | TEST(function test_reverse_ipv6(done) { | |
| 63 | - var req = dns.reverse('2001:4860:4860::8888', function(err, domains) { | ||
| 64 | - if (err) throw err; | ||
| 59 | + const req = dns.reverse('2001:4860:4860::8888', | ||
| 60 | + common.mustCall((err, domains) => { | ||
| 61 | + assert.ifError(err); | ||
| 65 | 62 | ||
| 66 | - assert.ok(domains.length > 0); | ||
| 63 | + assert.ok(domains.length > 0); | ||
| 67 | 64 | ||
| 68 | - for (var i = 0; i < domains.length; i++) { | ||
| 69 | - assert.ok(domains[i]); | ||
| 70 | - assert.ok(typeof domains[i] === 'string'); | ||
| 71 | - } | ||
| 65 | + for (let i = 0; i < domains.length; i++) | ||
| 66 | + assert.ok(typeof domains[i] === 'string'); | ||
| 72 | 67 | ||
| 73 | - done(); | ||
| 74 | - }); | ||
| 68 | + done(); | ||
| 69 | + })); | ||
| 75 | 70 | ||
| 76 | 71 | checkWrap(req); | |
| 77 | 72 | }); | |
| 78 | 73 | ||
| 79 | 74 | TEST(function test_lookup_ipv6_explicit(done) { | |
| 80 | - var req = dns.lookup('ipv6.google.com', 6, function(err, ip, family) { | ||
| 81 | - if (err) throw err; | ||
| 82 | - assert.ok(net.isIPv6(ip)); | ||
| 83 | - assert.strictEqual(family, 6); | ||
| 75 | + const req = dns.lookup('ipv6.google.com', 6, | ||
| 76 | + common.mustCall((err, ip, family) => { | ||
| 77 | + assert.ifError(err); | ||
| 78 | + assert.ok(isIPv6(ip)); | ||
| 79 | + assert.strictEqual(family, 6); | ||
| 84 | 80 | ||
| 85 | - done(); | ||
| 86 | - }); | ||
| 81 | + done(); | ||
| 82 | + })); | ||
| 87 | 83 | ||
| 88 | 84 | checkWrap(req); | |
| 89 | 85 | }); | |
@@ -103,24 +99,24 @@ TEST(function test_lookup_ipv6_implicit(done) { | |||
| 103 | 99 | */ | |
| 104 | 100 | ||
| 105 | 101 | TEST(function test_lookup_ipv6_explicit_object(done) { | |
| 106 | - var req = dns.lookup('ipv6.google.com', { | ||
| 102 | + const req = dns.lookup('ipv6.google.com', { | ||
| 107 | 103 | family: 6 | |
| 108 | - }, function(err, ip, family) { | ||
| 109 | - if (err) throw err; | ||
| 110 | - assert.ok(net.isIPv6(ip)); | ||
| 104 | + }, common.mustCall((err, ip, family) => { | ||
| 105 | + assert.ifError(err); | ||
| 106 | + assert.ok(isIPv6(ip)); | ||
| 111 | 107 | assert.strictEqual(family, 6); | |
| 112 | 108 | ||
| 113 | 109 | done(); | |
| 114 | - }); | ||
| 110 | + })); | ||
| 115 | 111 | ||
| 116 | 112 | checkWrap(req); | |
| 117 | 113 | }); | |
| 118 | 114 | ||
| 119 | 115 | TEST(function test_lookup_ipv6_hint(done) { | |
| 120 | - var req = dns.lookup('www.google.com', { | ||
| 116 | + const req = dns.lookup('www.google.com', { | ||
| 121 | 117 | family: 6, | |
| 122 | 118 | hints: dns.V4MAPPED | |
| 123 | - }, function(err, ip, family) { | ||
| 119 | + }, common.mustCall((err, ip, family) => { | ||
| 124 | 120 | if (err) { | |
| 125 | 121 | // FreeBSD does not support V4MAPPED | |
| 126 | 122 | if (common.isFreeBSD) { | |
@@ -130,66 +126,69 @@ TEST(function test_lookup_ipv6_hint(done) { | |||
| 130 | 126 | assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message)); | |
| 131 | 127 | done(); | |
| 132 | 128 | return; | |
| 133 | - } else { | ||
| 134 | - throw err; | ||
| 135 | 129 | } | |
| 130 | + | ||
| 131 | + assert.ifError(err); | ||
| 136 | 132 | } | |
| 137 | - assert.ok(net.isIPv6(ip)); | ||
| 133 | + | ||
| 134 | + assert.ok(isIPv6(ip)); | ||
| 138 | 135 | assert.strictEqual(family, 6); | |
| 139 | 136 | ||
| 140 | 137 | done(); | |
| 141 | - }); | ||
| 138 | + })); | ||
| 142 | 139 | ||
| 143 | 140 | checkWrap(req); | |
| 144 | 141 | }); | |
| 145 | 142 | ||
| 146 | 143 | TEST(function test_lookup_ip_ipv6(done) { | |
| 147 | - var req = dns.lookup('::1', function(err, ip, family) { | ||
| 148 | - if (err) throw err; | ||
| 149 | - assert.ok(net.isIPv6(ip)); | ||
| 150 | - assert.strictEqual(family, 6); | ||
| 144 | + const req = dns.lookup('::1', | ||
| 145 | + common.mustCall((err, ip, family) => { | ||
| 146 | + assert.ifError(err); | ||
| 147 | + assert.ok(isIPv6(ip)); | ||
| 148 | + assert.strictEqual(family, 6); | ||
| 151 | 149 | ||
| 152 | - done(); | ||
| 153 | - }); | ||
| 150 | + done(); | ||
| 151 | + })); | ||
| 154 | 152 | ||
| 155 | 153 | checkWrap(req); | |
| 156 | 154 | }); | |
| 157 | 155 | ||
| 158 | 156 | TEST(function test_lookup_all_ipv6(done) { | |
| 159 | - var req = dns.lookup( | ||
| 157 | + const req = dns.lookup( | ||
| 160 | 158 | 'www.google.com', | |
| 161 | 159 | {all: true, family: 6}, | |
| 162 | - function(err, ips) { | ||
| 163 | - if (err) throw err; | ||
| 160 | + common.mustCall((err, ips) => { | ||
| 161 | + assert.ifError(err); | ||
| 164 | 162 | assert.ok(Array.isArray(ips)); | |
| 165 | 163 | assert.ok(ips.length > 0); | |
| 166 | 164 | ||
| 167 | - ips.forEach(function(ip) { | ||
| 165 | + ips.forEach((ip) => { | ||
| 168 | 166 | assert.ok(isIPv6(ip.address), | |
| 169 | 167 | 'Invalid IPv6: ' + ip.address.toString()); | |
| 170 | 168 | assert.strictEqual(ip.family, 6); | |
| 171 | 169 | }); | |
| 172 | 170 | ||
| 173 | 171 | done(); | |
| 174 | 172 | } | |
| 175 | - ); | ||
| 173 | + )); | ||
| 176 | 174 | ||
| 177 | 175 | checkWrap(req); | |
| 178 | 176 | }); | |
| 179 | 177 | ||
| 180 | 178 | TEST(function test_lookupservice_ip_ipv6(done) { | |
| 181 | - var req = dns.lookupService('::1', 80, function(err, host, service) { | ||
| 182 | - if (err) { | ||
| 183 | - // Not skipping the test, rather checking an alternative result, | ||
| 184 | - // i.e. that ::1 may not be configured (e.g. in /etc/hosts) | ||
| 185 | - assert.strictEqual(err.code, 'ENOTFOUND'); | ||
| 186 | - return done(); | ||
| 187 | - } | ||
| 188 | - assert.equal(typeof host, 'string'); | ||
| 189 | - assert(host); | ||
| 190 | - assert(['http', 'www', '80'].includes(service)); | ||
| 191 | - done(); | ||
| 192 | - }); | ||
| 179 | + const req = dns.lookupService('::1', 80, | ||
| 180 | + common.mustCall((err, host, service) => { | ||
| 181 | + if (err) { | ||
| 182 | + // Not skipping the test, rather checking an alternative result, | ||
| 183 | + // i.e. that ::1 may not be configured (e.g. in /etc/hosts) | ||
| 184 | + assert.strictEqual(err.code, 'ENOTFOUND'); | ||
| 185 | + return done(); | ||
| 186 | + } | ||
| 187 | + assert.strictEqual(typeof host, 'string'); | ||
| 188 | + assert(host); | ||
| 189 | + assert(['http', 'www', '80'].includes(service)); | ||
| 190 | + done(); | ||
| 191 | + })); | ||
| 193 | 192 | ||
| 194 | 193 | checkWrap(req); | |
| 195 | 194 | }); | |
@@ -206,9 +205,3 @@ TEST(function test_lookupservice_ip_ipv6(done) { | |||
| 206 | 205 | ||
| 207 | 206 | checkWrap(req); | |
| 208 | 207 | }); */ | |
| 209 | - | ||
| 210 | - process.on('exit', function() { | ||
| 211 | - console.log(completed + ' tests completed'); | ||
| 212 | - assert.equal(running, false); | ||
| 213 | - assert.strictEqual(expected, completed); | ||
| 214 | - }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments