add unit test, fix dev dependencies, add Makefile

This commit is contained in:
Konstantin Pogorelov
2016-04-18 17:34:37 +02:00
parent 616e5daacc
commit 3ae9394154
4 changed files with 34 additions and 5 deletions

4
Makefile Normal file
View File

@@ -0,0 +1,4 @@
test:
./node_modules/jasme/run.js
lint:
node_modules/eslint/bin/eslint.js .

View File

@@ -1,7 +1,7 @@
{
"name": "express-prom-bundle",
"version": "1.0.0",
"description": "express middleware with standard prometheus metrics in one bundle",
"description": "express middleware with popular prometheus metrics in one bundle",
"main": "src/index.js",
"directories": {
"test": "test"
@@ -16,6 +16,9 @@
"prom-client": "^3.4.0"
},
"devDependencies": {
"eslint": "^2.8.0"
"eslint": "^2.8.0",
"express": "^4.13.4",
"jasme": "^4.1.1",
"supertest": "^1.2.0"
}
}

24
spec/indexSpec.js Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
/* eslint-env jasmine */
let express = require("express"),
request = require("supertest"),
bundle = require("../");
describe("index", () => {
const app = express();
app.use(bundle({
prefix: "hello"
}));
it("/metrics returns up=1", done => {
request(app)
.get("/metrics")
.end((err, res) => {
expect(res.status).toBe(200);
expect(res.text).toMatch(/hello:up\s1/);
done();
});
});
});

View File

@@ -1,9 +1,7 @@
"use strict";
const onFinished = require("on-finished");
module.exports = class {
constructor(opts, promClient) {
constructor(opts) {
this.opts = opts || {};
this.promClient = this.opts.promClient || require("prom-client");
this.metrics = {};