Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
test: run tests on webworkers (#19)
Browse files Browse the repository at this point in the history
* wip

* test: use dirty-chai

* chore: upgrading webcrypto version

* feat: add test:webworker
  • Loading branch information
daviddias authored Dec 13, 2017
1 parent 0de6397 commit 0789414
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ You will need to use Node.js `Buffer` API compatible, if you are running inside

```js
var multihashing = require('multihashing')
var buf = new Buffer('beep boop')
var buf = Buffer.from('beep boop')

// by default returns a multihash.
multihashing(buf, 'sha1')
Expand All @@ -98,7 +98,7 @@ h.digest()

```js
> var multihashing = require('multihashing')
> var buf = new Buffer('beep boop')
> var buf = Buffer.from('beep boop')

> console.log(multihashing(buf, 'sha1'))
// => <Buffer 11 14 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
Expand All @@ -114,7 +114,7 @@ h.digest()

```js
> var multihashing = require('multihashing')
> var buf = new Buffer('beep boop')
> var buf = Buffer.from('beep boop')

> console.log(multihashing.digest(buf, 'sha1'))
// => <SlowBuffer 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
Expand Down
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
"description": "multiple hash functions",
"main": "src/index.js",
"scripts": {
"test": "aegir-test --webworker=false",
"test:browser": "aegir-test browser --webworker=false",
"test:node": "aegir-test node",
"lint": "aegir-lint",
"release": "aegir-release --webworker=false --dom",
"release-minor": "aegir-release minor --webworker=false",
"release-major": "aegir-release major --webworker=false",
"build": "aegir-build",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
"lint": "aegir lint",
"build": "aegir build",
"test": "aegir test -t node -t browser -t webworker",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"test:webworker": "aegir test -t webworker",
"release": "aegir release -t node -t browser",
"release-minor": "aegir release --type minor -t node -t browser",
"release-major": "aegir release --type major -t node -t browser",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls"
},
"pre-commit": [
"lint",
Expand All @@ -34,11 +35,12 @@
"dependencies": {
"blakejs": "^1.0.1",
"multihashes": "~0.4.4",
"webcrypto": "~0.1.0"
"webcrypto": "~0.1.1"
},
"devDependencies": {
"aegir": "^11.0.0",
"aegir": "^12.2.0",
"chai": "^3.5.0",
"dirty-chai": "^1.2.2",
"pre-commit": "^1.2.2"
},
"homepage": "https://github.com/multiformats/js-multihashing",
Expand All @@ -51,4 +53,4 @@
"Richard Littauer <richard.littauer@gmail.com>",
"npm-to-cdn-bot (by Forbes Lindesay) <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]
}
}
2 changes: 1 addition & 1 deletion src/blake.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class B2Hash {
digest () {
const ctx = this.ctx
this.ctx = null
return new Buffer(this.hf.digest(ctx))
return Buffer.from(this.hf.digest(ctx))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const multihash = require('multihashes')
const crypto = require('webcrypto')
const blake = require('./blake')
const crypto = require('webcrypto')

const mh = module.exports = Multihashing

Expand Down
35 changes: 19 additions & 16 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,86 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
const dirtyChai = require('dirty-chai')
chai.use(dirtyChai)
const expect = chai.expect
const multihashing = require('../src')

describe('multihashing', () => {
it('sha1', () => {
const buf = new Buffer('beep boop')
const buf = Buffer.from('beep boop')

expect(
multihashing(buf, 'sha1')
).to.be.eql(
new Buffer('11147c8357577f51d4f0a8d393aa1aaafb28863d9421', 'hex')
Buffer.from('11147c8357577f51d4f0a8d393aa1aaafb28863d9421', 'hex')
)
})

it('sha2-256', () => {
const buf = new Buffer('beep boop')
const buf = Buffer.from('beep boop')

expect(
multihashing(buf, 'sha2-256')
).to.be.eql(
new Buffer('122090ea688e275d580567325032492b597bc77221c62493e76330b85ddda191ef7c', 'hex')
Buffer.from('122090ea688e275d580567325032492b597bc77221c62493e76330b85ddda191ef7c', 'hex')
)
})

it('sha2-512', () => {
const buf = new Buffer('beep boop')
const buf = Buffer.from('beep boop')

expect(
multihashing(buf, 'sha2-512')
).to.be.eql(
new Buffer('134014f301f31be243f34c5668937883771fa381002f1aaa5f31b3f78e500b66ff2f4f8ea5e3c9f5a61bd073e2452c480484b02e030fb239315a2577f7ae156af177', 'hex')
Buffer.from('134014f301f31be243f34c5668937883771fa381002f1aaa5f31b3f78e500b66ff2f4f8ea5e3c9f5a61bd073e2452c480484b02e030fb239315a2577f7ae156af177', 'hex')
)
})

it('blake2b', () => {
const buf = new Buffer('beep boop')
const buf = Buffer.from('beep boop')

expect(
multihashing(buf, 'blake2b-512')
).to.be.eql(
new Buffer('c0e402400eac6255ba822373a0948122b8d295008419a8ab27842ee0d70eca39855621463c03ec75ac3610aacfdff89fa989d8d61fc00450148f289eb5b12ad1a954f659', 'hex')
Buffer.from('c0e402400eac6255ba822373a0948122b8d295008419a8ab27842ee0d70eca39855621463c03ec75ac3610aacfdff89fa989d8d61fc00450148f289eb5b12ad1a954f659', 'hex')
)
expect(
multihashing(buf, 'blake2b-160')
).to.be.eql(
new Buffer('94e40214fe303247293e54e0a7ea48f9408ca68b36b08442', 'hex')
Buffer.from('94e40214fe303247293e54e0a7ea48f9408ca68b36b08442', 'hex')
)
})

it('blake2s', () => {
const buf = new Buffer('beep boop')
const buf = Buffer.from('beep boop')

expect(
multihashing(buf, 'blake2s-256')
).to.be.eql(
new Buffer('e0e402204542eaca484e4311def8af74b546edd7fceb49eeb3cdcfd8a4a72ed0dc81d4c0', 'hex')
Buffer.from('e0e402204542eaca484e4311def8af74b546edd7fceb49eeb3cdcfd8a4a72ed0dc81d4c0', 'hex')
)
expect(
multihashing(buf, 'blake2s-40')
).to.be.eql(
new Buffer('c5e402059ada01bb57', 'hex')
Buffer.from('c5e402059ada01bb57', 'hex')
)
})

it('cuts the length', () => {
const buf = new Buffer('beep boop')
const buf = Buffer.from('beep boop')

expect(
multihashing(buf, 'sha2-256', 10)
).to.be.eql(
new Buffer('120a90ea688e275d58056732', 'hex')
Buffer.from('120a90ea688e275d58056732', 'hex')
)
})

it('throws on non implemented func', () => {
expect(
() => multihashing(new Buffer('beep boop'), 'sha3')
() => multihashing(Buffer.from('beep boop'), 'sha3')
).to.throw(
/Unrecognized hash function named:/
)
Expand Down

0 comments on commit 0789414

Please sign in to comment.