@@ -3,29 +3,23 @@ import commonTest from './common.js'
33import fixtures from 'webtorrent-fixtures'
44import get from 'simple-get'
55import test from 'tape'
6+ import jsdom from 'jsdom'
67
78const peerId = Buffer . from ( '-WW0091-4ea5886ce160' )
89const unknownPeerId = Buffer . from ( '01234567890123456789' )
910
1011function 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