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.1 to 0.15.2

test.js

21

app/index.js

@@ -17,11 +17,21 @@ 'use strict';

const defaultConfig = {
name: 'mockyeah'
name: 'mockyeah',
output: true,
journal: false,
verbose: false
};
// Prepare configuration. Merge configuration with default configuration
app.config = Object.assign({}, defaultConfig, config || {});
// Prepare global config
const globalConfig = {};
if (global.MOCKYEAH_SUPPRESS_OUTPUT !== undefined) globalConfig.output = !global.MOCKYEAH_SUPPRESS_OUTPUT;
if (global.MOCKYEAH_VERBOSE_OUTPUT !== undefined) globalConfig.verbose = !!global.MOCKYEAH_VERBOSE_OUTPUT;
// Prepare configuration. Merge configuration with global and default configuration
app.config = Object.assign({}, defaultConfig, globalConfig, config || {});
// Instantiate new logger
const logger = new Logger({
name: app.config.name
name: app.config.name,
output: app.config.output,
verbose: app.config.verbose
});

@@ -32,2 +42,5 @@

// Provide user feedback when verbose output is enabled
app.log('info', 'verbose output enabled', true);
// Attach RouteManager to app object, the primary set of mockyeah API methods.

@@ -34,0 +47,0 @@ app.routeManager = new RouteManager(app);

@@ -23,2 +23,3 @@ 'use strict';

});
req.callCount = this.called;
next();

@@ -25,0 +26,0 @@ };

14

app/lib/Logger.js

@@ -13,4 +13,4 @@ 'use strict';

this.name = options.name;
this.suppress = global.MOCKYEAH_SUPPRESS_OUTPUT !== undefined ? global.MOCKYEAH_SUPPRESS_OUTPUT : false;
this.verbose = global.MOCKYEAH_VERBOSE_OUTPUT !== undefined ? global.MOCKYEAH_VERBOSE_OUTPUT : false;
this.output = options.output;
this.verbose = options.verbose;

@@ -63,4 +63,4 @@ return this;

// If suppressing output, abort
if (this.suppress) return;
// If silencing output, abort
if (!this.output) return;

@@ -73,2 +73,8 @@ // If verbose is off and message is flagged as verbose output, abort

// Explicity indicate verbose messages
if (args.verbose) args.types.unshift('verbose');
// Add timestamp to message
args.types.unshift((new Date()).toLocaleTimeString('en-US', { hour12: false }));
// Prepare string of types for output

