Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mockyeah

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockyeah - npm Package Compare versions

Comparing version 0.15.8 to 0.15.9

6

app/lib/RouteResolver.js

@@ -136,6 +136,6 @@ 'use strict';

RouteResolver.prototype.unregister = function unregister(routes) {
const routePaths = routes.map((route) => { return route.path; });
this.app._router.stack = this.app._router.stack.filter((layer) => {
return !(layer.route && routePaths.indexOf(layer.route.path) >= 0);
return !(layer.route && routes.some((route) => {
return route.path === layer.route.path && layer.route.methods[route.method] === true;
}));
});

@@ -142,0 +142,0 @@ };

{
"name": "mockyeah",
"version": "0.15.8",
"version": "0.15.9",
"description": "A powerful service mocking, recording, and playback utility.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -35,26 +35,26 @@ # mockyeah [![Build Status](https://travis-ci.org/ryanricard/mockyeah.svg)](https://travis-ci.org/ryanricard/mockyeah)

1. Create an example project and initialized with NPM
```shell
$ mkdir example-app && cd example-app
$ npm init # all defaults will be fine
```
```shell
$ mkdir example-app && cd example-app
$ npm init # all defaults will be fine
```
1. Install `mockyeah`
```shell
$ npm install mockyeah --save-dev
```
```shell
$ npm install mockyeah --save-dev
```
1. Create script file and add the source below
```shell
$ touch index.js
```
```js
const mockyeah = require('mockyeah');
```shell
$ touch index.js
```
```js
const mockyeah = require('mockyeah');
mockyeah.get('/hello-world', { text: 'Hello World' });
```
mockyeah.get('/hello-world', { text: 'Hello World' });
```
1. Run the script file with Node
```shell
$ node index.js
```
```shell
$ node index.js
```

@@ -96,5 +96,23 @@ 1. Open [http://localhost:4001/hello-world](http://localhost:4001/hello-world)

});
it('should verify a mock service expectation', (done) => {
// create service mock with expectation
const expectation = mockyeah
.get('/wondrous', { text: 'it worked' })
.expect()
.params({
foo: 'bar'
})
.once();
// invoke request and verify expectation
request
.get('/wondrous?foo=bar')
.expect(200, 'it worked')
.then(() => {
expectation.verify();
done();
});
});
});
```

@@ -15,24 +15,29 @@ 'use strict';

describe('Capture Record and Playback', function() {
let request;
let proxy;
let remote;
let getRemotePath;
let proxyReq;
let remoteReq;
before(() => {
// Instantiate proxy server for recording
proxy = MockYeahServer({
name: 'proxy',
port: 0,
capturesDir: PROXY_CAPTURES_DIR
before((done) => {
async.parallel([
function(cb) {
// Instantiate proxy server for recording
proxy = MockYeahServer({
name: 'proxy',
port: 0,
capturesDir: PROXY_CAPTURES_DIR
}, cb);
},
function(cb) {
// Instantiate remote server
remote = MockYeahServer({
name: 'remote',
port: 0
}, cb);
}
], () => {
remoteReq = supertest(remote.server);
proxyReq = supertest(proxy.server.rootUrl + '/' + remote.server.rootUrl);
done();
});
// Instantiate remote server
remote = MockYeahServer({
name: 'remote',
port: 0
});
request = supertest(proxy.server);
getRemotePath = (_path) => `/http://localhost:${remote.server.address().port}${_path}`;
});

@@ -51,4 +56,4 @@

