Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
.nyc_output
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ language: node_js
sudo: false

node_js:
- "8"
- "10"
- "11"
- "8.10.0"
- "10.0.0"
- "11.0.0"

script:
- npm install
- npm run test
- NODE_VERSION=$(echo $(node -v) | cut -c2-10) npm run test

before_script:
# install nats
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG BUILD_VERSION=8.10.0
FROM mhart/alpine-node:$BUILD_VERSION
MAINTAINER FelipeBarrosCruz <[email protected]>

RUN apk add --update \
make \
gcc \
g++ \
python \
git

WORKDIR /src

ADD package.json package-lock.json ./
RUN npm install

ADD / ./

CMD ["npm", "run", "lib:test"]
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3'
services:
nats:
image: 'nats:latest'
entrypoint: "/gnatsd -DV"
logging:
driver: none
expose:
- "4222"
ports:
- "4222:4222"
- "8222:8222"
lib-test:
tty: true
build:
context: .
dockerfile: Dockerfile
args:
BUILD_VERSION: ${NODE_VERSION}
environment:
- NATS_URL=nats://nats:4222
links:
- nats
depends_on:
- nats
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ async function register(server, options) {
}

internals.handler = (route, options) => {
return function hemeraHapiHandler(request) {
return request.hemera.act(internals.getPatternFromRequest(request, options.pattern))
return async function hemeraHapiHandler(request, h) {
const data = await request.hemera.act(internals.getPatternFromRequest(request, options.pattern))
return h.response(data).code(options.statusCode || 200)
}
}

Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@
"hemera-testsuite": "^4.1.0",
"istanbul": "^0.4.5",
"joi": "^14.3.1",
"mocha": "^6.0.2",
"mocha": "^6.1.3",
"mocha-lcov-reporter": "^1.3.0",
"np": "^4.0.2",
"nyc": "^14.0.0",
"prettier": "^1.16.4",
"sinon": "^7.2.7"
},
"scripts": {
"test": "mocha --exit -t 5000 --recursive",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec -t 5000 --recursive",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report text-lcov -- -R spec | node ./node_modules/coveralls/bin/coveralls.js",
"test": "docker-compose up --build --force-recreate --exit-code-from=lib-test",
"lib:test": "mocha --exit -t 5000 --recursive",
"lib:coverage": "istanbul cover node_modules/.bin/mocha -- -R spec -t 5000 --recursive",
"lib:coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report text-lcov -- -R spec | node ./node_modules/coveralls/bin/coveralls.js",
"lint": "eslint .",
"format": "prettier --write ./lib/**/*.js ./test/**/*.js",
"patch": "np patch --yolo",
Expand Down
21 changes: 7 additions & 14 deletions test/action-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@

const Code = require('code')
const Hapi = require('hapi')
const HemeraTestsuite = require('hemera-testsuite')
const HapiHemera = require('../')

const { expect } = Code

describe('Action Mapping', function() {
const PORT = 6242
const noAuthUrl = `nats://localhost:${PORT}`
let natsServer

// Start up our own nats-server
before(function(done) {
natsServer = HemeraTestsuite.start_server(PORT, done)
})

// Shutdown our server after we are done
after(function() {
natsServer.kill()
})
const noAuthUrl = process.env.NATS_URL || `nats://localhost:4222`

it('Maps an action to a server method', async () => {
const server = new Hapi.Server()
await server.register({
plugin: HapiHemera,
options: {
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down Expand Up @@ -62,6 +52,9 @@ describe('Action Mapping', function() {
await server.register({
plugin: HapiHemera,
options: {
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down
24 changes: 10 additions & 14 deletions test/base-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@

const Code = require('code')
const Hapi = require('hapi')
const HemeraTestsuite = require('hemera-testsuite')
const HapiHemera = require('../')

const { expect } = Code

describe('Base Pattern', function() {
const PORT = 6242
const noAuthUrl = `nats://localhost:${PORT}`
let natsServer

// Start up our own nats-server
before(function(done) {
natsServer = HemeraTestsuite.start_server(PORT, done)
})

// Shutdown our server after we are done
after(function() {
natsServer.kill()
})
const noAuthUrl = process.env.NATS_URL || `nats://localhost:4222`

it('Should be able to create base pattern with function', async () => {
const server = new Hapi.Server()
Expand All @@ -33,6 +20,9 @@ describe('Base Pattern', function() {
}
return basePattern
},
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down Expand Up @@ -63,6 +53,9 @@ describe('Base Pattern', function() {
basePattern: {
a: 1
},
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down Expand Up @@ -94,6 +87,9 @@ describe('Base Pattern', function() {
a: 1,
b: 2
},
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down
23 changes: 7 additions & 16 deletions test/basic-custominstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@ const Code = require('code')
const Hapi = require('hapi')
const Hemera = require('nats-hemera')
const Nats = require('nats')
const HemeraTestsuite = require('hemera-testsuite')
const HapiHemera = require('../')

const { expect } = Code

describe('Custom Hemera instance', function() {
const PORT = 6242
const noAuthUrl = `nats://localhost:${PORT}`
let natsServer

// Start up our own nats-server
before(function(done) {
natsServer = HemeraTestsuite.start_server(PORT, done)
})

// Shutdown our server after we are done
after(function() {
natsServer.kill()
})
const noAuthUrl = process.env.NATS_URL || `nats://localhost:4222`

it('Connect to NATS', async () => {
const server = new Hapi.Server()
const hemeraInstance = new Hemera(Nats.connect({ url: noAuthUrl }))
const hemeraInstance = new Hemera(Nats.connect({ url: noAuthUrl }), {
logLevel: 'silent'
})
await server.register({
plugin: HapiHemera,
options: {
Expand All @@ -38,7 +27,9 @@ describe('Custom Hemera instance', function() {

it('Add / Act', async () => {
const server = new Hapi.Server()
const hemeraInstance = new Hemera(Nats.connect({ url: noAuthUrl }))
const hemeraInstance = new Hemera(Nats.connect({ url: noAuthUrl }), {
logLevel: 'silent'
})
await server.register({
plugin: HapiHemera,
options: {
Expand Down
21 changes: 7 additions & 14 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@

const Code = require('code')
const Hapi = require('hapi')
const HemeraTestsuite = require('hemera-testsuite')
const HapiHemera = require('../')

const { expect } = Code

describe('Basic', function() {
const PORT = 6242
const noAuthUrl = `nats://localhost:${PORT}`
let natsServer

// Start up our own nats-server
before(function(done) {
natsServer = HemeraTestsuite.start_server(PORT, done)
})

// Shutdown our server after we are done
after(function() {
natsServer.kill()
})
const noAuthUrl = process.env.NATS_URL || `nats://localhost:4222`

it('Connect to NATS', async () => {
const server = new Hapi.Server()
await server.register({
plugin: HapiHemera,
options: {
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand All @@ -40,6 +30,9 @@ describe('Basic', function() {
await server.register({
plugin: HapiHemera,
options: {
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down
25 changes: 10 additions & 15 deletions test/handler-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,21 @@

const Code = require('code')
const Hapi = require('hapi')
const HemeraTestsuite = require('hemera-testsuite')
const HapiHemera = require('../')

const { expect } = Code

describe('Handler decorator', function() {
const PORT = 6242
const noAuthUrl = `nats://localhost:${PORT}`
const flags = []
let natsServer

// Start up our own nats-server
before(function(done) {
natsServer = HemeraTestsuite.start_server(PORT, flags, done)
})

// Shutdown our server after we are done
after(function() {
natsServer.kill()
})
const noAuthUrl = process.env.NATS_URL || `nats://localhost:4222`

it('Should be able to use handler decorators with query', async () => {
const server = new Hapi.Server()
await server.register({
plugin: HapiHemera,
options: {
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down Expand Up @@ -71,6 +60,9 @@ describe('Handler decorator', function() {
await server.register({
plugin: HapiHemera,
options: {
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down Expand Up @@ -115,6 +107,9 @@ describe('Handler decorator', function() {
await server.register({
plugin: HapiHemera,
options: {
hemera: {
logLevel: 'silent'
},
nats: {
url: noAuthUrl
}
Expand Down
Loading