Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test improvements: use fixtures #540

Merged
merged 8 commits into from Dec 27, 2015
Next

test: `torrent.announce` must always be an array

  • Loading branch information
feross committed Dec 19, 2015
commit 1da859430e3a425ea60764327e13f047c3c47766
@@ -116,7 +116,7 @@ test('client.add: parsed torrent, from `parse-torrent`', function (t) {
})

test('client.add: parsed torrent, with string type announce property', function (t) {
t.plan(6)
t.plan(7)

var client = new WebTorrent({ dht: false, tracker: false })

@@ -131,7 +131,44 @@ test('client.add: parsed torrent, with string type announce property', function

torrent.on('infoHash', function () {
t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, common.leaves.magnetURI + '&tr=' + encodeURIComponent('http://tracker.local:80'))

var expectedMagnetURI = common.leaves.magnetURI +
'&tr=' + encodeURIComponent('http://tracker.local:80')
t.equal(torrent.magnetURI, expectedMagnetURI)

// `torrent.announce` must always be an array
t.deepEqual(torrent.announce, [ 'http://tracker.local:80' ])

client.remove(common.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)

client.destroy(function (err) { t.error(err, 'client destroyed') })
})
})

test('client.add: parsed torrent, with array type announce property', function (t) {
t.plan(7)

var client = new WebTorrent({ dht: false, tracker: false })

client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })

var parsedTorrent = extend(common.leaves.parsedTorrent)
parsedTorrent.announce = [ 'http://tracker.local:80', 'http://tracker.local:81' ]

var torrent = client.add(parsedTorrent)
t.equal(client.torrents.length, 1)

torrent.on('infoHash', function () {
t.equal(torrent.infoHash, common.leaves.parsedTorrent.infoHash)

var expectedMagnetURI = common.leaves.magnetURI +
'&tr=' + encodeURIComponent('http://tracker.local:80') +
'&tr=' + encodeURIComponent('http://tracker.local:81')
t.equal(torrent.magnetURI, expectedMagnetURI)

t.deepEqual(torrent.announce, [ 'http://tracker.local:80', 'http://tracker.local:81' ])

client.remove(common.leaves.parsedTorrent, function (err) { t.error(err, 'torrent destroyed') })
t.equal(client.torrents.length, 0)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.