Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Changelog | ||
|
||
## v0.1.1 2017-02-19 | ||
|
||
* Upgraded tap-given | ||
|
||
## v0.1.0 2017-02-18 | ||
|
||
* ES6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 => {}) | ||
}) | ||
}) | ||
}) |