| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,15 +27,22 @@ const path = require('path'); | |||
| 27 | 27 | const { inspect } = require('util'); | |
| 28 | 28 | ||
| 29 | 29 | const is = { | |
| 30 | + number: (value, key) => { | ||
| 31 | + assert(!isNaN(value), `${key} should not be NaN`); | ||
| 32 | + assert.strictEqual(typeof value, 'number'); | ||
| 33 | + }, | ||
| 30 | 34 | string: (value) => { assert.strictEqual(typeof value, 'string'); }, | |
| 31 | - number: (value) => { assert.strictEqual(typeof value, 'number'); }, | ||
| 32 | 35 | array: (value) => { assert.ok(Array.isArray(value)); }, | |
| 33 | 36 | object: (value) => { | |
| 34 | 37 | assert.strictEqual(typeof value, 'object'); | |
| 35 | 38 | assert.notStrictEqual(value, null); | |
| 36 | 39 | } | |
| 37 | 40 | }; | |
| 38 | 41 | ||
| 42 | + const flatten = (arr) => | ||
| 43 | + arr.reduce((acc, c) => | ||
| 44 | + acc.concat(Array.isArray(c) ? flatten(c) : c), []); | ||
| 45 | + | ||
| 39 | 46 | process.env.TMPDIR = '/tmpdir'; | |
| 40 | 47 | process.env.TMP = '/tmp'; | |
| 41 | 48 | process.env.TEMP = '/temp'; | |
@@ -112,43 +119,49 @@ if (!common.isSunOS) { | |||
| 112 | 119 | assert.ok(os.totalmem() > 0); | |
| 113 | 120 | } | |
| 114 | 121 | ||
| 115 | - | ||
| 116 | 122 | const interfaces = os.networkInterfaces(); | |
| 117 | 123 | switch (platform) { | |
| 118 | - case 'linux': | ||
| 119 | - { | ||
| 120 | - const filter = | ||
| 121 | - (e) => e.address === '127.0.0.1' && e.netmask === '255.0.0.0'; | ||
| 124 | + case 'linux': { | ||
| 125 | + const filter = (e) => | ||
| 126 | + e.address === '127.0.0.1' && | ||
| 127 | + e.netmask === '255.0.0.0'; | ||
| 128 | + | ||
| 122 | 129 | const actual = interfaces.lo.filter(filter); | |
| 123 | - const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0', | ||
| 124 | - mac: '00:00:00:00:00:00', family: 'IPv4', | ||
| 125 | - internal: true, cidr: '127.0.0.1/8' }]; | ||
| 130 | + const expected = [{ | ||
| 131 | + address: '127.0.0.1', | ||
| 132 | + netmask: '255.0.0.0', | ||
| 133 | + mac: '00:00:00:00:00:00', | ||
| 134 | + family: 'IPv4', | ||
| 135 | + internal: true, | ||
| 136 | + cidr: '127.0.0.1/8' | ||
| 137 | + }]; | ||
| 126 | 138 | assert.deepStrictEqual(actual, expected); | |
| 127 | 139 | break; | |
| 128 | 140 | } | |
| 129 | - case 'win32': | ||
| 130 | - { | ||
| 131 | - const filter = (e) => e.address === '127.0.0.1'; | ||
| 141 | + case 'win32': { | ||
| 142 | + const filter = (e) => | ||
| 143 | + e.address === '127.0.0.1'; | ||
| 144 | + | ||
| 132 | 145 | const actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter); | |
| 133 | - const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0', | ||
| 134 | - mac: '00:00:00:00:00:00', family: 'IPv4', | ||
| 135 | - internal: true, cidr: '127.0.0.1/8' }]; | ||
| 146 | + const expected = [{ | ||
| 147 | + address: '127.0.0.1', | ||
| 148 | + netmask: '255.0.0.0', | ||
| 149 | + mac: '00:00:00:00:00:00', | ||
| 150 | + family: 'IPv4', | ||
| 151 | + internal: true, | ||
| 152 | + cidr: '127.0.0.1/8' | ||
| 153 | + }]; | ||
| 136 | 154 | assert.deepStrictEqual(actual, expected); | |
| 137 | 155 | break; | |
| 138 | 156 | } | |
| 139 | 157 | } | |
| 140 | - function flatten(arr) { | ||
| 141 | - return arr.reduce( | ||
| 142 | - (acc, c) => acc.concat(Array.isArray(c) ? flatten(c) : c), | ||
| 143 | - [] | ||
| 144 | - ); | ||
| 145 | - } | ||
| 146 | 158 | const netmaskToCIDRSuffixMap = new Map(Object.entries({ | |
| 147 | 159 | '255.0.0.0': 8, | |
| 148 | 160 | '255.255.255.0': 24, | |
| 149 | 161 | 'ffff:ffff:ffff:ffff::': 64, | |
| 150 | 162 | 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff': 128 | |
| 151 | 163 | })); | |
| 164 | + | ||
| 152 | 165 | flatten(Object.values(interfaces)) | |
| 153 | 166 | .map((v) => ({ v, mask: netmaskToCIDRSuffixMap.get(v.netmask) })) | |
| 154 | 167 | .forEach(({ v, mask }) => { | |
@@ -159,11 +172,13 @@ flatten(Object.values(interfaces)) | |||
| 159 | 172 | }); | |
| 160 | 173 | ||
| 161 | 174 | const EOL = os.EOL; | |
| 162 | - assert.ok(EOL.length > 0); | ||
| 163 | - | ||
| 175 | + if (common.isWindows) { | ||
| 176 | + assert.strictEqual(EOL, '\r\n'); | ||
| 177 | + } else { | ||
| 178 | + assert.strictEqual(EOL, '\n'); | ||
| 179 | + } | ||
| 164 | 180 | ||
| 165 | 181 | const home = os.homedir(); | |
| 166 | - | ||
| 167 | 182 | is.string(home); | |
| 168 | 183 | assert.ok(home.includes(path.sep)); | |
| 169 | 184 | ||
@@ -204,11 +219,20 @@ assert.ok(pwd.homedir.includes(path.sep)); | |||
| 204 | 219 | assert.strictEqual(pwd.username, pwdBuf.username.toString('utf8')); | |
| 205 | 220 | assert.strictEqual(pwd.homedir, pwdBuf.homedir.toString('utf8')); | |
| 206 | 221 | ||
| 207 | - // Test that the Symbol.toPrimitive functions work correctly | ||
| 208 | - [ | ||
| 209 | - [`${os.hostname}`, os.hostname()], | ||
| 210 | - [`${os.homedir}`, os.homedir()], | ||
| 211 | - [`${os.release}`, os.release()], | ||
| 212 | - [`${os.type}`, os.type()], | ||
| 213 | - [`${os.endianness}`, os.endianness()] | ||
| 214 | - ].forEach((set) => assert.strictEqual(set[0], set[1])); | ||
| 222 | + assert.strictEqual(`${os.hostname}`, os.hostname()); | ||
| 223 | + assert.strictEqual(`${os.homedir}`, os.homedir()); | ||
| 224 | + assert.strictEqual(`${os.release}`, os.release()); | ||
| 225 | + assert.strictEqual(`${os.type}`, os.type()); | ||
| 226 | + assert.strictEqual(`${os.endianness}`, os.endianness()); | ||
| 227 | + assert.strictEqual(`${os.tmpdir}`, os.tmpdir()); | ||
| 228 | + assert.strictEqual(`${os.arch}`, os.arch()); | ||
| 229 | + assert.strictEqual(`${os.platform}`, os.platform()); | ||
| 230 | + | ||
| 231 | + assert.strictEqual(+os.totalmem, os.totalmem()); | ||
| 232 | + | ||
| 233 | + // Assert that the following values are coercible to numbers. | ||
| 234 | + is.number(+os.uptime, 'uptime'); | ||
| 235 | + is.number(os.uptime(), 'uptime'); | ||
| 236 | + | ||
| 237 | + is.number(+os.freemem, 'freemem'); | ||
| 238 | + is.number(os.freemem(), 'freemem'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments