Socket
Socket
Sign inDemoInstall

express-status-monitor

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-status-monitor - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.studio

6

package.json
{
"name": "express-status-monitor",
"version": "1.0.0",
"version": "1.0.1",
"description": "Realtime Monitoring for Express-based Node applications",

@@ -45,3 +45,3 @@ "main": "index.js",

"dependencies": {
"debug": "^2.6.8",
"debug": "^2.6.9",
"on-headers": "^1.0.1",

@@ -72,2 +72,2 @@ "pidusage": "^1.1.6",

"snyk": true
}
}

@@ -7,15 +7,13 @@ const chai = require('chai');

describe('helpers', () => {
describe('gather-os-metrics', () => {
describe('when invoked', () => {
it('then ...', () => {
const span = { os: [], responses: [] };
describe('gather-os-metrics', () => {
describe('when invoked', () => {
it('then ...', () => {
const span = { os: [], responses: [] };
gatherOsMetrics({}, span);
gatherOsMetrics({}, span);
// todo: not sure what should I test, maybe the resulted span structure?
// todo: also this component has got some internal timing events?
});
// todo: not sure what should I test, maybe the resulted span structure?
// todo: also this component has got some internal timing events?
});
});
});

@@ -9,38 +9,36 @@ const chai = require('chai');

describe('helpers', () => {
describe('on-headers-listener', () => {
describe('when invoked', () => {
const clock = sinon.useFakeTimers();
const spans = defaultConfig.spans;
describe('on-headers-listener', () => {
describe('when invoked', () => {
const clock = sinon.useFakeTimers();
const spans = defaultConfig.spans;
before(() => {
spans.forEach((span) => {
span.responses = [];
});
before(() => {
spans.forEach((span) => {
span.responses = [];
});
});
after(() => {
clock.restore();
});
after(() => {
clock.restore();
});
it('then for all spans, responses length should equal 1', () => {
onHeadersListener(404, process.hrtime(), spans);
it('then for all spans, responses length should equal 1', () => {
onHeadersListener(404, process.hrtime(), spans);
spans.forEach((span) => {
span.responses.length.should.equal(1);
});
spans.forEach((span) => {
span.responses.length.should.equal(1);
});
});
describe('when invoked after 1 second', () => {
it('then for span interval 1, responses length should equal 2', () => {
clock.tick(1000);
onHeadersListener(500, process.hrtime(), spans);
describe('when invoked after 1 second', () => {
it('then for span interval 1, responses length should equal 2', () => {
clock.tick(1000);
onHeadersListener(500, process.hrtime(), spans);
spans.forEach((span) => {
if (span.interval === 1) {
span.responses.length.should.equal(2);
} else {
span.responses.length.should.equal(1);
}
});
spans.forEach((span) => {
if (span.interval === 1) {
span.responses.length.should.equal(2);
} else {
span.responses.length.should.equal(1);
}
});

@@ -47,0 +45,0 @@ });

@@ -8,15 +8,13 @@ const chai = require('chai');

describe('helpers', () => {
describe('send-metrics', () => {
describe('when invoked', () => {
it('then io.emit called', () => {
const io = { emit: sinon.stub() };
const span = { os: [], responses: [] };
describe('send-metrics', () => {
describe('when invoked', () => {
it('then io.emit called', () => {
const io = { emit: sinon.stub() };
const span = { os: [], responses: [] };
sendMetrics(io, span);
sendMetrics(io, span);
sinon.assert.calledWith(io.emit, 'esm_stats');
});
sinon.assert.calledWith(io.emit, 'esm_stats');
});
});
});

@@ -8,20 +8,18 @@ const chai = require('chai');

describe('helpers', () => {
describe('socket-io-init', () => {
describe('when invoked', () => {
it('then all spans should have os and responses property', () => {
const spans = defaultConfig.spans;
describe('socket-io-init', () => {
describe('when invoked', () => {
it('then all spans should have os and responses property', () => {
const spans = defaultConfig.spans;
spans.forEach((span) => {
span.should.not.have.property('os');
// info: not working as if it was another test interfering
// span.should.not.have.property('responses');
});
spans.forEach((span) => {
span.should.not.have.property('os');
// info: not working as if it was another test interfering
// span.should.not.have.property('responses');
});
socketIoInit({}, defaultConfig);
socketIoInit({}, defaultConfig);
spans.forEach((span) => {
span.should.have.property('os');
span.should.have.property('responses');
});
spans.forEach((span) => {
span.should.have.property('os');
span.should.have.property('responses');
});

@@ -28,0 +26,0 @@ });

@@ -9,77 +9,75 @@ /* eslint-disable no-unused-expressions */

describe('helpers', () => {
describe('validate', () => {
describe('when config is null or undefined', () => {
const config = validate();
describe('validate', () => {
describe('when config is null or undefined', () => {
const config = validate();
it(`then title === ${defaultConfig.title}`, () => {
config.title.should.equal(defaultConfig.title);
});
it(`then title === ${defaultConfig.title}`, () => {
config.title.should.equal(defaultConfig.title);
});
it(`then path === ${defaultConfig.path}`, () => {
config.path.should.equal(defaultConfig.path);
});
it(`then path === ${defaultConfig.path}`, () => {
config.path.should.equal(defaultConfig.path);
});
it(`then spans === ${JSON.stringify(defaultConfig.spans)}`, () => {
config.spans.should.equal(defaultConfig.spans);
});
it(`then spans === ${JSON.stringify(defaultConfig.spans)}`, () => {
config.spans.should.equal(defaultConfig.spans);
});
it('then port === null', () => {
chai.expect(config.port).to.be.null;
});
it('then port === null', () => {
chai.expect(config.port).to.be.null;
});
it('then websocket === null', () => {
chai.expect(config.websocket).to.be.null;
});
it('then websocket === null', () => {
chai.expect(config.websocket).to.be.null;
});
});
describe('when config is invalid', () => {
const config = validate({ title: true, path: false, spans: 'not-an-array', port: 'abc', websocket: false });
describe('when config is invalid', () => {
const config = validate({ title: true, path: false, spans: 'not-an-array', port: 'abc', websocket: false });
it(`then title === ${defaultConfig.title}`, () => {
config.title.should.equal(defaultConfig.title);
});
it(`then title === ${defaultConfig.title}`, () => {
config.title.should.equal(defaultConfig.title);
});
it(`then path === ${defaultConfig.path}`, () => {
config.path.should.equal(defaultConfig.path);
});
it(`then path === ${defaultConfig.path}`, () => {
config.path.should.equal(defaultConfig.path);
});
it(`then spans === ${JSON.stringify(defaultConfig.spans)}`, () => {
config.spans.should.equal(defaultConfig.spans);
});
it(`then spans === ${JSON.stringify(defaultConfig.spans)}`, () => {
config.spans.should.equal(defaultConfig.spans);
});
it('then port === null', () => {
chai.expect(config.port).to.be.null;
});
it('then port === null', () => {
chai.expect(config.port).to.be.null;
});
it('then websocket === null', () => {
chai.expect(config.websocket).to.be.null;
});
it('then websocket === null', () => {
chai.expect(config.websocket).to.be.null;
});
});
describe('when config is valid', () => {
const customConfig = { title: 'Custom title', path: '/custom-path', spans: [{}, {}, {}], port: 9999, websocket: {} };
const config = validate(customConfig);
describe('when config is valid', () => {
const customConfig = { title: 'Custom title', path: '/custom-path', spans: [{}, {}, {}], port: 9999, websocket: {} };
const config = validate(customConfig);
it(`then title === ${customConfig.title}`, () => {
config.title.should.equal(customConfig.title);
});
it(`then title === ${customConfig.title}`, () => {
config.title.should.equal(customConfig.title);
});
it(`then path === ${customConfig.path}`, () => {
config.path.should.equal(customConfig.path);
});
it(`then path === ${customConfig.path}`, () => {
config.path.should.equal(customConfig.path);
});
it(`then spans === ${JSON.stringify(customConfig.spans)}`, () => {
config.spans.should.equal(customConfig.spans);
});
it(`then spans === ${JSON.stringify(customConfig.spans)}`, () => {
config.spans.should.equal(customConfig.spans);
});
it('then websocket === {}', () => {
config.websocket.should.deep.equal({});
});
it('then websocket === {}', () => {
config.websocket.should.deep.equal({});
});
it(`then port === ${customConfig.port}`, () => {
config.port.should.equal(customConfig.port);
});
it(`then port === ${customConfig.port}`, () => {
config.port.should.equal(customConfig.port);
});
});
});

@@ -9,7 +9,7 @@ const chai = require('chai');

describe('express-status-monitor', () => {
describe('middleware-wrapper', () => {
describe('when initialised', () => {
const middleware = expresStatusMonitor();
it('then it should be an instance of Function', () => {
it('then it should be an instance of a Function', () => {
middleware.should.be.an.instanceof(Function);

@@ -39,3 +39,23 @@ });

describe('and used as separate middlware and page handler', () => {
it('and res.removeHeader is present, then header is removed', () => {
const middlewareWithConfig = expresStatusMonitor({
iframe: true,
});
const resWithHeaders = Object.assign({}, res);
resWithHeaders.headers = {
'X-Frame-Options': 1,
};
resWithHeaders.removeHeader = sinon.stub();
middlewareWithConfig(req, resWithHeaders, next);
sinon.assert.called(resWithHeaders.removeHeader);
resWithHeaders.removeHeader = undefined;
resWithHeaders.remove = sinon.stub();
middlewareWithConfig(req, resWithHeaders, next);
sinon.assert.called(resWithHeaders.remove);
});
describe('and used as separate middleware and page handler', () => {
it('exposes a page handler', () => {

@@ -42,0 +62,0 @@ middleware.pageRoute.should.be.an.instanceof(Function);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc