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

mockserver

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockserver - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

32

bin/mockserver.js

@@ -10,12 +10,28 @@ #!/usr/bin/env node

var port = argv.p || argv.port;
var verbose = !(argv.q || argv.quiet);
if (!mocks || !port) {
console.log("Mockserver v" + info.version);
console.log();
console.log("Usage: mockserver -p PORT -m /PATH/TO/YOUR/MOCKS");
console.log("Example: mockserver -p 8080 -m test/mocks");
console.log([
"Mockserver v" + info.version,
"",
"Usage:",
" mockserver [-q] -p PORT -m PATH",
"",
"Options:",
" -p, --port=PORT - Port to listen on",
" -m, --mocks=PATH - Path to mock files",
" -q, --quiet - Do not output anything",
"",
"Example:",
" mockserver -p 8080 -m './mocks'"
].join("\n"));
} else {
http.createServer(mockserver(mocks)).listen(port);
console.log('Mockserver serving mocks under "' + mocks.green + '" at ' + 'http://localhost:'.green + port.toString().green);
}
http.createServer(mockserver(mocks, verbose)).listen(port);
if (verbose) {
console.log('Mockserver serving mocks {'
+ 'verbose'.yellow + ':' + (verbose && 'true'.green || 'false')
+ '} under "' + mocks.green + '" at '
+ 'http://localhost:'.green + port.toString().green);
}
}

@@ -107,8 +107,17 @@ var fs = require('fs');

var mockFile = join(mockserver.directory, path, mockName);
var content;
try {
return fs.readFileSync(mockFile, {encoding: 'utf8'});
content = fs.readFileSync(mockFile, {encoding: 'utf8'});
if (mockserver.verbose) {
console.log('Reading from '+ mockFile.yellow +' file: ' + 'Matched'.green);
}
} catch(err) {
return (body || query) && getMockedContent(path, prefix);
if (mockserver.verbose) {
console.log('Reading from '+ mockFile.yellow +' file: ' + 'Not matched'.red);
}
content = (body || query) && getMockedContent(path, prefix);
}
return content;
}

@@ -118,4 +127,6 @@

directory: '.',
use: function(directory) {
verbose: false,
init: function(directory, verbose) {
this.directory = directory;
this.verbose = !!verbose;
},

@@ -177,4 +188,4 @@ handle: function(req, res) {

module.exports = function(directory){
mockserver.use(directory);
module.exports = function(directory, silent) {
mockserver.init(directory, silent);

@@ -181,0 +192,0 @@ return mockserver.handle;

{
"name": "mockserver",
"version": "1.3.0",
"version": "1.4.0",
"description": "Easily mock your webservices while testing frontends.",

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

@@ -64,2 +64,16 @@ # mockserver

## Verbosity
By default mockserver is running in verbose mode: log messages are pushed to `stdout`.
That will help to distinguish, which mock file matches best the request.
```shell
$ mockserver -p 8080 -m './mocks'
Mockserver serving mocks {verbose:true} under "./mocks" at http://localhost:8080
Reading from ./mocks/api/GET--a=b.mock file: Not matched
Reading from ./mocks/api/GET.mock file: Matched
```
Option `-q|--quiet` disables this behavior.
## Mock files

@@ -191,1 +205,13 @@

(if you don't have mocha installed globally).
To run test with debug output, expose `DEBUG=true` environment variable:
```shell
$ DEBUG=true ./node_modules/mocha/bin/mocha
```
Or as npm shortcut:
```shell
$ DEBUG=true npm test
```
var MockReq = require('mock-req');
var assert = require("assert");
var colors = require('colors');
var mockserver = require("./../mockserver");

@@ -9,2 +10,4 @@

var verbose = process.env.DEBUG === 'true' || false;
describe('mockserver', function() {

@@ -42,3 +45,3 @@ beforeEach(function() {

req.method = method;
mockserver(mocksDirectory)(req, res);
mockserver(mocksDirectory, verbose)(req, res);
}

@@ -45,0 +48,0 @@

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