Skip to content

Commit

Permalink
Updated readme and added node 6 as test target
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Potsides committed Nov 10, 2016
1 parent 22d2628 commit db30cda
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "4.0"
- "5.0"
- "6.0"
script: npm run test:coverage
after_script: npm run coveralls
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -5,7 +5,20 @@ Like [freeport](https://libraries.io/npm/freeport) but with promises.

```javascript
freeport()
.then((port) => {
.then(port => {
console.log(port)
})
```

## Using other promise libraries

By default we use the language-level `Promise` class, but if you want to use a different implementation, just pass it in as an argument:

```javascript
const bluebird = require('bluebird')

freeport(bluebird)
.then(port => {
console.log(port)
})
```
6 changes: 3 additions & 3 deletions lib/freeport.js
@@ -1,9 +1,9 @@
var net = require('net')
const net = require('net')

module.exports = (PromiseLibrary) => {
module.exports = PromiseLibrary => {
PromiseLibrary = PromiseLibrary || Promise
return new PromiseLibrary((resolve, reject) => {
var server = net.createServer()
const server = net.createServer()
var port = 0

server.once('listening', () => {
Expand Down
16 changes: 9 additions & 7 deletions test/freeport.js
@@ -1,20 +1,22 @@
var freeport = require('../lib/freeport')
var expect = require('chai').expect
var describe = require('mocha').describe
var it = require('mocha').it
const freeport = require('../lib/freeport')
const expect = require('chai').expect
const describe = require('mocha').describe
const it = require('mocha').it

describe('freeport', () => {
it('should find a free port', () => {
return freeport()
.then((port) => {
.then(port => {
expect(port).to.be.a('number')
expect(port).to.not.equal(0)
})
})

it('should work with a external promise library', () => {
var bluebird = require('bluebird')
const bluebird = require('bluebird')

return freeport(bluebird)
.then((port) => {
.then(port => {
expect(port).to.be.a('number')
expect(port).to.not.equal(0)
})
Expand Down

0 comments on commit db30cda

Please sign in to comment.