Skip to content

Commit 78147ad

Browse files
committed
add: changed index test
1 parent 33ff67d commit 78147ad

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"compact2string": "^1.4.1",
3737
"debug": "^4.1.1",
3838
"ip": "^1.1.5",
39+
"jsdom": "^22.1.0",
3940
"lru": "^3.1.0",
4041
"minimist": "^1.2.5",
4142
"once": "^1.4.0",

server.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,25 +331,25 @@ class Server extends EventEmitter {
331331
<body>
332332
<div class="center">
333333
<div class="first">Tracker Stats</div>
334-
<div class="first">There are ${stats.torrents} torrents, ${stats.activeTorrents} are active.</div>
335-
<div class="first">Connected Peers: ${stats.peersAll}</div>
334+
<div class="first">There are <div id="torrents">${stats.torrents}</div> torrents, <div id="activeTorrents">${stats.activeTorrents}</div> are active.</div>
335+
<div class="first">Connected Peers: <div id="peersAll">${stats.peersAll}</div></div>
336336
</div>
337337
338338
<div class="center">
339-
<div class="second">Peers Seeding Only: ${stats.peersSeederOnly}</div>
340-
<div class="second">Peers Leeching Only: ${stats.peersLeecherOnly}</div>
341-
<div class="second">Peers Seeding & Leeching: ${stats.peersSeederAndLeecher}</div>
339+
<div class="second">Peers Seeding Only: <div id="peersSeederOnly">${stats.peersSeederOnly}</div></div>
340+
<div class="second">Peers Leeching Only: <div id="peersLeecherOnly">${stats.peersLeecherOnly}</div></div>
341+
<div class="second">Peers Seeding & Leeching: <div id="peersSeederAndLeecher">${stats.peersSeederAndLeecher}</div></div>
342342
</div>
343343
344344
<div class="center">
345-
<div class="third">IPv4 Peers: ${stats.peersIPv4}</div>
346-
<div class="third">IPv6 Peers: ${stats.peersIPv6}</div>
345+
<div class="third">IPv4 Peers: <div id="peersIPv4">${stats.peersIPv4}</div></div>
346+
<div class="third">IPv6 Peers: <div id="peersIPv6">${stats.peersIPv6}</div></div>
347347
</div>
348348
349349
<div class="center">
350350
<div class="fourth">
351351
<h4>Clients:</h4>
352-
${printClients(stats.clients)}
352+
<div id="clients">${printClients(stats.clients)}</div>
353353
</div>
354354
</div>
355355
</body>

test/stats.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,23 @@ import commonTest from './common.js'
33
import fixtures from 'webtorrent-fixtures'
44
import get from 'simple-get'
55
import test from 'tape'
6+
import jsdom from 'jsdom'
67

78
const peerId = Buffer.from('-WW0091-4ea5886ce160')
89
const unknownPeerId = Buffer.from('01234567890123456789')
910

1011
function parseHtml (html) {
11-
const extractValue = /[^v^h](\d+)/
12-
const array = html.replace('torrents', '\n').split('\n').filter(line => line && line.trim().length > 0).map(line => {
13-
const a = extractValue.exec(line)
14-
if (a) {
15-
return parseInt(a[1])
16-
}
17-
return null
18-
})
19-
let i = 0
12+
const dom = new jsdom.JSDOM(html)
13+
2014
return {
21-
torrents: array[i++],
22-
activeTorrents: array[i++],
23-
peersAll: array[i++],
24-
peersSeederOnly: array[i++],
25-
peersLeecherOnly: array[i++],
26-
peersSeederAndLeecher: array[i++],
27-
peersIPv4: array[i++],
28-
peersIPv6: array[i]
15+
torrents: parseInt(dom.window.document.getElementById('torrents').textContent),
16+
activeTorrents: parseInt(dom.window.document.getElementById('activeTorrents').textContent),
17+
peersAll: parseInt(dom.window.document.getElementById('peersAll').textContent),
18+
peersSeederOnly: parseInt(dom.window.document.getElementById('peersSeederOnly').textContent),
19+
peersLeecherOnly: parseInt(dom.window.document.getElementById('peersLeecherOnly').textContent),
20+
peersSeederAndLeecher: parseInt(dom.window.document.getElementById('peersSeederAndLeecher').textContent),
21+
peersIPv4: parseInt(dom.window.document.getElementById('peersIPv4').textContent),
22+
peersIPv6: parseInt(dom.window.document.getElementById('peersIPv6').textContent)
2923
}
3024
}
3125

0 commit comments

Comments
 (0)