function getCaptureFilePath(captureName, remoteUrl) {
const fileName = remoteUrl.replace(/^\/?/, '').replace(/\//g, '|');
function getCaptureFilePath(captureName, _path) {
const fileName = _path.replace(/^\/?/, '').replace(/\//g, '|');
return path.resolve(PROXY_CAPTURES_DIR, captureName, fileName);

@@ -58,2 +63,4 @@ }

it('should record and playback capture', function(done) {
this.timeout = 10000;
const captureName = 'some-fancy-capture';

@@ -63,14 +70,14 @@

// e.g. http://localhost:4041/http://example.com/some/service
const remoteUrl1 = getRemotePath('/some/service/one');
const remoteUrl2 = getRemotePath('/some/service/two');
const remoteUrl3 = getRemotePath('/some/service/three');
const remoteUrl4 = getRemotePath('/some/service/four');
const remoteUrl5 = getRemotePath('/some/service/five');
const path1 = '/some/service/one';
const path2 = '/some/service/two';
const path3 = '/some/service/three';
const path4 = '/some/service/four';
const path5 = '/some/service/five';
// Determine file save locations from capture name and remote service urls
const filePath1 = getCaptureFilePath(captureName, remoteUrl1);
const filePath2 = getCaptureFilePath(captureName, remoteUrl2);
const filePath3 = getCaptureFilePath(captureName, remoteUrl3);
const filePath4 = getCaptureFilePath(captureName, remoteUrl4);
const filePath5 = getCaptureFilePath(captureName, remoteUrl5);
const filePath1 = getCaptureFilePath(captureName, remote.server.rootUrl + path1);
const filePath2 = getCaptureFilePath(captureName, remote.server.rootUrl + path2);
const filePath3 = getCaptureFilePath(captureName, remote.server.rootUrl + path3);
const filePath4 = getCaptureFilePath(captureName, remote.server.rootUrl + path4);
const filePath5 = getCaptureFilePath(captureName, remote.server.rootUrl + path5);

@@ -91,7 +98,7 @@ // Mount remote service end points

// e.g. http://localhost:4041/http://example.com/some/service
(cb) => request.get(remoteUrl1).expect(200, 'first', cb),
(cb) => request.get(remoteUrl2).expect(200, 'second', cb),
(cb) => request.get(remoteUrl3).expect(200, 'third', cb),
(cb) => request.get(remoteUrl4).expect(200, 'fourth', cb),
(cb) => request.get(remoteUrl5).expect(200, 'fifth', cb),
(cb) => proxyReq.get(path1).expect(200, 'first', cb),
(cb) => proxyReq.get(path2).expect(200, 'second', cb),
(cb) => proxyReq.get(path3).expect(200, 'third', cb),
(cb) => proxyReq.get(path4).expect(200, 'fourth', cb),
(cb) => proxyReq.get(path5).expect(200, 'fifth', cb),

@@ -112,17 +119,17 @@ // Assert files exist

// e.g. http://localhost:4041/http://example.com/some/service
(cb) => request.get(remoteUrl1).expect(200, 'first', cb),
(cb) => request.get(remoteUrl2).expect(200, 'second', cb),
(cb) => request.get(remoteUrl3).expect(200, 'third', cb),
(cb) => request.get(remoteUrl4).expect(200, 'fourth', cb),
(cb) => request.get(remoteUrl5).expect(200, 'fifth', cb),
(cb) => remoteReq.get(path1).expect(200, 'first', cb),
(cb) => remoteReq.get(path2).expect(200, 'second', cb),
(cb) => remoteReq.get(path3).expect(200, 'third', cb),
(cb) => remoteReq.get(path4).expect(200, 'fourth', cb),
(cb) => remoteReq.get(path5).expect(200, 'fifth', cb),
// Assert paths are routed the correct responses
// e.g. http://localhost:4041/some/service
(cb) => request.get('/some/service/one').expect(200, 'first', cb),
(cb) => request.get('/some/service/two').expect(200, 'second', cb),
(cb) => request.get('/some/service/three').expect(200, 'third', cb),
(cb) => request.get('/some/service/four').expect(200, 'fourth', cb),
(cb) => request.get('/some/service/five').expect(200, 'fifth', cb)
(cb) => proxyReq.get(path1).expect(200, 'first', cb),
(cb) => proxyReq.get(path2).expect(200, 'second', cb),
(cb) => proxyReq.get(path3).expect(200, 'third', cb),
(cb) => proxyReq.get(path4).expect(200, 'fourth', cb),
(cb) => proxyReq.get(path5).expect(200, 'fifth', cb)
], done);
});
});
});

@@ -18,3 +18,3 @@ 'use strict';

// stop mockyeah
// stop mockyeah server
after(() => mockyeah.close());

@@ -41,2 +41,22 @@

});
});
it('should verify a mock service expectation', (done) => {
// create service mock with expectation
const expectation = mockyeah
.get('/wondrous', { text: 'it worked' })
.expect()
.params({
foo: 'bar'
})
.once();
// invoke request and verify expectation
request
.get('/wondrous?foo=bar')
.expect(200, 'it worked')
.then(() => {
expectation.verify();
done();
});
});
});
'use strict';
const async = require('async');
const TestHelper = require('../TestHelper');

@@ -33,2 +34,16 @@ const MockYeahServer = require('../../server');

});
it('should not replace existing matching routes with different http verbs', (done) => {
mockyeah.get('/foo', { text: 'bar get' });
mockyeah.post('/foo', { text: 'bar post' });
mockyeah.put('/foo', { text: 'bar put' });
mockyeah.delete('/foo', { text: 'bar delete' });
async.parallel([
(cb) => request.get('/foo').expect(200, 'bar get', cb),
(cb) => request.post('/foo').expect(200, 'bar post', cb),
(cb) => request.put('/foo').expect(200, 'bar put', cb),
(cb) => request.delete('/foo').expect(200, 'bar delete', cb)
], done);
});
});
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