Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdidon committed Apr 22, 2022
1 parent 97e9438 commit 4c5db05
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
58 changes: 29 additions & 29 deletions test/bonjour.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict'

var os = require('os')
var dgram = require('dgram')
var tape = require('tape')
var afterAll = require('after-all')
var { Service } = require('../dist/lib/service')
var { Bonjour } = require('../dist')

var getAddresses = function () {
var addresses = []
var itrs = os.networkInterfaces()
for (var i in itrs) {
var addrs = itrs[i]
for (var j in addrs) {
const os = require('os')
const dgram = require('dgram')
const tape = require('tape')
const afterAll = require('after-all')
const { Service } = require('../dist/lib/service')
const { Bonjour } = require('../dist')

const getAddresses = function () {
const addresses = []
const itrs = os.networkInterfaces()
for (const i in itrs) {
const addrs = itrs[i]
for (const j in addrs) {
if (addrs[j].internal === false) {
addresses.push(addrs[j].address)
}
Expand All @@ -21,18 +21,18 @@ var getAddresses = function () {
return addresses
}

var port = function (cb) {
var s = dgram.createSocket('udp4')
const port = function (cb) {
const s = dgram.createSocket('udp4')
s.bind(0, function () {
var port = s.address().port
const port = s.address().port
s.on('close', function () {
cb(port)
})
s.close()
})
}

var test = function (name, fn) {
const test = function (name, fn) {
tape(name, function (t) {
port(function (p) {
fn(new Bonjour({ ip: '127.0.0.1', port: p, multicast: false }), t)
Expand All @@ -41,7 +41,7 @@ var test = function (name, fn) {
}

test('bonjour.publish', function (bonjour, t) {
var service = bonjour.publish({ name: 'foo', type: 'bar', port: 3000 })
const service = bonjour.publish({ name: 'foo', type: 'bar', port: 3000 })
t.ok(service instanceof Service)
t.equal(service.published, false)
service.on('up', function () {
Expand All @@ -53,7 +53,7 @@ test('bonjour.publish', function (bonjour, t) {

test('bonjour.unpublishAll', function (bonjour, t) {
t.test('published services', function (t) {
var service = bonjour.publish({ name: 'foo', type: 'bar', port: 3000 })
const service = bonjour.publish({ name: 'foo', type: 'bar', port: 3000 })
service.on('up', function () {
bonjour.unpublishAll(function (err) {
t.error(err)
Expand All @@ -73,9 +73,9 @@ test('bonjour.unpublishAll', function (bonjour, t) {
})

test('bonjour.find', function (bonjour, t) {
var next = afterAll(function () {
var browser = bonjour.find({ type: 'test' })
var ups = 0
const next = afterAll(function () {
const browser = bonjour.find({ type: 'test' })
let ups = 0

browser.on('up', function (s) {
if (s.name === 'Foo Bar') {
Expand Down Expand Up @@ -117,8 +117,8 @@ test('bonjour.find', function (bonjour, t) {
})

test('bonjour.find - binary txt', function (bonjour, t) {
var next = afterAll(function () {
var browser = bonjour.find({ type: 'test', txt: { binary: true } })
const next = afterAll(function () {
const browser = bonjour.find({ type: 'test', txt: { binary: true } })

browser.on('up', function (s) {
t.equal(s.name, 'Foo')
Expand All @@ -133,10 +133,10 @@ test('bonjour.find - binary txt', function (bonjour, t) {
})

test('bonjour.find - down event', function (bonjour, t) {
var service = bonjour.publish({ name: 'Foo Bar', type: 'test', port: 3000 })
const service = bonjour.publish({ name: 'Foo Bar', type: 'test', port: 3000 })

service.on('up', function () {
var browser = bonjour.find({ type: 'test' })
const browser = bonjour.find({ type: 'test' })

browser.on('up', function (s) {
t.equal(s.name, 'Foo Bar')
Expand All @@ -152,7 +152,7 @@ test('bonjour.find - down event', function (bonjour, t) {
})

test('bonjour.findOne - callback', function (bonjour, t) {
var next = afterAll(function () {
const next = afterAll(function () {
bonjour.findOne({ type: 'test' }, function (s) {
t.equal(s.name, 'Callback')
bonjour.destroy()
Expand All @@ -165,8 +165,8 @@ test('bonjour.findOne - callback', function (bonjour, t) {
})

test('bonjour.findOne - emitter', function (bonjour, t) {
var next = afterAll(function () {
var browser = bonjour.findOne({ type: 'test' })
const next = afterAll(function () {
const browser = bonjour.findOne({ type: 'test' })
browser.on('up', function (s) {
t.equal(s.name, 'Emitter')
bonjour.destroy()
Expand Down
30 changes: 15 additions & 15 deletions test/service.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

var os = require('os')
var test = require('tape')
var { Service } = require('../dist/lib/service')
const os = require('os')
const test = require('tape')
const { Service } = require('../dist/lib/service')

var getAddressesRecords = function (host) {
var records = []
var itrs = os.networkInterfaces()
for (var i in itrs) {
var addrs = itrs[i]
for (var j in addrs) {
const getAddressesRecords = function (host) {
const records = []
const itrs = os.networkInterfaces()
for (const i in itrs) {
const addrs = itrs[i]
for (const j in addrs) {
if (addrs[j].internal === false) {
records.push({ data: addrs[j].address, name: host, ttl: 120, type: addrs[j].family === 'IPv4' ? 'A' : 'AAAA' })
}
Expand Down Expand Up @@ -40,7 +40,7 @@ test('no port', function (t) {
})

test('minimal', function (t) {
var s = new Service({ name: 'Foo Bar', type: 'http', port: 3000 })
const s = new Service({ name: 'Foo Bar', type: 'http', port: 3000 })
t.equal(s.name, 'Foo Bar')
t.equal(s.protocol, 'tcp')
t.equal(s.type, '_http._tcp')
Expand All @@ -54,25 +54,25 @@ test('minimal', function (t) {
})

test('protocol', function (t) {
var s = new Service({ name: 'Foo Bar', type: 'http', port: 3000, protocol: 'udp' })
const s = new Service({ name: 'Foo Bar', type: 'http', port: 3000, protocol: 'udp' })
t.deepEqual(s.protocol, 'udp')
t.end()
})

test('host', function (t) {
var s = new Service({ name: 'Foo Bar', type: 'http', port: 3000, host: 'example.com' })
const s = new Service({ name: 'Foo Bar', type: 'http', port: 3000, host: 'example.com' })
t.deepEqual(s.host, 'example.com')
t.end()
})

test('txt', function (t) {
var s = new Service({ name: 'Foo Bar', type: 'http', port: 3000, txt: { foo: 'bar' } })
const s = new Service({ name: 'Foo Bar', type: 'http', port: 3000, txt: { foo: 'bar' } })
t.deepEqual(s.txt, { foo: 'bar' })
t.end()
})

test('_records() - minimal', function (t) {
var s = new Service({ name: 'Foo Bar', type: 'http', protocol: 'tcp', port: 3000 })
const s = new Service({ name: 'Foo Bar', type: 'http', protocol: 'tcp', port: 3000 })
t.deepEqual(s.records(), [
{ data: s.fqdn, name: '_http._tcp.local', ttl: 28800, type: 'PTR' },
{ data: { port: 3000, target: os.hostname() }, name: s.fqdn, ttl: 120, type: 'SRV' },
Expand All @@ -82,7 +82,7 @@ test('_records() - minimal', function (t) {
})

test('_records() - everything', function (t) {
var s = new Service({ name: 'Foo Bar', type: 'http', protocol: 'tcp', port: 3000, host: 'example.com', txt: { foo: 'bar' } })
const s = new Service({ name: 'Foo Bar', type: 'http', protocol: 'tcp', port: 3000, host: 'example.com', txt: { foo: 'bar' } })
t.deepEqual(s.records(), [
{ data: s.fqdn, name: '_http._tcp.local', ttl: 28800, type: 'PTR' },
{ data: { port: 3000, target: 'example.com' }, name: s.fqdn, ttl: 120, type: 'SRV' },
Expand Down

0 comments on commit 4c5db05

Please sign in to comment.