koa-actuator
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -32,3 +32,7 @@ const path = require('path'); | ||
function findFilePathInProjectRootDir(fileName) { | ||
const pathsToSearchIn = [appRootPath + path.sep + fileName, process.cwd() + path.sep + fileName, '../../../' + fileName]; | ||
const pathsToSearchIn = [ | ||
appRootPath + path.sep + fileName, | ||
process.cwd() + path.sep + fileName, | ||
path.resolve(__dirname + '/../../../' + fileName) | ||
]; | ||
for (let idx in pathsToSearchIn) { | ||
@@ -35,0 +39,0 @@ const filePath = pathsToSearchIn[idx]; |
{ | ||
"name": "koa-actuator", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Healthcheck and monitoring middleware for koa inspired by java spring's actuators", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
"koa": "^2.2.0", | ||
"mocha": "^3.3.0", | ||
"mocha": "^5.2.0", | ||
"mock-require": "^3.0.1", | ||
@@ -28,0 +28,0 @@ "sinon": "^4.4.2", |
@@ -12,10 +12,19 @@ const Koa = require('koa'); | ||
let app; | ||
let server; | ||
beforeEach(() => { | ||
app = new Koa(); | ||
server = app.listen(); | ||
}); | ||
afterEach(() => server.close()); | ||
describe('/health', () => { | ||
it('should return 200 and status UP if no checks defined', (done) => { | ||
//arrange | ||
const app = new Koa(); | ||
app.use(actuator()); | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/health') | ||
@@ -30,6 +39,5 @@ .expect(200) | ||
const app = new Koa(); | ||
app.use(actuator({}, options)); | ||
request(app.callback()) | ||
request(server) | ||
.get('/custom-actuator-path/health') | ||
@@ -42,3 +50,2 @@ .expect(200) | ||
//arrange | ||
const app = new Koa(); | ||
app.use(actuator({ | ||
@@ -50,3 +57,3 @@ db: () => Promise.resolve({status: 'UP', freeConnections: 10}), | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/health') | ||
@@ -65,3 +72,2 @@ .expect(200) | ||
//arrange | ||
const app = new Koa(); | ||
app.use(actuator({ | ||
@@ -73,3 +79,3 @@ db: () => Promise.resolve({status: 'UP', freeConnections: 10}), | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/health') | ||
@@ -88,3 +94,2 @@ .expect(503) | ||
//arrange | ||
const app = new Koa(); | ||
app.use(actuator({ | ||
@@ -98,3 +103,3 @@ db: () => { | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/health') | ||
@@ -113,3 +118,2 @@ .expect(503) | ||
//arrange | ||
const app = new Koa(); | ||
app.use(actuator({ | ||
@@ -121,3 +125,3 @@ db: () => Promise.resolve({status: 'UP', freeConnections: 10}), | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/health') | ||
@@ -136,3 +140,2 @@ .expect(503) | ||
//arrange | ||
const app = new Koa(); | ||
const options = {checkTimeout: 100}; | ||
@@ -144,3 +147,3 @@ app.use(actuator({ | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/health') | ||
@@ -171,7 +174,6 @@ .expect(503) | ||
//arrange | ||
const app = new Koa(); | ||
app.use(actuator()); | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/info') | ||
@@ -190,7 +192,6 @@ .expect(200) | ||
const app = new Koa(); | ||
app.use(actuator({}, options)); | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/custom-actuator-path/info') | ||
@@ -212,7 +213,6 @@ .expect(200) | ||
const app = new Koa(); | ||
app.use(actuator()); | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/info') | ||
@@ -245,7 +245,6 @@ .expect(200) | ||
//arrange | ||
const app = new Koa(); | ||
app.use(actuator()); | ||
//act & assert | ||
request(app.callback()) | ||
request(server) | ||
.get('/actuator/info') | ||
@@ -252,0 +251,0 @@ .expect(200) |
@@ -35,7 +35,7 @@ const appRootPath = require('app-root-path'); | ||
it('should require package.json from relative path if CWD fails', () => { | ||
sandbox.stub(fs, 'existsSync').withArgs('../../../package.json').returns(true); | ||
sandbox.stub(fs, 'existsSync').withArgs(path.resolve(__dirname + '/../../../package.json')).returns(true); | ||
const mockedPackageJson = {description: 'package.json from relative path'}; | ||
mock(appRootPath + path.sep + 'package.json', 'not_exiting'); | ||
mock(process.cwd() + path.sep + 'package.json', 'not_existing'); | ||
mock('../../../package.json', mockedPackageJson); | ||
mock(path.resolve(__dirname + '/../../../package.json'), mockedPackageJson); | ||
const utils = mock.reRequire('../lib/utils'); | ||
@@ -42,0 +42,0 @@ |
19834