Skip to content

Commit

Permalink
Upgraded tap and tap-given
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er committed Feb 19, 2017
1 parent c486de8 commit 1cfc7fa
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## v0.1.1 2017-02-19

* Upgraded tap-given

## v0.1.0 2017-02-18

* ES6
Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "dgram-as-promised",
"version": "0.1.0",
"version": "0.1.1",
"description": "Promisify dgram module",
"main": "lib/dgram-as-promised.js",
"repository": {
Expand All @@ -27,8 +27,8 @@
"chai": "^3.5.0",
"nyc": "^10.1.2",
"standard": "^8.6.0",
"tap": "^10.1.2",
"tap-given": "^0.1.0"
"tap": "^10.2.0",
"tap-given": "^0.2.0"
},
"scripts": {
"test": "tap --timeout 20 test/*.js",
Expand Down
126 changes: 64 additions & 62 deletions test/dgram-as-promised.js
@@ -1,87 +1,89 @@
'use strict'

/* global scenario, given, when, then, after */
/* global Feature, Scenario, Given, When, Then, After */
const t = require('tap')
require('tap-given')(t)
require('chai').should()

const dgramAsPromised = require('../lib/dgram-as-promised')

scenario('Send datagram', function () {
given('socket', () => {
this.socket = dgramAsPromised.createSocket('udp4')
return this.socket
})
Feature('Test dgram-as-promised module', () => {
Scenario('Send datagram', function () {
Given('socket', () => {
this.socket = dgramAsPromised.createSocket('udp4')
return this.socket
})

when('socket is bound', () => {
return this.socket.bind()
})
When('socket is bound', () => {
return this.socket.bind()
})

when('membership is added', () => {
try {
this.address = '224.0.0.1'
this.socket.setBroadcast(true)
this.socket.setMulticastTTL(128)
this.socket.addMembership(this.address)
} catch (e) {
this.address = '127.0.0.1'
}
})
When('membership is added', () => {
try {
this.address = '224.0.0.1'
this.socket.setBroadcast(true)
this.socket.setMulticastTTL(128)
this.socket.addMembership(this.address)
} catch (e) {
this.address = '127.0.0.1'
}
})

when('correct message is sent', () => {
return this.socket.send(new Buffer('ABCDEFGH'), 0, 8, 41234, this.address)
})
When('correct message is sent', () => {
return this.socket.send(new Buffer('ABCDEFGH'), 0, 8, 41234, this.address)
})

when('socket is closed', () => {
return this.socket.close()
})
When('socket is closed', () => {
return this.socket.close()
})

when('I try to close again', () => {
return this.socket.close()
.catch(e => {
this.error = e
When('I try to close again', () => {
return this.socket.close()
.catch(e => {
this.error = e
})
})
})

then("can't be closed again", () => {
this.error.should.be.an('Error')
Then("can't be closed again", () => {
this.error.should.be.an('Error')
})
})
})

scenario("Can't send datagram", function () {
given('socket', () => {
this.socket = dgramAsPromised.createSocket('udp4')
return this.socket
})
Scenario("Can't send datagram", function () {
Given('socket', () => {
this.socket = dgramAsPromised.createSocket('udp4')
return this.socket
})

when('socket is bound', () => {
return this.socket.bind()
})
When('socket is bound', () => {
return this.socket.bind()
})

when('membership is added', () => {
try {
this.address = '224.0.0.1'
this.socket.setBroadcast(true)
this.socket.setMulticastTTL(128)
this.socket.addMembership(this.address)
} catch (e) {
this.address = '127.0.0.1'
}
})
When('membership is added', () => {
try {
this.address = '224.0.0.1'
this.socket.setBroadcast(true)
this.socket.setMulticastTTL(128)
this.socket.addMembership(this.address)
} catch (e) {
this.address = '127.0.0.1'
}
})

when('wrong message is sent', () => {
return this.socket.send('', 0, 0, null, null)
.catch(e => {
this.error = e
When('wrong message is sent', () => {
return this.socket.send('', 0, 0, null, null)
.catch(e => {
this.error = e
})
})
})

then("can't be sent", () => {
this.error.should.be.an('Error')
})
Then("can't be sent", () => {
this.error.should.be.an('Error')
})

after('close the socket', () => {
return this.socket.close()
.catch(e => {})
After('close the socket', () => {
return this.socket.close()
.catch(e => {})
})
})
})

0 comments on commit 1cfc7fa

Please sign in to comment.