@@ -75,0 +81,0 @@ args.types = args.types.reduce((result, value) => {

@@ -17,2 +17,3 @@ 'use strict';

register: function register(method, _path, response) {
app.log(['serve', 'mount', method], _path);
return routeStore.register(method, _path, response);

@@ -41,4 +42,5 @@ },

reset: function reset() {
routeStore.reset();
reset: function reset(/* paths 1, path 2, path 3, etc. */) {
const paths = [].slice.call(arguments);
routeStore.reset.call(routeStore, paths);
},

@@ -57,4 +59,4 @@

capture.files().forEach((route) => {
app.log(['serve', 'mount', route.method], route.originalPath, false);
app.log(['serve', 'mount', route.method], `${route.originalPath} at ${route.path}`, true);
app.log(['serve', 'playing', route.method], route.originalPath, false);
app.log(['serve', 'playing', route.method], `${route.originalPath} at ${route.path}`, true);

@@ -65,2 +67,2 @@ this.register(route.method, route.path, route.options);

};
};
};

@@ -61,2 +61,16 @@ 'use strict';

if (this.app.config.journal) {
this.app.log(['request', 'journal'], JSON.stringify({
callCount: req.callCount,
url: req.url,
fullUrl: req.protocol + '://' + req.get('host') + req.originalUrl,
clientIp: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
method: req.method,
headers: req.headers,
query: req.query,
body: req.body,
cookies: req.cookies
}, null, 2));
}
// Default latency to 0 when undefined

@@ -63,0 +77,0 @@ response.latency = response.latency || 0;

@@ -22,4 +22,5 @@ 'use strict';

RouteStore.prototype.reset = function reset() {
this.routeResolver.unregister(this.routes);
RouteStore.prototype.reset = function reset(paths) {
const routes = paths.length ? this.routes.filter((route) => paths.indexOf(route.path) >= 0) : this.routes;
this.routeResolver.unregister(routes);
this.routes = [];

@@ -26,0 +27,0 @@ };

@@ -8,2 +8,32 @@ # Change Log

### [0.15.2] - 2016-11-18
#### Add
- `output`, `journal`, and `verbose` boolean configuration options for configuring mockyeah output.
- Add request journaling to provide greater visibility into mockyeah request handling. Example:
```
[mockyeah][14:54:21][REQUEST][JOURNAL] {
"callCount": 1,
"url": "/foo?bar=baa",
"fullUrl": "http://localhost:4001/foo?bar=baa",
"clientIp": "127.0.0.1",
"method": "GET",
"headers": {
"host": "localhost:4001",
"user-agent": "curl/7.43.0",
"accept": "*/*"
},
"query": {
"bar": "baa"
},
"body": {}
}
```
- `[MOUNT]` message now output for all mounted services.
- `[VERBOS]` indicator added to verbose messages.
- Timestamp added to all logged messages.
### [0.15.1] - 2016-11-02
#### Add
- Mock expectation support. Expectations enable the ability to assert interactivity with mock services. This functionality is currently undocumented for beta testing. Once api is finalized, documentation will be added.
### [0.15.0] - 2016-10-31

@@ -54,3 +84,5 @@ #### Fix

[Unreleased]: https://github.com/ryanricard/mockyeah/compare/v0.15.0...HEAD
[Unreleased]: https://github.com/ryanricard/mockyeah/compare/v0.15.2...HEAD
[0.15.2]: https://github.com/ryanricard/mockyeah/compare/v0.15.1...v0.15.2
[0.15.1]: https://github.com/ryanricard/mockyeah/compare/v0.15.0...v0.15.1
[0.15.0]: https://github.com/ryanricard/mockyeah/compare/v0.14.1...v0.15.0

@@ -57,0 +89,0 @@ [0.14.1]: https://github.com/ryanricard/mockyeah/compare/v0.14.0...v0.14.1

{
"name": "mockyeah",
"version": "0.15.1",
"version": "0.15.2",
"description": "An invaluable service mocking platform built on Express.",

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

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

Removes all mounted mock services. Useful during after test teardown.
Removes all mounted mock services. Best practice is to execute `.reset()` in an after test hook. Example usage with Mocha:
```js
// unmounts all mounted services after each test
afterEach(() => mockyeah.reset());
```
You may remove specific services by passing paths matching services to unmount. Example:
```js
mockyeah.get('/foo-1', { text: 'bar' });
mockyeah.get('/foo-2', { text: 'bar' });
mockyeah.get('/foo-3', { text: 'bar' });
// unmounts only /foo-1 and /foo-2
mockyeah.reset('/foo-1', '/bar-2');
```
__mockyeah.close()__

@@ -146,3 +161,6 @@

"fixturesDir": "./fixtures",
"capturesDir": "./mockyeah"
"capturesDir": "./mockyeah",
"output": true,
"journal": false,
"verbose": false
}

@@ -156,2 +174,23 @@ ```

- `capturesDir`: Relative path to the captures directory.
- `output`: Boolean to toggle mockyeah generated output written to stdout.
- `journal`: Boolean to toggle request journaling. Example:
```
[mockyeah][14:54:21][REQUEST][JOURNAL] {
"callCount": 1,
"url": "/foo?bar=baa",
"fullUrl": "http://localhost:4001/foo?bar=baa",
"clientIp": "127.0.0.1",
"method": "GET",
"headers": {
"host": "localhost:4001",
"user-agent": "curl/7.43.0",
"accept": "*/*"
},
"query": {
"bar": "baa"
},
"body": {}
}
```
- `verbose`: Boolean to toggle verbosity of mockyeah generated output.

@@ -158,0 +197,0 @@ Overriding any of these configurations can be done by placing a `.mockyeah`

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

*/
module.exports = function Server(config) {
module.exports = function Server(config, onStart) {
config = prepareConfig(config);

@@ -24,2 +24,4 @@

app.log('serve', `Listening at http://${this.address().address}:${this.address().port}`);
// Execute callback once server starts
if (onStart) onStart.call(null);
});

@@ -26,0 +28,0 @@

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