mockserver
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32403
416
216
2