Skip to content

Commit

Permalink
Merge branch 'master' into feature/custom_queue_group
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed Jul 9, 2017
2 parents 8b556d3 + f43165b commit c6d4da7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/hemera/lib/index.js
Expand Up @@ -1204,6 +1204,8 @@ class Hemera extends EventEmitter {
.then(x => resolve(x))
.catch(x => reject(x))
} else {
// any return value in a callback function will fullfilled the
// promise but an error will reject it
const r = ctx._actCallback(err, result)
if (r instanceof Error) {
reject(r)
Expand Down
49 changes: 48 additions & 1 deletion test/hemera-plugin/index.spec.js
Expand Up @@ -47,7 +47,6 @@ describe('Hemera plugin', function () {

const hemera = new Hemera(nats)
const throws = function () {

// Plugin
let plugin = HemeraPlugin(function (opts, next) {
next()
Expand All @@ -68,4 +67,52 @@ describe('Hemera plugin', function () {
hemera.close()
done()
})

it('Should throw an error because plugin function is not a function', function (done) {
const nats = require('nats').connect(authUrl)

const hemera = new Hemera(nats)
const throws = function () {
// Plugin
let plugin = HemeraPlugin(true, '1')

hemera.use({
plugin: plugin,
attributes: {
name: 'myPlugin'
},
options: {}
})

hemera.ready()
}

expect(throws).to.throw(Error, 'hemera-plugin expects a function, instead got a \'boolean\'')
hemera.close()
done()
})

it('Should throw an error because plugin version is not a string', function (done) {
const nats = require('nats').connect(authUrl)

const hemera = new Hemera(nats)
const throws = function () {
// Plugin
let plugin = HemeraPlugin(() => {}, true)

hemera.use({
plugin: plugin,
attributes: {
name: 'myPlugin'
},
options: {}
})

hemera.ready()
}

expect(throws).to.throw(Error, 'hemera-plugin expects a version string as second parameter, instead got \'boolean\'')
hemera.close()
done()
})
})
2 changes: 2 additions & 0 deletions test/hemera/async-await.node8.js
Expand Up @@ -429,6 +429,8 @@ describe('Async / Await support', function () {
return await Promise.reject(new Error('test'))
})

// in future we have to try catch it

hemera.act({
topic: 'math',
cmd: 'add',
Expand Down
2 changes: 1 addition & 1 deletion test/hemera/extensions.spec.js
Expand Up @@ -16,7 +16,7 @@ describe('Extension reply', function () {
server.kill()
})

it('Should be bale to reply an error', function (done) {
it('Should be able to reply an error', function (done) {
let ext1 = Sinon.spy()
let ext2 = Sinon.spy()

Expand Down
2 changes: 2 additions & 0 deletions test/hemera/generator-promise.spec.js
Expand Up @@ -483,6 +483,8 @@ describe('Generator / Promise support', function () {
return yield Promise.reject(new Error('test'))
})

// in future we have to try catch it

hemera.act({
topic: 'math',
cmd: 'add',
Expand Down
20 changes: 20 additions & 0 deletions test/hemera/unit/util.spec.js
Expand Up @@ -20,4 +20,24 @@ describe('Util', function () {
expect(regex2).to.be.equals(/^a.[a-zA-Z0-9\-\.]+$/i)
done()
})

it('Should be able to detect async function', function (done) {
const a = HemeraUtil.isAsyncFunction(async function test () {})
const b = HemeraUtil.isAsyncFunction(function test () {})
const c = HemeraUtil.isAsyncFunction('')
expect(a).to.be.equals(true)
expect(b).to.be.equals(false)
expect(c).to.be.equals(false)
done()
})

it('Should be able to detect generator function', function (done) {
const a = HemeraUtil.isGeneratorFunction(function * test () {})
const b = HemeraUtil.isGeneratorFunction(function test () {})
const c = HemeraUtil.isGeneratorFunction('')
expect(a).to.be.equals(true)
expect(b).to.be.equals(false)
expect(c).to.be.equals(false)
done()
})
})

0 comments on commit c6d4da7

Please sign in to comment.