add coverage, fix codestyle

This commit is contained in:
David Dias 2016-02-14 07:32:09 +00:00
parent 1f72aaf7b7
commit 845bd088fe
4 changed files with 19 additions and 7 deletions

View File

@ -1,7 +1,7 @@
peer-id JavaScript implementation
==============================
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/diasdavid/js-peer-id.svg?style=flat-square)](https://travis-ci.org/diasdavid/js-peer-id) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/diasdavid/js-peer-id) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/diasdavid/js-peer-id.svg?style=flat-square)](https://travis-ci.org/diasdavid/js-peer-id) ![](https://img.shields.io/badge/coverage-95%25-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/diasdavid/js-peer-id) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
> IPFS Peer Id implementation in JavaScript
# Description

View File

@ -4,10 +4,11 @@
"description": "IPFS Peer Id implementation in Node.js",
"main": "src/index.js",
"scripts": {
"test:node": "mocha tests/test.js",
"lint": "standard",
"test": "npm run test:node && npm run test:browser",
"test:browser": "karma start karma.conf.js"
"test:node": "mocha tests/test.js",
"test:browser": "karma start karma.conf.js",
"coverage": "istanbul cover --print both -- _mocha tests/test.js"
},
"keywords": [
"IPFS"
@ -20,7 +21,8 @@
],
"standard": {
"ignore": [
"dist"
"dist",
"deps"
]
},
"engines": {
@ -33,6 +35,7 @@
"devDependencies": {
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"istanbul": "^0.4.2",
"json-loader": "^0.5.4",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",

View File

@ -11,7 +11,8 @@ var protobuf = require('protocol-buffers')
var isNode = !global.window
// protobuf read from file
var messages = isNode ? protobuf(fs.readFileSync(__dirname + '/../pb/crypto.proto')) : protobuf(require('buffer!./../pb/crypto.proto'))
var messages = isNode ? protobuf(fs.readFileSync(__dirname + '/../pb/crypto.proto'))
: protobuf(require('buffer!./../pb/crypto.proto'))
exports = module.exports = Id

View File

@ -1,3 +1,5 @@
/* globals describe, it */
'use strict'
const expect = require('chai').expect
@ -17,31 +19,37 @@ const testIdB58String = 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A'
describe('id', function (done) {
this.timeout(30000)
it('create a new id', done => {
var id = PeerId.create()
expect(id.toB58String().length).to.equal(46)
done()
})
it('recreate an Id from Hex string', done => {
var id = PeerId.createFromHexString(testIdHex)
expect(testIdBytes).to.deep.equal(id.id)
done()
})
it('Recreate an Id from a Buffer', done => {
var id = PeerId.createFromBytes(testIdBytes)
expect(testId.id).to.equal(id.toHexString())
done()
})
it('Recreate a B58 String', done => {
var id = PeerId.createFromB58String(testIdB58String)
expect(testIdB58String).to.equal(id.toB58String())
done()
})
it('Recreate from a Public Key', done => {
var id = PeerId.createFromPubKey(testId.pubKey)
expect(testIdB58String).to.equal(id.toB58String())
done()
})
it('Recreate from a Private Key', done => {
var id = PeerId.createFromPrivKey(testId.privKey)
expect(testIdB58String).to.equal(id.toB58String())